/** * Injects the cardinalities of a current {@link ExecutionState} into its associated {@link RheemPlan}. * * @return whether any cardinalities have been injected */ private boolean injectMeasuredCardinalities(ExecutionState executionState) { executionState.getCardinalityMeasurements().forEach(this::injectMeasuredCardinality); return !executionState.getCardinalityMeasurements().isEmpty(); }
/** * Brings the given {@code task} into execution. */ private void execute(ExecutionTask task, OptimizationContext optimizationContext, ExecutionState executionState) { final GraphChiExecutionOperator graphChiExecutionOperator = (GraphChiExecutionOperator) task.getOperator(); ChannelInstance[] inputChannelInstances = new ChannelInstance[task.getNumInputChannels()]; for (int i = 0; i < inputChannelInstances.length; i++) { inputChannelInstances[i] = executionState.getChannelInstance(task.getInputChannel(i)); } final OptimizationContext.OperatorContext operatorContext = optimizationContext.getOperatorContext(graphChiExecutionOperator); ChannelInstance[] outputChannelInstances = new ChannelInstance[task.getNumOuputChannels()]; for (int i = 0; i < outputChannelInstances.length; i++) { outputChannelInstances[i] = task.getOutputChannel(i).createInstance(this, operatorContext, i); } long startTime = System.currentTimeMillis(); final Tuple<Collection<ExecutionLineageNode>, Collection<ChannelInstance>> results = graphChiExecutionOperator.execute(inputChannelInstances, outputChannelInstances, operatorContext); long endTime = System.currentTimeMillis(); final Collection<ExecutionLineageNode> executionLineageNodes = results.getField0(); final Collection<ChannelInstance> producedChannelInstances = results.getField1(); for (ChannelInstance outputChannelInstance : outputChannelInstances) { if (outputChannelInstance != null) { executionState.register(outputChannelInstance); } } final PartialExecution partialExecution = this.createPartialExecution(executionLineageNodes, endTime - startTime); executionState.add(partialExecution); this.registerMeasuredCardinalities(producedChannelInstances); }
@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); } }
/** * Accept input {@link ChannelInstance}s from the given {@link ExecutionState}. * * @param executionState provides {@link ChannelInstance}s */ private void acceptFrom(ExecutionState executionState) { for (int inputIndex = 0; inputIndex < this.task.getNumInputChannels(); inputIndex++) { final Channel channel = this.task.getInputChannel(inputIndex); final ChannelInstance channelInstance = executionState.getChannelInstance(channel); if (channelInstance != null) { this.accept(channelInstance); } } }
/** * Put new {@link ChannelInstance}s to the {@link #executionState} and release input {@link ChannelInstance}s. */ private void updateExecutionState() { for (final ChannelInstance channelInstance : this.allChannelInstances) { // Capture outbound ChannelInstances. if (channelInstance.getChannel().isBetweenStages() || channelInstance.getChannel().getConsumers().stream() .anyMatch(consumer -> consumer.getOperator().isLoopHead())) { this.executionState.register(channelInstance); } // Release the ChannelInstance. channelInstance.noteDiscardedReference(true); } this.allChannelInstances.clear(); } }