Skip to content

Commit

Permalink
Minor Misses
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauernfeind committed Oct 23, 2023
1 parent c163316 commit 5d73734
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import java.util.concurrent.locks.Condition;
Expand Down Expand Up @@ -57,6 +58,8 @@ public boolean isDone() {

@Override
public T get() throws InterruptedException, ExecutionException {
checkSharedLockState();

if (resultSupplier != null) {
return resultSupplier.get();
}
Expand All @@ -70,6 +73,8 @@ public T get() throws InterruptedException, ExecutionException {
@Override
public T get(final long timeout, @NotNull final TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
checkSharedLockState();

if (resultSupplier != null) {
return resultSupplier.get();
}
Expand All @@ -81,12 +86,6 @@ public T get(final long timeout, @NotNull final TimeUnit unit)

private T getInternal(final long timeout, @Nullable final TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
// test lock conditions
if (updateGraph.sharedLock().isHeldByCurrentThread()) {
throw new UnsupportedOperationException(
"Cannot Future.get(...) while holding the " + updateGraph + " shared lock");
}

final boolean holdingUpdateGraphLock = updateGraph.exclusiveLock().isHeldByCurrentThread();
if (holdingUpdateGraphLock) {
if (updateGraphCondition == null) {
Expand All @@ -111,6 +110,13 @@ private T getInternal(final long timeout, @Nullable final TimeUnit unit)
return resultSupplier.get();
}

private void checkSharedLockState() {
if (updateGraph.sharedLock().isHeldByCurrentThread()) {
throw new UnsupportedOperationException(
"Cannot Future.get(...) while holding the " + updateGraph + " shared lock");
}
}

private void waitForResult(final Condition condition, final long timeout, @Nullable final TimeUnit unit)
throws InterruptedException, TimeoutException {
if (unit == null) {
Expand Down Expand Up @@ -138,9 +144,7 @@ public boolean complete(T value) {
}

public boolean completeExceptionally(Throwable ex) {
if (ex == null) {
throw new NullPointerException();
}
Objects.requireNonNull(ex);
return trySignalCompletion(() -> {
throw new ExecutionException(ex);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ private void onFutureComplete() {
protected void destroy() {
super.destroy();
cancel("no longer live");
if (future != null) {
future.completeExceptionally(new RequestCancelledException("Barrage subscription is no longer live"));
final FutureAdapter localFuture = future;
if (localFuture != null) {
localFuture.completeExceptionally(new RequestCancelledException("Barrage subscription is no longer live"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,12 @@ private synchronized void onExportResolved(final SessionState.ExportObject<Objec
final Object export = parent.get();
if (export instanceof QueryTable) {
final QueryTable table = (QueryTable) export;

if (table.isFailed()) {
throw Exceptions.statusRuntimeException(Code.FAILED_PRECONDITION,
"Table is already failed");
}

final UpdateGraph ug = table.getUpdateGraph();
try (final SafeCloseable ignored = ExecutionContext.getContext().withUpdateGraph(ug).open()) {
bmp = table.getResult(bmpOperationFactory.create(table, minUpdateIntervalMs));
Expand Down

0 comments on commit 5d73734

Please sign in to comment.