LuciferYang commented on code in PR #13400:
URL: https://github.com/apache/gravitino/pull/13400#discussion_r4069412947
##########
core/src/main/java/org/apache/gravitino/cache/SegmentedLock.java:
##########
@@ -34,8 +34,15 @@ public class SegmentedLock {
private final Striped<Lock> stripedLocks;
- /** CountDownLatch for global operations - null when no operation is in
progress */
- private final AtomicReference<CountDownLatch> globalOperationLatch = new
AtomicReference<>();
+ /**
+ * Gates segment operations against global operations: segment operations
hold the read lock
+ * across their whole critical section, global operations hold the write
lock, so a global
+ * operation excludes every segment operation, including ones already in
flight when it starts.
+ */
+ private final ReentrantReadWriteLock globalGate = new
ReentrantReadWriteLock();
Review Comment:
Good catch. Switched `globalGate` to a fair `ReentrantReadWriteLock`, so
once `withGlobalLock` is queued as a writer, new `withLock` readers block
behind it and the global action can no longer be starved. Reentrant read
reacquisition stays exempt from the fair queueing (the JDK exempts a thread
that already holds the read lock), so the nested cache paths that reacquire the
read lock (`withCacheLock` -> `doPut` -> `withLock`) do not deadlock. Verified
by running the full cache test suite.
--
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]