public boolean isFinished() { checkLockNotHeld("Can not check finished status while holding the driver lock"); // if we can get the lock, attempt a clean shutdown; otherwise someone else will shutdown Optional<Boolean> result = tryWithLock(this::isFinishedInternal); return result.orElseGet(() -> state.get() != State.ALIVE || driverContext.isDone()); }
public void updateSource(TaskSource sourceUpdate) { checkLockNotHeld("Can not update sources while holding the driver lock"); checkArgument( sourceOperator.isPresent() && sourceOperator.get().getSourceId().equals(sourceUpdate.getPlanNodeId()), "sourceUpdate is for a plan node that is different from this Driver's source node"); // stage the new updates pendingTaskSourceUpdates.updateAndGet(current -> current == null ? sourceUpdate : current.update(sourceUpdate)); // attempt to get the lock and process the updates we staged above // updates will be processed in close if and only if we got the lock tryWithLock(() -> TRUE); }
public ListenableFuture<?> process() { checkLockNotHeld("Can not process while holding the driver lock"); // if the driver is blocked we don't need to continue SettableFuture<?> blockedFuture = driverBlockedFuture.get(); if (!blockedFuture.isDone()) { return blockedFuture; } Optional<ListenableFuture<?>> result = tryWithLock(100, TimeUnit.MILLISECONDS, () -> { ListenableFuture<?> future = processInternal(createTimer()); return updateDriverBlockedFuture(future); }); return result.orElse(NOT_BLOCKED); }
private <T> Optional<T> tryWithLock(long timeout, TimeUnit unit, Supplier<T> task) checkLockNotHeld("Lock can not be reacquired");
public ListenableFuture<?> processFor(Duration duration) checkLockNotHeld("Can not process for a duration while holding the driver lock");
private DriverLockResult tryLockAndProcessPendingStateChanges(int timeout, TimeUnit unit) { checkLockNotHeld("Can not acquire the driver lock while already holding the driver lock"); return new DriverLockResult(timeout, unit); }
public ListenableFuture<?> process() { checkLockNotHeld("Can not process while holding the driver lock"); try (DriverLockResult lockResult = tryLockAndProcessPendingStateChanges(100, TimeUnit.MILLISECONDS)) { if (!lockResult.wasAcquired()) { // this is unlikely to happen unless the driver is being // destroyed and in that case the caller should notice notice // this state change by calling isFinished return NOT_BLOCKED; } return processInternal(); } }
public boolean isFinished() { checkLockNotHeld("Can not check finished status while holding the driver lock"); // if we can get the lock, attempt a clean shutdown; otherwise someone else will shutdown try (DriverLockResult lockResult = tryLockAndProcessPendingStateChanges(0, TimeUnit.MILLISECONDS)) { if (lockResult.wasAcquired()) { return isFinishedInternal(); } else { // did not get the lock, so we can't check operators, or destroy return state.get() != State.ALIVE || driverContext.isDone(); } } }
public void updateSource(TaskSource source) checkLockNotHeld("Can not update sources while holding the driver lock");
public ListenableFuture<?> processFor(Duration duration) { checkLockNotHeld("Can not process for a duration while holding the driver lock"); requireNonNull(duration, "duration is null"); long maxRuntime = duration.roundTo(TimeUnit.NANOSECONDS); try (DriverLockResult lockResult = tryLockAndProcessPendingStateChanges(100, TimeUnit.MILLISECONDS)) { if (lockResult.wasAcquired()) { driverContext.startProcessTimer(); try { long start = System.nanoTime(); do { ListenableFuture<?> future = processInternal(); if (!future.isDone()) { return future; } } while (System.nanoTime() - start < maxRuntime && !isFinishedInternal()); } finally { driverContext.recordProcessed(); } } } return NOT_BLOCKED; }