Repository navigation
Fixes #35428: Stop cache-miss loads pinning virtual threads - #35429
Conversation
On JDK 21 a virtual thread that blocks while holding a monitor keeps its carrier thread. Guava LoadingCache.get, Caffeine get and ConcurrentHashMap.compute all run the loader inside synchronized, so a cache miss that reads Redis or the database pins the thread. In six merge-queue stalls of the Postgres + OpenSearch IT lane all four carriers of the runner were pinned; 3 of the 24 pinned threads were in the entity cache's Guava load (the rest were Jdbi, fixed by #35374). Add SingleFlight: runs a miss on the caller's thread with no monitor held, at most one load per key, other callers waiting on a CompletableFuture. - EntityRepository find/findByName load misses through SingleFlight and re-check the write epoch after the put, evicting if a write raced the load. Loaders stay attached so direct CACHE_WITH_* callers are unchanged. - AuditLogRepository, OwnerResolver, RdfPropertyMapper: read, then put. - EntityStatusWorkflows: SingleFlight plus an invalidation counter so a workflow change during a load is not hidden by what the load read. - StageStatsTracker.flush: ReentrantLock instead of synchronized.
✅ PR checks passedThe linked issue has a description and all required Shipping project fields set. Thanks! |
Only the entity cache's Guava load showed up pinned in the stall dumps. Load the miss with a plain read, put and epoch re-check in EntityRepository instead of a new SingleFlight class, and revert the preventive changes to the audit bot cache, OwnerResolver, RdfPropertyMapper, EntityStatusWorkflows and StageStatsTracker, plus the decision record.
Code Review ✅ Approved 1 closed / 1 findings🟡 Medium risk · Entity-cache misses now load outside Guava locks, allowing duplicate Redis/database reads that could increase backend load during concurrent misses. Stops cache-miss entity loads in ✅ 1 closed✅ Quality: Load-outside-cache-lock rule no longer recorded after ADR deletion
VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
Main's #35429 moved find/findByName L1 misses out of the cache lock (loadOutsideCacheLock: read epoch, load, put, re-check epoch) because a loading get, Guava's or Caffeine's, pins virtual threads (ADR:2026-10-14-cache-misses-that-do-io-load-outside-the-cache-lock). That replaces this branch's Guava-to-Caffeine L1 switch, so keep main's find/findByName, L1 builders, COUNT_CACHE and loaders, and drop the Caffeine-only test. Keep the L1-after-Redis eviction order in invalidateCachesAfterStore, and bump the write epochs again just before the L1 eviction there and in evictCommittedWrites. Without a loading get, an eviction no longer waits for a load in flight: a miss that read its epoch after the first bump and fetched the stale Redis copy before the delete could put it after the L1 eviction and still pass its re-check. EntityCacheLoadRaceTest covers both paths and fails without the second bump.
… (#38520) * Fixes #35373: Stop Jdbi pinning virtual threads and the test suite summary 404 on deleted test cases (#35374) * Build Jdbi SQL object handlers on first call, not on every attach (#35469) * Fixes #35428: Stop cache-miss loads pinning virtual threads (#35429) --------- Co-authored-by: Mohit Yadav <[email protected]> Co-authored-by: Ram Narayan Balaji <[email protected]>
Describe your changes:
Fixes #35428
Follow-up to #35374. An entity-cache miss in
EntityRepository.find/findByNamenow loads outside Guava's lock.Why:
CACHE_WITH_ID.get(key)/CACHE_WITH_NAME.get(key)run the loader's Redis and database reads inside a Guavasynchronized. On JDK 21 a virtual thread blocked there stays pinned to its carrier thread. In six merge-queue stalls of the Postgres + OpenSearch IT lane, all 4 carriers were pinned. Most of those pins came from Jdbi (fixed in #35374); 3 of the 24 were this Guava load.Change: a small
loadOutsideCacheLockhelper inEntityRepository:putthe result;LoaderRaceException, whichfindalready handles by retrying through the bypass read.Failures come back wrapped in
ExecutionException, asLoadingCache.getthrows them, so the existingcatchblocks are unchanged. The loaders stay attached to the caches, so directCACHE_WITH_*.getcallers behave as before.Trade-off: concurrent misses for the same entity may now each run the loader once, where Guava made them wait for one load. Redis L2 sits in front of the database, so the extra reads are usually cheap.
Type of change:
Tests:
Unit tests
EntityCacheVirtualThreadTest(5 tests):jdk.VirtualThreadPinnedJFR event;CACHE_WITH_ID.getdoes record one, so the first check can't pass vacuously;putevicts what was cached;The existing tests around the entity cache pass:
Tests run: 165, Failures: 0, Errors: 0.Backend integration tests
Run locally on MySQL + Elasticsearch, before the strip-down, against the same
find/findByNameload path:EntityCacheInvalidationIT,EntityCacheMemoryIT,RestoreHierarchyIT,EntityLifecycleStagesIT,EntityStatusWorkflowOwnershipIT,AuditLogResourceIT,BotResourceIT,DomainResourceIT. Tests run: 533, Failures: 0, Errors: 0, Skipped: 55.The full IT suite (MySQL + ES, PostgreSQL + OS) is running in CI on this head.
Collate CI (
maven-collate-ci) stays red until open-metadata/openmetadata-collate#7428 (Jdbi 3.49.5) merges. That failure is unrelated to this change.Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.docs/decisions/2026-10-14-cache-misses-that-do-io-load-outside-the-cache-lock.md.🤖 Generated with Claude Code