Skip to content
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

fix: BaseTable#awaitUpdate Could Account for Exclusive Lock Wait Time #6116

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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 @@ -525,11 +525,25 @@ public void awaitUpdate() throws InterruptedException {

@Override
public boolean awaitUpdate(long timeout) throws InterruptedException {
final MutableBoolean result = new MutableBoolean(false);
updateGraph.exclusiveLock().doLocked(
() -> result.setValue(ensureCondition().await(timeout, TimeUnit.MILLISECONDS)));

return result.booleanValue();
final long startTime = System.nanoTime();
if (!updateGraph.exclusiveLock().tryLock(timeout, TimeUnit.MILLISECONDS)) {
// Usually, users will already be holding the exclusive lock when calling this method. If they are not and
// cannot acquire the lock within the timeout, we should return false now.
return false;
}
timeout -= (System.nanoTime() - startTime) / 1_000_000;

boolean result;
try {
// Note that we must reacquire the exclusive lock before returning from await. This deadline may be
// exceeded if the thread must wait to reacquire the lock.
result = ensureCondition().await(timeout, TimeUnit.MILLISECONDS);
} finally {
updateGraph.exclusiveLock().unlock();
}

return result;
}

private Condition ensureCondition() {
Expand Down