Skip to content

Commit 62dfa1b

Browse files
committed
Apply Ohad's requested changes
1 parent e81f7d2 commit 62dfa1b

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

fdb-record-layer-lucene/src/main/java/com/apple/foundationdb/record/lucene/directory/FDBDirectoryLockFactory.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.util.UUID;
4646
import java.util.concurrent.CompletableFuture;
4747
import java.util.concurrent.TimeUnit;
48+
import java.util.concurrent.atomic.AtomicBoolean;
4849
import java.util.function.Function;
4950

5051
/**
@@ -92,8 +93,7 @@ protected static class FDBDirectoryLock extends Lock {
9293
*/
9394
private FDBRecordContext closingContext = null;
9495
private final Object fileLockSetLock = new Object();
95-
private boolean clearingLockNow = false;
96-
private final Object clearingLockNowLock = new Object();
96+
private final AtomicBoolean clearingLockNow = new AtomicBoolean();
9797

9898
private FDBDirectoryLock(final AgilityContext agilityContext, final String lockName, byte[] fileLockKey, int timeWindowMilliseconds) {
9999
this.agilityContext = agilityContext;
@@ -212,12 +212,9 @@ private void fileLockCheckNewLock(byte[] val, long nowMillis) {
212212
}
213213

214214
private void fileLockClearFlushAndClose(boolean isRecovery) {
215-
synchronized (clearingLockNowLock) {
215+
if (!clearingLockNow.compareAndExchange(false, true)) {
216216
// Here: this function is being called from too many paths. Until cleanup, this guard is here to avoid recursions
217-
if (clearingLockNow) {
218-
return;
219-
}
220-
clearingLockNow = true;
217+
return;
221218
}
222219
Function<FDBRecordContext, CompletableFuture<Void>> fileLockFunc = aContext ->
223220
aContext.ensureActive().get(fileLockKey)
@@ -253,10 +250,7 @@ private void fileLockClearFlushAndClose(boolean isRecovery) {
253250
} finally {
254251
closed = flushed; // allow close retry
255252
closingContext = null;
256-
synchronized (clearingLockNowLock) {
257-
// clearing under lock to avoid spotbugsMain's "Inconsistent synchronization" issue.
258-
clearingLockNow = false;
259-
}
253+
clearingLockNow.compareAndExchange(true, false);
260254
}
261255
}
262256

0 commit comments

Comments
 (0)