Skip to content

fix: topology-aware cache keys with shard epoch to prevent collision during rebalance - #6

Open
Kasuki354 wants to merge 2 commits into
rasoolharlym8:mainfrom
Kasuki354:fix/cache-key-collision
Open

fix: topology-aware cache keys with shard epoch to prevent collision during rebalance#6
Kasuki354 wants to merge 2 commits into
rasoolharlym8:mainfrom
Kasuki354:fix/cache-key-collision

Conversation

@Kasuki354

Copy link
Copy Markdown

Summary

Fixes issue #1: Cache key collision and partial results during tenant shuffle-sharding rebalance.

Implementation

  1. ShardConfig struct: Tracks tenant shard assignment with Epoch (version number) and RoutingHash (hash of shard IDs)

  2. ShardStateManager: Thread-safe manager using sync.RWMutex for concurrent read access during query loads and atomic writes during rebalancing

  3. GenerateCacheKey: Incorporates tenant ID, shard epoch, routing hash, and request hash. When a rebalance occurs, the epoch increments, causing all new cache keys to differ from old ones. This prevents merging fragments from different shard configurations.

  4. ValidateShardConsistency: Detects mid-flight shard transitions by comparing the epoch captured at query start with the current epoch. If changed, cache write-back is aborted.

Tests

  • Cache keys differ when shard config changes (same request, different epoch)
  • Cache keys match for same shard config (cache hit works)
  • ValidateShardConsistency detects epoch changes
  • ShardStateManager handles concurrent reads + writes safely

/claim #1

Implements the fix for issue rasoolharlym8#1: cache key collision during tenant
shuffle-sharding rebalance.

Changes:
1. ShardConfig struct with Epoch and RoutingHash for shard versioning
2. ShardStateManager with RWMutex for thread-safe concurrent access
3. GenerateCacheKey: incorporates tenant shard epoch + routing hash
4. ValidateShardConsistency: detects mid-flight shard transitions

When a rebalance occurs, the epoch increments, causing all new cache keys
to differ from old ones. This prevents merging fragments from different
shard configurations.

Resolves rasoolharlym8#1
@opirebot

opirebot Bot commented Aug 7, 2026

Copy link
Copy Markdown

😅 Unfortunately there are no rewards left to claim in this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant