Repository navigation
fix(cache): skip oversized offheap query keys - #3321
Conversation
- treat oversized query keys as optional cache misses - retain backend execution and persistent id encoding - cover ascii and utf8 byte boundaries - preserve normal key lookup and invalidation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3321 +/- ##
============================================
- Coverage 52.63% 52.62% -0.01%
Complexity 2435 2435
============================================
Files 770 770
Lines 67694 67707 +13
Branches 9172 9175 +3
============================================
+ Hits 35631 35632 +1
- Misses 28520 28533 +13
+ Partials 3543 3542 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
- derive a safe UTF-16 bound from the byte limit - encode only query keys in the middle range - preserve RAM and offheap fallback behavior - cover Unicode boundaries and real cache lifecycles
- use the merged launcher and required CI baseline - preserve the constant-time QueryId guard - validate RAM and offheap cache behavior on the new base
bitflicker64
left a comment
There was a problem hiding this comment.
Blocking: no. Summary: The guard keeps query keys whose UTF-8 form exceeds BytesBuffer.ID_LEN_MAX out of the off-heap tier on lookup, insert, containsKey and remove, so a large edge batch query misses the cache and reaches the backend instead of failing in BytesBuffer.writeId; other Id types and keys within the limit behave as before. Evidence: read the full diff at 4d92853 with OffheapCache, LevelCache, AbstractCache, CachedBackendStore.QueryId, QueryIdOffHeap, CachedGraphTransaction.fetchEdgeBatch and BytesBuffer.writeId; the two length shortcuts are sound because UTF-8 uses between one and three bytes per UTF-16 code unit; mvn test -pl hugegraph-server/hugegraph-test -am -P unit-test -Dtest='CacheTest*' on JDK 17 ran 88 tests with 0 failures (OffheapCacheTest 31, RamCacheTest 25, LevelCacheTest 32); Server CI, Compatibility CI and CodeQL are green on this head, and only the informational codecov/project status is red (-0.01%).
Purpose of the PR
A valid 2,500-edge batch update can exceed the off-heap binary key limit and fail before reaching the backend. Oversized query keys now bypass that cache; ordinary short query keys avoid an additional UTF-8 encoding and byte-array allocation in the guard.
Main Changes
ID_LEN_MAX / 3pass immediately, values aboveID_LEN_MAXbypass off-heap caching, and only the middle interval needs a UTF-8 byte-length check.Verifying these changes
The old guard fails the new zero-extra-encoding regression for short keys. Boundary checks cover ASCII, Chinese text and surrogate pairs, including the exact UTF-8 limit and overflow. Real LevelCache regressions cover RAM and off-heap hits, invalidation, misses and backend refetch. Java 17 formatting, clean compilation, the cache test groups and three independent final reviews passed. New-head CI is pending.
The earlier patched service completed two 2,500-edge SUM updates with typed-value and endpoint readback, and rejected a 2,501-edge request without writes. Those receipts belong to the earlier source; this performance supplement does not claim a new live-service run, runtime cache-hit metric, restart or complete C04 acceptance.
Documentation Status
Doc - No Need: internal cache guard optimization; no API, configuration or persistent format change.Implementation illustration
Oversized query keys bypass the off-heap tier so cache misses can reach the backend; short keys avoid UTF-8 encoding in the guard. RAM caching and persistent ID encoding remain unchanged. Source-level behavior illustration, not a runtime or CI result.