Skip to content

Commit

Permalink
fix: determine region role by using is_readonly (#4725)
Browse files Browse the repository at this point in the history
fix: correct `is_writable` behavior
  • Loading branch information
WenyXu authored Sep 18, 2024
1 parent f73fb82 commit befb6d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/mito2/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
}
Expand Down
5 changes: 5 additions & 0 deletions src/mito2/src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit befb6d8

Please sign in to comment.