-
Notifications
You must be signed in to change notification settings - Fork 116
Prevent parallel file lock clear #3714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,6 +92,8 @@ protected static class FDBDirectoryLock extends Lock { | |
| */ | ||
| private FDBRecordContext closingContext = null; | ||
| private final Object fileLockSetLock = new Object(); | ||
| private boolean clearingLockNow = false; | ||
| private final Object clearingLockNowLock = new Object(); | ||
|
|
||
| private FDBDirectoryLock(final AgilityContext agilityContext, final String lockName, byte[] fileLockKey, int timeWindowMilliseconds) { | ||
| this.agilityContext = agilityContext; | ||
|
|
@@ -210,6 +212,17 @@ private void fileLockCheckNewLock(byte[] val, long nowMillis) { | |
| } | ||
|
|
||
| private void fileLockClearFlushAndClose(boolean isRecovery) { | ||
| if (clearingLockNow) { | ||
| // Here: this function is being called from too many paths. Until cleanup, this guard is here to avoid recursions | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If indeed all that the synchronized block is trying to do is protect a boolean, then an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to undo the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious: Which tests failed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure, but it might have been |
||
| return; | ||
| } | ||
| synchronized (clearingLockNowLock) { | ||
| // repeat under lock | ||
| if (clearingLockNow) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've only seen it for lazy instantiation, but would it be worth to duplicate this before the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can either do that or remove the |
||
| return; | ||
| } | ||
| clearingLockNow = true; | ||
| } | ||
| Function<FDBRecordContext, CompletableFuture<Void>> fileLockFunc = aContext -> | ||
| aContext.ensureActive().get(fileLockKey) | ||
| .thenAccept(val -> { | ||
|
|
@@ -224,6 +237,12 @@ private void fileLockClearFlushAndClose(boolean isRecovery) { | |
| throw new AlreadyClosedException("FileLock: Expected to be locked during close.This=" + this + " existingUuid=" + existingUuid); // The string append methods should handle null arguments. | ||
| } | ||
| } | ||
| }) | ||
| .whenComplete((res, err) -> { | ||
| synchronized (clearingLockNowLock) { | ||
| // clearing under lock to avoid spotbugsMain's "Inconsistent synchronization" issue. | ||
| clearingLockNow = false; | ||
| } | ||
| }); | ||
|
|
||
| if (agilityContext.isClosed()) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds like there are some concurrency challenges with
FDBDirectoryLock, it would probably be good to add some tests that try to clear this lock concurrently.