Skip to content

Commit

Permalink
Fix stale region cache with no leader
Browse files Browse the repository at this point in the history
Signed-off-by: yongman <[email protected]>
  • Loading branch information
yongman committed Mar 11, 2024
1 parent c6110dd commit 6d318ca
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/region_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ impl<C: RetryClientTrait> RegionCache<C> {
.get(&candidate_region_ver_id)
.unwrap();

if region.contains(key) {
// Region in cache maybe stale if the region has not been elected leader yet during start.
if region.contains(key) && region.leader.is_some() {
return Ok(region.clone());
}
}
Expand All @@ -102,7 +103,11 @@ impl<C: RetryClientTrait> RegionCache<C> {
let ver_id = region_cache_guard.id_to_ver_id.get(&id);
if let Some(ver_id) = ver_id {
let region = region_cache_guard.ver_id_to_region.get(ver_id).unwrap();
return Ok(region.clone());

// Region in cache maybe stale if the region has not been elected leader yet during start.
if region.leader.is_some() {
return Ok(region.clone());
}
}

// check concurrent requests
Expand Down

0 comments on commit 6d318ca

Please sign in to comment.