LuciferYang opened a new pull request, #13400: URL: https://github.com/apache/gravitino/pull/13400
### What changes were proposed in this pull request? Replace the entry latch in `SegmentedLock` with a `ReentrantReadWriteLock` gate. Every `withLock` variant now holds the read lock across its full critical section (segment-lock acquire plus the action), and `withGlobalLock` takes the write lock, so the global action waits for all in-flight segment operations to finish before it runs. The concurrent-global `IllegalStateException` and `isClearing()` semantics are preserved. ### Why are the changes needed? `withGlobalLock` promised exclusive access to all segments but acquired no segment lock, so a segment operation already inside its critical section ran concurrently with the global action. In `CaffeineEntityCache`, a `doPut` racing `clear()` could write its index entry into the tree `clear()` was swapping out, leaving an entity in `cacheData` but absent from the active `cacheIndex` and served stale until TTL. Fix: #13399 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Added `TestSegmentedLock.testGlobalClearingWaitsForInFlightOperations`, a deterministic test that pins that a global action does not proceed until an in-flight segment operation has finished. It fails against the pre-fix code. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
