Fix type assertion panic in Cache.Get() when key not found#881
Merged
mattisonchao merged 3 commits intooxia-db:mainfrom Feb 6, 2026
Merged
Fix type assertion panic in Cache.Get() when key not found#881mattisonchao merged 3 commits intooxia-db:mainfrom
mattisonchao merged 3 commits intooxia-db:mainfrom
Conversation
When a key is not found in Oxia, the cache stores a negative cache entry using `empty[cachedResult[Value]]()`. However, since cachedResult[Value] is a type alias for Optional[valueVersion[Value]], this creates a double-wrapped optional type: *optional[Optional[valueVersion[Value]]]. When Cache.Get() later retrieves this entry and attempts the type assertion `cachedValue.(cachedResult[Value])`, it fails with: "interface conversion: *oxia.optional[cachedResult[...]] is not cachedResult[...]: missing method Get" The fix is to use `empty[valueVersion[Value]]()` instead, which creates *optional[valueVersion[Value]] - the same type structure as the non-empty case, ensuring type consistency.
Member
|
Hi @labuladong could you hellp add a test for it? |
mattisonchao
reviewed
Feb 5, 2026
TestCache_GetNotFoundTwice: Verifies that calling Get() twice on a non-existing key does not panic. The first call stores a negative cache entry via load(), the second call reads it from ristretto and performs a type assertion that would fail with the old code. TestCache_GetNotFoundThenPut: Verifies that a key can transition from "not found" (negative cache entry) to a valid value without issues.
fe79297 to
d42f605
Compare
mattisonchao
approved these changes
Feb 6, 2026
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.
Summary
Fix a type assertion panic that occurs when
Cache.Get()is called for a key that doesn't exist in Oxia.Problem
When a key is not found, the cache stores a negative cache entry using:
However,
cachedResult[Value]is a type alias forOptional[valueVersion[Value]], so this creates a double-wrapped optional type:When
Cache.Get()later retrieves this entry and attempts the type assertion:It fails with:
Solution
Use
empty[valueVersion[Value]]()instead, which creates*optional[valueVersion[Value]]- the same type structure as the non-empty case, ensuring type consistency.Type Analysis