fix(kvblock): stop Lookup at first prefix-chain break#688
Open
Iceber wants to merge 1 commit into
Open
Conversation
Signed-off-by: Iceber Gu <caiwei95@hotmail.com>
Iceber
requested review from
dannyharnik,
kfirtoledo,
liu-cong and
vMaroon
as code owners
June 29, 2026 09:36
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aligns the in-memory KV-block index lookup behavior with prefix-cache semantics (and the Redis-backed index) by stopping lookup at the first “prefix-chain break”, preventing later blocks from being counted as usable cache hits when an earlier block is missing or filtered out.
Changes:
- Update
InMemoryIndex.LookupandCostAwareMemoryIndex.Lookupto stop scanning at the first missing/empty/filtered-miss key in the request-key chain. - Treat “no matching pods after filtering” as a chain break (early stop) in both in-memory implementations.
- Adjust eviction-related tests to avoid relying on multi-key lookup behavior that now early-stops.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pkg/kvcache/kvblock/in_memory.go | Early-stop lookup on missing keys and filtered-miss to enforce continuous-prefix semantics. |
| pkg/kvcache/kvblock/in_memory_test.go | Update eviction test to lookup surviving keys directly (avoid prefix-chain early-stop dependency). |
| pkg/kvcache/kvblock/cost_aware_memory.go | Mirror early-stop prefix behavior in cost-aware in-memory lookup implementation. |
| pkg/kvcache/kvblock/cost_aware_memory_test.go | Adjust cost-aware eviction test to avoid multi-key lookup semantics impacted by early-stop. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
149
to
152
| } else { | ||
| traceLogger.Info("key not found in index", "key", requestKey) | ||
| return podsPerKey, nil // early stop since prefix-chain breaks here | ||
| } |
Comment on lines
326
to
329
| } else { | ||
| traceLogger.Info("key not found in index", "key", key) | ||
| return podsPerKey, nil // early stop since prefix-chain breaks here | ||
| } |
Comment on lines
+78
to
83
| // Lookup the surviving key directly so this test verifies cost-based | ||
| // eviction without depending on prefix-chain early-stop semantics. | ||
| podsPerKey, err := index.Lookup(ctx, []BlockHash{requestKey3}, nil) | ||
| require.NoError(t, err) | ||
|
|
||
| assert.Len(t, podsPerKey, 1) // Only requestKey3 should be present |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Index.Lookupat the first break in the prefix chain forInMemoryIndexandCostAwareMemoryIndex.Why
KV-cache hits are only useful while the prefix is continuous. If a block in the middle of the chain is missing, later blocks cannot be used even if they still exist in the index.
The previous in-memory lookup behavior skipped over gaps and kept scanning the rest of
requestKeys. That could overstate a pod's cache locality and give it a higher score than it should receive.For example:
Before this change, a lookup filtered to
pod-targetcould still return block 2. After this change, lookup returns only the continuous prefix up to block 0, matching the prefix-cache semantics and the Redis-backed index behavior.