chore: add log for converting region to follower (#5222)

* chore: add log for converting region to follower

* chore: apply suggestions from CR
This commit is contained in:
Weny Xu
2024-12-25 10:38:47 +08:00
committed by Yingwen
parent 66b21b29b5
commit 1111a8bd57

View File

@@ -447,7 +447,26 @@ impl ManifestContext {
pub(crate) fn set_role(&self, next_role: RegionRole, region_id: RegionId) {
match next_role {
RegionRole::Follower => {
self.state.store(RegionRoleState::Follower);
match self.state.fetch_update(|state| {
if !matches!(state, RegionRoleState::Follower) {
Some(RegionRoleState::Follower)
} else {
None
}
}) {
Ok(state) => info!(
"Convert region {} to follower, previous role state: {:?}",
region_id, state
),
Err(state) => {
if state != RegionRoleState::Follower {
warn!(
"Failed to convert region {} to follower, current role state: {:?}",
region_id, state
)
}
}
}
}
RegionRole::Leader => {
match self.state.fetch_update(|state| {