private Driver(DriverContext driverContext, List<Operator> operators) { this.driverContext = requireNonNull(driverContext, "driverContext is null"); this.allOperators = ImmutableList.copyOf(requireNonNull(operators, "operators is null")); checkArgument(allOperators.size() > 1, "At least two operators are required"); this.activeOperators = new ArrayList<>(operators); checkArgument(!operators.isEmpty(), "There must be at least one operator"); Optional<SourceOperator> sourceOperator = Optional.empty(); Optional<DeleteOperator> deleteOperator = Optional.empty(); for (Operator operator : operators) { if (operator instanceof SourceOperator) { checkArgument(!sourceOperator.isPresent(), "There must be at most one SourceOperator"); sourceOperator = Optional.of((SourceOperator) operator); } else if (operator instanceof DeleteOperator) { checkArgument(!deleteOperator.isPresent(), "There must be at most one DeleteOperator"); deleteOperator = Optional.of((DeleteOperator) operator); } } this.sourceOperator = sourceOperator; this.deleteOperator = deleteOperator; currentTaskSource = sourceOperator.map(operator -> new TaskSource(operator.getSourceId(), ImmutableSet.of(), false)).orElse(null); // initially the driverBlockedFuture is not blocked (it is completed) SettableFuture<?> future = SettableFuture.create(); future.set(null); driverBlockedFuture.set(future); }
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 Driver(DriverContext driverContext, List<Operator> operators) { this.driverContext = requireNonNull(driverContext, "driverContext is null"); this.operators = ImmutableList.copyOf(requireNonNull(operators, "operators is null")); checkArgument(!operators.isEmpty(), "There must be at least one operator"); ImmutableMap.Builder<PlanNodeId, SourceOperator> sourceOperators = ImmutableMap.builder(); Optional<DeleteOperator> deleteOperator = Optional.empty(); for (Operator operator : operators) { if (operator instanceof SourceOperator) { SourceOperator sourceOperator = (SourceOperator) operator; sourceOperators.put(sourceOperator.getSourceId(), sourceOperator); } else if (operator instanceof DeleteOperator) { checkArgument(!deleteOperator.isPresent(), "There must be at most one DeleteOperator"); deleteOperator = Optional.of((DeleteOperator) operator); } } this.sourceOperators = sourceOperators.build(); this.deleteOperator = deleteOperator; }