chore(spanner): implement key range cache for location-aware routing - #6215
chore(spanner): implement key range cache for location-aware routing#6215olavloite wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces an in-memory interval cache (KeyRangeCache) for Spanner location-aware routing, which maps table key range split boundaries to tablet replica groups and supports interval lookups under CoveringSplit and PickRandom routing modes. Feedback on the implementation suggests improving the tablet selection logic in select_tablet to prevent defeating zone-aware routing, avoid load imbalance, and handle fallback scenarios more optimally by tracking the minimum distance and utilizing reservoir sampling.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6215 +/- ##
==========================================
+ Coverage 96.02% 96.07% +0.05%
==========================================
Files 269 270 +1
Lines 67282 68426 +1144
==========================================
+ Hits 64607 65741 +1134
- Misses 2675 2685 +10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
4addb84 to
d0a57b2
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a location-aware routing module for Spanner, implementing an in-memory interval cache (KeyRangeCache) to map table key range split boundaries to tablet replica groups. The review feedback highlights a critical bug in the cache implementation: keying the BTreeMap by limit_key causes the last split range (which has an empty limit_key representing infinity) to be incorrectly sorted as the smallest element, leading to cache misses and overlapping ranges. To resolve this, the reviewer suggests keying the map by start_key instead and provides refactored implementations for replace_range_if_newer_locked and find_range. Additionally, the reviewer recommends removing the unused MAX_SAME_REGION_DISTANCE constant.
d0a57b2 to
dfb34e3
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces KeyRangeCache to support location-aware routing in Spanner by caching split boundaries and mapping them to replica groups. The feedback highlights a critical correctness bug in the find_range method under RangeMode::PickRandom when the requested key is out of range, which can lead to incorrect routing or false gap detection. Additionally, a documentation correction is needed for the ranges map in CacheState to accurately reflect that it maps start_key rather than limit_key.
dfb34e3 to
a5fb379
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a location-aware routing module for Spanner, implementing an in-memory interval cache (KeyRangeCache) to map table key range split boundaries to tablet replica groups. Feedback on the implementation highlights a performance bottleneck in replace_range_if_newer_locked, where inserting a range performs an O(N) scan of the BTreeMap starting from Bound::Unbounded. It is recommended to optimize this to O(log N) by locating the first potentially overlapping range using a targeted B-tree lookup.
Add `KeyRangeCache`, an in-memory interval cache that maps table key range boundaries (`start_key` and `limit_key`) to Paxos replica groups and tablet endpoints for location-aware routing.
a5fb379 to
5ef5c5b
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a thread-safe, in-memory interval cache (KeyRangeCache) for Spanner location-aware routing, along with its corresponding module structure. The cache maps table key range split boundaries to tablet replica groups and supports interval lookups for point keys and key ranges under CoveringSplit and PickRandom routing modes. It also includes a comprehensive suite of unit tests to verify its behavior under various scenarios such as overlapping ranges, different generations, and tablet selection. There are no review comments, and the implementation appears solid and well-tested, so I have no feedback to provide.
Add
KeyRangeCache, an in-memory interval cache that maps table key range boundaries (start_keyandlimit_key) to Paxos replica groups and tablet endpoints for location-aware routing.