|
45 | 45 | import java.util.UUID; |
46 | 46 | import java.util.concurrent.CompletableFuture; |
47 | 47 | import java.util.concurrent.TimeUnit; |
| 48 | +import java.util.concurrent.atomic.AtomicBoolean; |
48 | 49 | import java.util.function.Function; |
49 | 50 |
|
50 | 51 | /** |
@@ -92,8 +93,7 @@ protected static class FDBDirectoryLock extends Lock { |
92 | 93 | */ |
93 | 94 | private FDBRecordContext closingContext = null; |
94 | 95 | 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(); |
97 | 97 |
|
98 | 98 | private FDBDirectoryLock(final AgilityContext agilityContext, final String lockName, byte[] fileLockKey, int timeWindowMilliseconds) { |
99 | 99 | this.agilityContext = agilityContext; |
@@ -212,12 +212,9 @@ private void fileLockCheckNewLock(byte[] val, long nowMillis) { |
212 | 212 | } |
213 | 213 |
|
214 | 214 | private void fileLockClearFlushAndClose(boolean isRecovery) { |
215 | | - synchronized (clearingLockNowLock) { |
| 215 | + if (!clearingLockNow.compareAndExchange(false, true)) { |
216 | 216 | // 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; |
221 | 218 | } |
222 | 219 | Function<FDBRecordContext, CompletableFuture<Void>> fileLockFunc = aContext -> |
223 | 220 | aContext.ensureActive().get(fileLockKey) |
@@ -253,10 +250,7 @@ private void fileLockClearFlushAndClose(boolean isRecovery) { |
253 | 250 | } finally { |
254 | 251 | closed = flushed; // allow close retry |
255 | 252 | 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); |
260 | 254 | } |
261 | 255 | } |
262 | 256 |
|
|
0 commit comments