use of org.apache.flink.runtime.operators.util.TaskConfig in project flink by apache.
the class AllReduceDriver method prepare.
// --------------------------------------------------------------------------------------------
@Override
public void prepare() throws Exception {
final TaskConfig config = this.taskContext.getTaskConfig();
if (config.getDriverStrategy() != DriverStrategy.ALL_REDUCE) {
throw new Exception("Unrecognized driver strategy for AllReduce driver: " + config.getDriverStrategy().name());
}
TypeSerializerFactory<T> serializerFactory = this.taskContext.getInputSerializer(0);
this.serializer = serializerFactory.getSerializer();
this.input = this.taskContext.getInput(0);
ExecutionConfig executionConfig = taskContext.getExecutionConfig();
this.objectReuseEnabled = executionConfig.isObjectReuseEnabled();
if (LOG.isDebugEnabled()) {
LOG.debug("AllReduceDriver object reuse: " + (this.objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
}
}
use of org.apache.flink.runtime.operators.util.TaskConfig in project flink by apache.
the class BatchTask method initOutputs.
/**
* Creates a writer for each output. Creates an OutputCollector which forwards its input to all writers.
* The output collector applies the configured shipping strategy.
*/
@SuppressWarnings("unchecked")
public static <T> Collector<T> initOutputs(AbstractInvokable containingTask, ClassLoader cl, TaskConfig config, List<ChainedDriver<?, ?>> chainedTasksTarget, List<RecordWriter<?>> eventualOutputs, ExecutionConfig executionConfig, Map<String, Accumulator<?, ?>> accumulatorMap) throws Exception {
final int numOutputs = config.getNumOutputs();
// check whether we got any chained tasks
final int numChained = config.getNumberOfChainedStubs();
if (numChained > 0) {
// got chained stubs. that means that this one may only have a single forward connection
if (numOutputs != 1 || config.getOutputShipStrategy(0) != ShipStrategyType.FORWARD) {
throw new RuntimeException("Plan Generation Bug: Found a chained stub that is not connected via an only forward connection.");
}
// instantiate each task
@SuppressWarnings("rawtypes") Collector previous = null;
for (int i = numChained - 1; i >= 0; --i) {
// get the task first
final ChainedDriver<?, ?> ct;
try {
Class<? extends ChainedDriver<?, ?>> ctc = config.getChainedTask(i);
ct = ctc.newInstance();
} catch (Exception ex) {
throw new RuntimeException("Could not instantiate chained task driver.", ex);
}
// get the configuration for the task
final TaskConfig chainedStubConf = config.getChainedStubConfig(i);
final String taskName = config.getChainedTaskName(i);
if (i == numChained - 1) {
// last in chain, instantiate the output collector for this task
previous = getOutputCollector(containingTask, chainedStubConf, cl, eventualOutputs, 0, chainedStubConf.getNumOutputs());
}
ct.setup(chainedStubConf, taskName, previous, containingTask, cl, executionConfig, accumulatorMap);
chainedTasksTarget.add(0, ct);
if (i == numChained - 1) {
ct.getIOMetrics().reuseOutputMetricsForTask();
}
previous = ct;
}
// the collector of the first in the chain is the collector for the task
return (Collector<T>) previous;
}
// instantiate the output collector the default way from this configuration
return getOutputCollector(containingTask, config, cl, eventualOutputs, 0, numOutputs);
}
use of org.apache.flink.runtime.operators.util.TaskConfig in project flink by apache.
the class CoGroupRawDriver method prepare.
@Override
public void prepare() throws Exception {
final TaskConfig config = this.taskContext.getTaskConfig();
if (config.getDriverStrategy() != DriverStrategy.CO_GROUP_RAW) {
throw new Exception("Unrecognized driver strategy for CoGoup Python driver: " + config.getDriverStrategy().name());
}
final MutableObjectIterator<IT1> in1 = this.taskContext.getInput(0);
final MutableObjectIterator<IT2> in2 = this.taskContext.getInput(1);
IT1 reuse1 = this.taskContext.<IT1>getInputSerializer(0).getSerializer().createInstance();
IT2 reuse2 = this.taskContext.<IT2>getInputSerializer(1).getSerializer().createInstance();
this.coGroupIterator1 = new SimpleIterable<IT1>(reuse1, in1);
this.coGroupIterator2 = new SimpleIterable<IT2>(reuse2, in2);
if (LOG.isDebugEnabled()) {
LOG.debug(this.taskContext.formatLogString("CoGroup task iterator ready."));
}
}
use of org.apache.flink.runtime.operators.util.TaskConfig in project flink by apache.
the class CoGroupWithSolutionSetSecondDriver method initialize.
// --------------------------------------------------------------------------------------------
@Override
@SuppressWarnings("unchecked")
public void initialize() throws Exception {
final TypeComparator<IT2> solutionSetComparator;
// grab a handle to the hash table from the iteration broker
if (taskContext instanceof AbstractIterativeTask) {
AbstractIterativeTask<?, ?> iterativeTaskContext = (AbstractIterativeTask<?, ?>) taskContext;
String identifier = iterativeTaskContext.brokerKey();
Object table = SolutionSetBroker.instance().get(identifier);
if (table instanceof CompactingHashTable) {
this.hashTable = (CompactingHashTable<IT2>) table;
solutionSetSerializer = this.hashTable.getBuildSideSerializer();
solutionSetComparator = this.hashTable.getBuildSideComparator().duplicate();
} else if (table instanceof JoinHashMap) {
this.objectMap = (JoinHashMap<IT2>) table;
solutionSetSerializer = this.objectMap.getBuildSerializer();
solutionSetComparator = this.objectMap.getBuildComparator().duplicate();
} else {
throw new RuntimeException("Unrecognized solution set index: " + table);
}
} else {
throw new Exception("The task context of this driver is no iterative task context.");
}
TaskConfig config = taskContext.getTaskConfig();
ClassLoader classLoader = taskContext.getUserCodeClassLoader();
TypeComparatorFactory<IT1> probeSideComparatorFactory = config.getDriverComparator(0, classLoader);
this.probeSideSerializer = taskContext.<IT1>getInputSerializer(0).getSerializer();
this.probeSideComparator = probeSideComparatorFactory.createComparator();
ExecutionConfig executionConfig = taskContext.getExecutionConfig();
objectReuseEnabled = executionConfig.isObjectReuseEnabled();
if (objectReuseEnabled) {
solutionSideRecord = solutionSetSerializer.createInstance();
}
;
TypePairComparatorFactory<IT1, IT2> factory = taskContext.getTaskConfig().getPairComparatorFactory(taskContext.getUserCodeClassLoader());
pairComparator = factory.createComparator12(this.probeSideComparator, solutionSetComparator);
}
use of org.apache.flink.runtime.operators.util.TaskConfig in project flink by apache.
the class CrossDriver method prepare.
@Override
public void prepare() throws Exception {
final TaskConfig config = this.taskContext.getTaskConfig();
final DriverStrategy ls = config.getDriverStrategy();
switch(ls) {
case NESTEDLOOP_BLOCKED_OUTER_FIRST:
this.blocked = true;
this.firstIsOuter = true;
break;
case NESTEDLOOP_BLOCKED_OUTER_SECOND:
this.blocked = true;
this.firstIsOuter = false;
break;
case NESTEDLOOP_STREAMED_OUTER_FIRST:
this.blocked = false;
this.firstIsOuter = true;
break;
case NESTEDLOOP_STREAMED_OUTER_SECOND:
this.blocked = false;
this.firstIsOuter = false;
break;
default:
throw new RuntimeException("Invalid local strategy for CROSS: " + ls);
}
this.memManager = this.taskContext.getMemoryManager();
final int numPages = this.memManager.computeNumberOfPages(config.getRelativeMemoryDriver());
if (numPages < 2) {
throw new RuntimeException("The Cross task was initialized with too little memory. " + "Cross requires at least 2 memory pages.");
}
// divide memory between spilling and blocking side
if (ls == DriverStrategy.NESTEDLOOP_STREAMED_OUTER_FIRST || ls == DriverStrategy.NESTEDLOOP_STREAMED_OUTER_SECOND) {
this.memPagesForSpillingSide = numPages;
this.memPagesForBlockSide = 0;
} else {
if (numPages > 32) {
this.memPagesForSpillingSide = 2;
} else {
this.memPagesForSpillingSide = 1;
}
this.memPagesForBlockSide = numPages - this.memPagesForSpillingSide;
}
ExecutionConfig executionConfig = taskContext.getExecutionConfig();
this.objectReuseEnabled = executionConfig.isObjectReuseEnabled();
if (LOG.isDebugEnabled()) {
LOG.debug("CrossDriver object reuse: " + (this.objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
}
}
Aggregations