@Override protected void doExecute() { TaskActivator readyActivator; while ((readyActivator = this.readyActivators.poll()) != null) { // Execute the ExecutionTask. final ExecutionTask task = readyActivator.getTask(); final Tuple<List<ChannelInstance>, PartialExecution> executionResult = this.execute(readyActivator, task); readyActivator.dispose(); // Register the outputChannelInstances (to obtain cardinality measurements and for further stages). final List<ChannelInstance> outputChannelInstances = executionResult.getField0(); outputChannelInstances.stream().filter(Objects::nonNull).forEach(this::store); // Log executions. final PartialExecution partialExecution = executionResult.getField1(); if (partialExecution != null) { this.executionState.add(partialExecution); } // Activate successor ExecutionTasks. this.activateSuccessorTasks(task, outputChannelInstances); outputChannelInstances.stream().filter(Objects::nonNull).forEach(ChannelInstance::disposeIfUnreferenced); } }
/** * Puts an {@link ExecutionTask} into execution. * * @param readyActivator activated the {@code task} * @param task should be executed * @return the {@link ChannelInstance}s created by the {@code task} and a {@link PartialExecution} or * {@code null} if something has been actually executed */ private Tuple<List<ChannelInstance>, PartialExecution> execute(TaskActivator readyActivator, ExecutionTask task) { final boolean isRequestEagerExecution = this.terminalTasks.contains(task); return this.executor().execute(readyActivator, isRequestEagerExecution); }
private void scheduleStartTask(ExecutionTask startTask) { TaskActivator activator = new TaskActivator(startTask, this.fetchOperatorContext(startTask), this.executionState); assert activator.isReady() : String.format("Stage starter %s is not immediately ready.", startTask); this.readyActivators.add(activator); }
private void activateSuccessorTasks(ExecutionTask task, Collection<ChannelInstance> outputChannelInstances) { for (ChannelInstance outputChannelInstance : outputChannelInstances) { if (outputChannelInstance == null) continue; // Partial results possible (cf. LoopHeadOperator). final Channel channel = outputChannelInstance.getChannel(); for (ExecutionTask consumer : channel.getConsumers()) { // Stay within ExecutionStage. if (consumer.getStage() != task.getStage() || consumer.getOperator().isLoopHead()) continue; // Get or create the TaskActivator. final TaskActivator consumerActivator = this.stagedActivators.computeIfAbsent( consumer, (key) -> new TaskActivator(key, this.fetchOperatorContext(key), this.executionState) ); // Register the outputChannelInstance. consumerActivator.accept(outputChannelInstance); // Schedule the consumerActivator if it isReady. if (consumerActivator.isReady()) { this.stagedActivators.remove(consumer); this.readyActivators.add(consumerActivator); } } } }
/** * Executes the {@link ExecutionStage} and contributes results to the {@link #executionState}. */ void executeStage() { this.execute(); this.updateExecutionState(); }
@Override public void execute(ExecutionStage stage, OptimizationContext optimizationContext, ExecutionState executionState) { assert !this.isDisposed() : String.format("%s has been disposed.", this); final StageExecution stageExecution = new StageExecution(stage, optimizationContext, executionState); stageExecution.executeStage(); }