@Override public ListenableFuture<?> isBlocked() { return statisticsAggregationOperator.isBlocked(); }
private Optional<ListenableFuture<?>> getBlockedFuture(Operator operator) { ListenableFuture<?> blocked = revokingOperators.get(operator); if (blocked != null) { // We mark operator as blocked regardless of blocked.isDone(), because finishMemoryRevoke has not been called yet. return Optional.of(blocked); } blocked = operator.isBlocked(); if (!blocked.isDone()) { return Optional.of(blocked); } blocked = operator.getOperatorContext().isWaitingForMemory(); if (!blocked.isDone()) { return Optional.of(blocked); } blocked = operator.getOperatorContext().isWaitingForRevocableMemory(); if (!blocked.isDone()) { return Optional.of(blocked); } return Optional.empty(); }
private static boolean waitForOperatorToUnblock(Operator operator, Duration timeout) { try { operator.isBlocked().get(timeout.toMillis(), TimeUnit.MILLISECONDS); return true; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException("interrupted", e); } catch (ExecutionException e) { throw new RuntimeException(e.getCause()); } catch (TimeoutException expected) { return false; } }
@Override public void addInput(Page page) { requireNonNull(page, "page is null"); checkState(needsInput(), "Operator does not need input"); Block[] blocks = new Block[columnChannels.size()]; for (int outputChannel = 0; outputChannel < columnChannels.size(); outputChannel++) { blocks[outputChannel] = page.getBlock(columnChannels.get(outputChannel)); } OperationTimer timer = new OperationTimer(statisticsCpuTimerEnabled); statisticAggregationOperator.addInput(page); timer.end(statisticsTiming); ListenableFuture<?> blockedOnAggregation = statisticAggregationOperator.isBlocked(); CompletableFuture<?> future = pageSink.appendPage(new Page(blocks)); updateMemoryUsage(); ListenableFuture<?> blockedOnWrite = toListenableFuture(future); blocked = allAsList(blockedOnAggregation, blockedOnWrite); rowCount += page.getPositionCount(); updateWrittenBytes(); }
private static boolean handledBlocked(Operator operator) { ListenableFuture<?> isBlocked = operator.isBlocked(); if (!isBlocked.isDone()) { tryGetFutureValue(isBlocked, 1, TimeUnit.MILLISECONDS); return true; } return false; }
@Override public void finish() { ListenableFuture<?> currentlyBlocked = blocked; OperationTimer timer = new OperationTimer(statisticsCpuTimerEnabled); statisticAggregationOperator.finish(); timer.end(statisticsTiming); ListenableFuture<?> blockedOnAggregation = statisticAggregationOperator.isBlocked(); ListenableFuture<?> blockedOnFinish = NOT_BLOCKED; if (state == State.RUNNING) { state = State.FINISHING; finishFuture = pageSink.finish(); blockedOnFinish = toListenableFuture(finishFuture); updateWrittenBytes(); } this.blocked = allAsList(currentlyBlocked, blockedOnAggregation, blockedOnFinish); }
@Test(expectedExceptions = IllegalStateException.class) public void addInputFailsOnBlockedOperator() { Operator operator = createTableWriterOperator(new BlockingPageSink()); operator.addInput(rowPagesBuilder(BIGINT).row(42).build().get(0)); assertFalse(operator.isBlocked().isDone()); assertFalse(operator.needsInput()); operator.addInput(rowPagesBuilder(BIGINT).row(42).build().get(0)); }
verify(statisticsAggregationOperator.isBlocked().isDone(), "aggregation operator should not be blocked");
assertTrue(operator.isBlocked().isDone()); assertFalse(operator.isFinished()); assertTrue(operator.needsInput()); assertFalse(operator.isBlocked().isDone()); assertFalse(operator.isFinished()); assertFalse(operator.needsInput()); assertTrue(operator.isBlocked().isDone()); assertFalse(operator.isFinished()); assertTrue(operator.needsInput()); assertFalse(operator.isBlocked().isDone()); assertFalse(operator.isFinished()); assertFalse(operator.needsInput()); assertFalse(operator.isBlocked().isDone()); assertFalse(operator.isFinished()); assertFalse(operator.needsInput()); rowPagesBuilder(expectedTypes).row(2, null).build().get(0)); assertTrue(operator.isBlocked().isDone()); assertTrue(operator.isFinished()); assertFalse(operator.needsInput());
private static Page getAtMostOnePage(Operator operator, Page sourcePage) { // add our input page if needed if (operator.needsInput()) { operator.addInput(sourcePage); } // try to get the output page Page result = operator.getOutput(); // tell operator to finish operator.finish(); // try to get output until the operator is finished while (!operator.isFinished()) { // operator should never block assertTrue(operator.isBlocked().isDone()); Page output = operator.getOutput(); if (output != null) { assertNull(result); result = output; } } return result; }
nestedLoopBuildOperatorFactory.noMoreOperators(); while (nestedLoopBuildOperator.isBlocked().isDone()) { driver.process();
private static ListenableFuture<?> isBlocked(Operator operator) { ListenableFuture<?> blocked = operator.isBlocked(); if (blocked.isDone()) { blocked = operator.getOperatorContext().isWaitingForMemory(); } return blocked; }
@Test(expectedExceptions = IllegalStateException.class) public void addInputFailsOnBlockedOperator() throws Exception { Operator operator = createTableWriterOperator(new BlockingPageSink()); operator.addInput(rowPagesBuilder(BIGINT).row(42).build().get(0)); assertEquals(operator.isBlocked().isDone(), false); assertEquals(operator.needsInput(), false); operator.addInput(rowPagesBuilder(BIGINT).row(42).build().get(0)); }
assertEquals(operator.isBlocked().isDone(), true); assertEquals(operator.isFinished(), false); assertEquals(operator.needsInput(), true); assertEquals(operator.isBlocked().isDone(), false); assertEquals(operator.isFinished(), false); assertEquals(operator.needsInput(), false); assertEquals(operator.isBlocked().isDone(), true); assertEquals(operator.isFinished(), false); assertEquals(operator.needsInput(), true); assertEquals(operator.isBlocked().isDone(), false); assertEquals(operator.isFinished(), false); assertEquals(operator.needsInput(), false); assertEquals(operator.isBlocked().isDone(), false); assertEquals(operator.isFinished(), false); assertEquals(operator.needsInput(), false); rowPagesBuilder(TableWriterOperator.TYPES).row(2, null).build().get(0)); assertEquals(operator.isBlocked().isDone(), true); assertEquals(operator.isFinished(), true); assertEquals(operator.needsInput(), false);
private static Page getAtMostOnePage(Operator operator, Page sourcePage) { // add our input page if needed if (operator.needsInput()) { operator.addInput(sourcePage); } // try to get the output page Page result = operator.getOutput(); // tell operator to finish operator.finish(); // try to get output until the operator is finished while (!operator.isFinished()) { // operator should never block assertTrue(operator.isBlocked().isDone()); Page output = operator.getOutput(); if (output != null) { assertNull(result); result = output; } } return result; }