Stale cache results during read repair with consistency level operations
0 reputation · 20 Jan 2021, 06:51 UTC
0 reputation · 20 Jan 2021, 06:51 UTC
In Apache Cassandra, read repair is documented to trigger when replicas return inconsistent data during a read, but the interaction between this repair path and the row cache or key cache can leave stale entries visible to clients. The precise question is under what conditions a cache invalidation is guaranteed to propagate to all replicas after a read repair, and whether a subsequent read at the same consistency level should be expected to return the repaired value or a stale cached result.
Relevant constraints include version-specific behavior between Cassandra 3.x and 4.x, the configured row_cache_size_in_mb and key_cache_size_in_mb, and the compaction strategy in use, since LeveledCompactionStrategy can affect how quickly inconsistencies are resolved. Network partition duration and the timing of cache invalidation relative to the repair operation further complicate the expected outcome. Because these variables interact and behavior may differ across releases, it is unclear which configuration combinations make stale reads a transient symptom versus a persistent failure condition.
Does a read repair operation invalidate stale cache entries synchronously on all replicas, or only on the coordinator? How do row_cache_size_in_mb and key_cache_size_in_mb change the observable window in which a stale read can occur after repair? Is there a documented consistency level or compaction strategy combination that eliminates stale cache results during read repair, or is the behavior always version-dependent?
Read repair does not guarantee that a stale row cache entry is cleared on every node, including the coordinator, as part of a single repair operation. The repair mutation is sent to the out‑of‑date replicas and they invalidate the affected row in their own row cache. The coordinator’s cache is not touched by that repair; it will only be refreshed on the next write that passes through it or when the cached entry expires or is evicted. Therefore, after a read repair a subsequent read at the same consistency level can still return a stale value if the coordinator’s row cache still holds the old partition.
Changing row_cache_size_in_mb to zero removes the possibility of a stale coordinator cache, but does not affect the replicas’ caches. The key_cache_size_in_mb setting only caches partition‑index locations; it does not hold cell data and therefore does not create a stale‑data window.
No documented combination of consistency level and compaction strategy (e.g., LCS vs. SCS) guarantees the elimination of stale cache results after a read repair. The observed behavior is largely version‑dependent, with differences noted between Cassandra 3.x and 4.x in how cache invalidation is performed and how long a stale entry may persist.
In practice, a read at QUORUM or LOCAL_QUORUM that triggers read repair will contact all replicas in the read quorum. The coordinator forwards the newer value to any replica that is lagging and instructs it to apply the mutation, which includes invalidating its row cache entry. The coordinator, however, keeps its own cache entry until a new write invalidates it or the entry ages out. Because the coordinator may serve a cached row before contacting the repaired replica, a client can observe the old value immediately after a repair.
Compaction strategy influences how quickly on‑disk inconsistencies are merged, but it does not affect the in‑memory row cache. Even with LCS, a stale cache entry can survive until eviction or time‑based expiry.
row_cache_size_in_mb in cassandra.yaml. If it is greater than zero, a stale coordinator cache window is possible.TRACING ON in cqlsh, perform a write that creates divergence (e.g., INSERT at ONE), then read at QUORUM to trigger repair, and finally read again at QUORUM.row_cache_size_in_mb to 0 and restart the node(s); repeat the test.To give a more precise recommendation, I need to know the exact Cassandra minor version you are running (e.g., 3.11.x, 4.0.x, 4.1.x). Version‑specific code changes can alter the timing of cache invalidation and the interaction with read repair.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.