fix: determine region role by using is_readonly (#4725)

fix: correct `is_writable` behavior
This commit is contained in:
Weny Xu
2024-09-19 07:17:39 +09:00
committed by GitHub
parent f73fb82133
commit befb6d85f0
2 changed files with 8 additions and 3 deletions

View File

@@ -462,10 +462,10 @@ impl EngineInner {
fn role(&self, region_id: RegionId) -> Option<RegionRole> {
self.workers.get_region(region_id).map(|region| {
if region.is_writable() {
RegionRole::Leader
} else {
if region.is_readonly() {
RegionRole::Follower
} else {
RegionRole::Leader
}
})
}

View File

@@ -174,6 +174,11 @@ impl MitoRegion {
self.manifest_ctx.state.load() == RegionState::Writable
}
/// Returns whether the region is readonly.
pub(crate) fn is_readonly(&self) -> bool {
self.manifest_ctx.state.load() == RegionState::ReadOnly
}
/// Returns the state of the region.
pub(crate) fn state(&self) -> RegionState {
self.manifest_ctx.state.load()