Skip to content
Draft
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -210,6 +212,13 @@ private void fileLockCheckNewLock(byte[] val, long nowMillis) {
}

private void fileLockClearFlushAndClose(boolean isRecovery) {
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that there are concurrent calls for this (within the same session) but recursive calls.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, in that case, it would be good to have tests that cause this to happen recursively. that might be very hard at the higher levels, but should be doable at this level, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot recreate it and wondering if one the two rebases eliminated the scenario. Switching to draft for a full unit testing ...

synchronized (clearingLockNowLock) {
// Here: this function is being called from too many paths. Until cleanup, this guard is here to avoid recursions
if (clearingLockNow) {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 synchronized lock to avoid entering the Synchronized lock if already clearing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can either do that or remove the synchronized lock altogether (since our concern is recursion, the synchronized lock might be an overkill...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed clearingLockNowLock - this will now only protect from recursion, but not from concurrency (which - AFAIK - does not happen).

return;
}
clearingLockNow = true;
}
Function<FDBRecordContext, CompletableFuture<Void>> fileLockFunc = aContext ->
aContext.ensureActive().get(fileLockKey)
.thenAccept(val -> {
Expand Down Expand Up @@ -244,6 +253,10 @@ private void fileLockClearFlushAndClose(boolean isRecovery) {
} finally {
closed = flushed; // allow close retry
closingContext = null;
synchronized (clearingLockNowLock) {
// clearing under lock to avoid spotbugsMain's "Inconsistent synchronization" issue.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in a finally around all the code above?
i.e. what happens if the asyncToSync calls above fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!
I've moved it to a fileLockFunc's whenComplete step.

clearingLockNow = false;
}
}
}

Expand Down
Loading