fix(cache): init guard, corrupted entry eviction, and lock improvement#1925
Conversation
- fuzzyDelete() now checks init flag before accessing cacheManager, preventing NPE when static initialization failed - getList() now removes corrupted cache entries on deserialization failure, preventing repeated parse errors until TTL expires
String.intern() uses the JVM global string pool which is never GC'd, causing memory leaks in long-running deployments. ConcurrentHashMap provides the same per-key locking without polluting the string pool.
openai0229
left a comment
There was a problem hiding this comment.
The corrupted-entry eviction and initialization guard look reasonable, but the lock change still introduces unbounded permanent retention. LOCK_MAP.computeIfAbsent(lockKey, ...) adds one entry per distinct key and no path ever removes it, so this replaces string-intern retention with another process-lifetime map leak.
Please use a bounded striped-lock implementation, or implement lifecycle-safe removal that cannot remove a lock while another thread is waiting on or using it. Add a concurrency test that covers many distinct keys and same-key mutual exclusion. Also coordinate the duplicated fuzzyDelete guard with #1890 so only one focused change remains.
# Conflicts: # chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/cache/CacheManage.java
openai0229
left a comment
There was a problem hiding this comment.
Reviewed and updated. The superseded CacheManage changes were dropped in favor of current main. The remaining lock fix now uses a bounded 1,024-stripe Guava lock set instead of an unbounded map, with tests covering many distinct keys and same-key mutual exclusion. Targeted domain-core tests pass locally.
Summary
Fixes 3 verified bugs in the cache layer.
Fixes included:
if (!init) return;guard to prevent NPE when static initialization failedString.intern()locking withConcurrentHashMapto prevent JVM string pool pollution