use of org.apache.hyracks.api.dataflow.IActivity in project asterixdb by apache.
the class ActivityClusterGraphBuilder method inferActivityClusters.
public ActivityClusterGraph inferActivityClusters(JobId jobId, JobActivityGraph jag) {
/*
* Build initial equivalence sets map. We create a map such that for each IOperatorTask, t -> { t }
*/
Map<ActivityId, Set<ActivityId>> stageMap = new HashMap<ActivityId, Set<ActivityId>>();
Set<Set<ActivityId>> stages = new HashSet<Set<ActivityId>>();
for (ActivityId taskId : jag.getActivityMap().keySet()) {
Set<ActivityId> eqSet = new HashSet<ActivityId>();
eqSet.add(taskId);
stageMap.put(taskId, eqSet);
stages.add(eqSet);
}
boolean changed = true;
while (changed) {
changed = false;
Pair<ActivityId, ActivityId> pair = findMergePair(jag, stages);
if (pair != null) {
merge(stageMap, stages, pair.getLeft(), pair.getRight());
changed = true;
}
}
ActivityClusterGraph acg = new ActivityClusterGraph();
Map<ActivityId, ActivityCluster> acMap = new HashMap<ActivityId, ActivityCluster>();
int acCounter = 0;
Map<ActivityId, IActivity> activityNodeMap = jag.getActivityMap();
List<ActivityCluster> acList = new ArrayList<ActivityCluster>();
for (Set<ActivityId> stage : stages) {
ActivityCluster ac = new ActivityCluster(acg, new ActivityClusterId(jobId, acCounter++));
acList.add(ac);
for (ActivityId aid : stage) {
IActivity activity = activityNodeMap.get(aid);
ac.addActivity(activity);
acMap.put(aid, ac);
}
}
for (Set<ActivityId> stage : stages) {
for (ActivityId aid : stage) {
IActivity activity = activityNodeMap.get(aid);
ActivityCluster ac = acMap.get(aid);
List<IConnectorDescriptor> aOutputs = jag.getActivityOutputMap().get(aid);
if (aOutputs == null || aOutputs.isEmpty()) {
ac.addRoot(activity);
} else {
int nActivityOutputs = aOutputs.size();
for (int i = 0; i < nActivityOutputs; ++i) {
IConnectorDescriptor conn = aOutputs.get(i);
ac.addConnector(conn);
Pair<Pair<IActivity, Integer>, Pair<IActivity, Integer>> pcPair = jag.getConnectorActivityMap().get(conn.getConnectorId());
ac.connect(conn, activity, i, pcPair.getRight().getLeft(), pcPair.getRight().getRight(), jag.getConnectorRecordDescriptorMap().get(conn.getConnectorId()));
}
}
}
}
Map<ActivityId, Set<ActivityId>> blocked2BlockerMap = jag.getBlocked2BlockerMap();
for (ActivityCluster s : acList) {
Map<ActivityId, Set<ActivityId>> acBlocked2BlockerMap = s.getBlocked2BlockerMap();
Set<ActivityCluster> blockerStages = new HashSet<ActivityCluster>();
for (ActivityId t : s.getActivityMap().keySet()) {
Set<ActivityId> blockerTasks = blocked2BlockerMap.get(t);
acBlocked2BlockerMap.put(t, blockerTasks);
if (blockerTasks != null) {
for (ActivityId bt : blockerTasks) {
blockerStages.add(acMap.get(bt));
}
}
}
for (ActivityCluster bs : blockerStages) {
s.getDependencies().add(bs);
}
}
acg.addActivityClusters(acList);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(acg.toJSON().asText());
}
return acg;
}
use of org.apache.hyracks.api.dataflow.IActivity in project asterixdb by apache.
the class SuperActivityOperatorNodePushable method init.
private void init() throws HyracksDataException {
Queue<Pair<Pair<IActivity, Integer>, Pair<IActivity, Integer>>> childQueue = new LinkedList<>();
List<IConnectorDescriptor> outputConnectors;
/*
* Set up the source operators
*/
for (Entry<ActivityId, IActivity> entry : startActivities.entrySet()) {
IOperatorNodePushable opPushable = entry.getValue().createPushRuntime(ctx, recordDescProvider, partition, nPartitions);
operatorNodePushablesBFSOrder.add(opPushable);
operatorNodePushables.put(entry.getKey(), opPushable);
inputArity += opPushable.getInputArity();
outputConnectors = MapUtils.getObject(parent.getActivityOutputMap(), entry.getKey(), Collections.emptyList());
for (IConnectorDescriptor conn : outputConnectors) {
childQueue.add(parent.getConnectorActivityMap().get(conn.getConnectorId()));
}
}
/*
* Using BFS (breadth-first search) to construct to runtime execution DAG...
*/
while (!childQueue.isEmpty()) {
/*
* construct the source to destination information
*/
Pair<Pair<IActivity, Integer>, Pair<IActivity, Integer>> channel = childQueue.poll();
ActivityId sourceId = channel.getLeft().getLeft().getActivityId();
int outputChannel = channel.getLeft().getRight();
ActivityId destId = channel.getRight().getLeft().getActivityId();
int inputChannel = channel.getRight().getRight();
IOperatorNodePushable sourceOp = operatorNodePushables.get(sourceId);
IOperatorNodePushable destOp = operatorNodePushables.get(destId);
if (destOp == null) {
destOp = channel.getRight().getLeft().createPushRuntime(ctx, recordDescProvider, partition, nPartitions);
operatorNodePushablesBFSOrder.add(destOp);
operatorNodePushables.put(destId, destOp);
}
/*
* construct the dataflow connection from a producer to a consumer
*/
sourceOp.setOutputFrameWriter(outputChannel, destOp.getInputFrameWriter(inputChannel), recordDescProvider.getInputRecordDescriptor(destId, inputChannel));
/*
* traverse to the child of the current activity
*/
outputConnectors = MapUtils.getObject(parent.getActivityOutputMap(), destId, Collections.emptyList());
/*
* expend the executing activities further to the downstream
*/
for (IConnectorDescriptor conn : outputConnectors) {
if (conn != null) {
childQueue.add(parent.getConnectorActivityMap().get(conn.getConnectorId()));
}
}
}
}
use of org.apache.hyracks.api.dataflow.IActivity in project asterixdb by apache.
the class IntersectOperatorDescriptor method contributeActivities.
@Override
public void contributeActivities(IActivityGraphBuilder builder) {
IActivity intersectActivity = new IntersectActivity(new ActivityId(getOperatorId(), 0));
builder.addActivity(this, intersectActivity);
for (int i = 0; i < getInputArity(); i++) {
builder.addSourceEdge(i, intersectActivity, i);
}
builder.addTargetEdge(0, intersectActivity, 0);
}
use of org.apache.hyracks.api.dataflow.IActivity in project asterixdb by apache.
the class StartTasksWork method run.
@Override
public void run() {
Task task = null;
try {
NCServiceContext serviceCtx = ncs.getContext();
Joblet joblet = getOrCreateLocalJoblet(deploymentId, jobId, serviceCtx, acgBytes);
final ActivityClusterGraph acg = joblet.getActivityClusterGraph();
IRecordDescriptorProvider rdp = new IRecordDescriptorProvider() {
@Override
public RecordDescriptor getOutputRecordDescriptor(ActivityId aid, int outputIndex) {
ActivityCluster ac = acg.getActivityMap().get(aid);
IConnectorDescriptor conn = ac.getActivityOutputMap().get(aid).get(outputIndex);
return ac.getConnectorRecordDescriptorMap().get(conn.getConnectorId());
}
@Override
public RecordDescriptor getInputRecordDescriptor(ActivityId aid, int inputIndex) {
ActivityCluster ac = acg.getActivityMap().get(aid);
IConnectorDescriptor conn = ac.getActivityInputMap().get(aid).get(inputIndex);
return ac.getConnectorRecordDescriptorMap().get(conn.getConnectorId());
}
};
for (TaskAttemptDescriptor td : taskDescriptors) {
TaskAttemptId taId = td.getTaskAttemptId();
TaskId tid = taId.getTaskId();
ActivityId aid = tid.getActivityId();
ActivityCluster ac = acg.getActivityMap().get(aid);
IActivity han = ac.getActivityMap().get(aid);
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info("Initializing " + taId + " -> " + han);
}
final int partition = tid.getPartition();
List<IConnectorDescriptor> inputs = ac.getActivityInputMap().get(aid);
task = new Task(joblet, taId, han.getClass().getName(), ncs.getExecutor(), ncs, createInputChannels(td, inputs));
IOperatorNodePushable operator = han.createPushRuntime(task, rdp, partition, td.getPartitionCount());
List<IPartitionCollector> collectors = new ArrayList<>();
if (inputs != null) {
for (int i = 0; i < inputs.size(); ++i) {
IConnectorDescriptor conn = inputs.get(i);
IConnectorPolicy cPolicy = connectorPoliciesMap.get(conn.getConnectorId());
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info("input: " + i + ": " + conn.getConnectorId());
}
RecordDescriptor recordDesc = ac.getConnectorRecordDescriptorMap().get(conn.getConnectorId());
IPartitionCollector collector = createPartitionCollector(td, partition, task, i, conn, recordDesc, cPolicy);
collectors.add(collector);
}
}
List<IConnectorDescriptor> outputs = ac.getActivityOutputMap().get(aid);
if (outputs != null) {
for (int i = 0; i < outputs.size(); ++i) {
final IConnectorDescriptor conn = outputs.get(i);
RecordDescriptor recordDesc = ac.getConnectorRecordDescriptorMap().get(conn.getConnectorId());
IConnectorPolicy cPolicy = connectorPoliciesMap.get(conn.getConnectorId());
IPartitionWriterFactory pwFactory = createPartitionWriterFactory(task, cPolicy, jobId, conn, partition, taId, flags);
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info("output: " + i + ": " + conn.getConnectorId());
}
IFrameWriter writer = conn.createPartitioner(task, recordDesc, pwFactory, partition, td.getPartitionCount(), td.getOutputPartitionCounts()[i]);
operator.setOutputFrameWriter(i, writer, recordDesc);
}
}
task.setTaskRuntime(collectors.toArray(new IPartitionCollector[collectors.size()]), operator);
joblet.addTask(task);
task.start();
}
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Failure starting a task", e);
// notify cc of start task failure
List<Exception> exceptions = new ArrayList<>();
ExceptionUtils.setNodeIds(exceptions, ncs.getId());
ncs.getWorkQueue().schedule(new NotifyTaskFailureWork(ncs, task, exceptions));
}
}
use of org.apache.hyracks.api.dataflow.IActivity in project asterixdb by apache.
the class ActivityCluster method toJSON.
public JsonNode toJSON() {
ObjectMapper om = new ObjectMapper();
ArrayNode jans = om.createArrayNode();
ObjectNode jac = om.createObjectNode();
for (IActivity an : activities.values()) {
ObjectNode jan = om.createObjectNode();
jan.put("id", an.getActivityId().toString());
jan.put("java-class", an.getClass().getName());
List<IConnectorDescriptor> inputs = activityInputMap.get(an.getActivityId());
if (inputs != null) {
ArrayNode jInputs = om.createArrayNode();
for (int i = 0; i < inputs.size(); ++i) {
ObjectNode jInput = om.createObjectNode();
jInput.put("input-port", i);
jInput.put("connector-id", inputs.get(i).getConnectorId().toString());
jInputs.add(jInput);
}
jan.set("inputs", jInputs);
}
List<IConnectorDescriptor> outputs = activityOutputMap.get(an.getActivityId());
if (outputs != null) {
ArrayNode jOutputs = om.createArrayNode();
for (int i = 0; i < outputs.size(); ++i) {
ObjectNode jOutput = om.createObjectNode();
jOutput.put("output-port", i);
jOutput.put("connector-id", outputs.get(i).getConnectorId().toString());
jOutputs.add(jOutput);
}
jan.set("outputs", jOutputs);
}
Set<ActivityId> blockers = getBlocked2BlockerMap().get(an.getActivityId());
if (blockers != null) {
ArrayNode jDeps = om.createArrayNode();
for (ActivityId blocker : blockers) {
jDeps.add(blocker.toString());
}
jan.set("depends-on", jDeps);
}
jans.add(jan);
}
jac.set("activities", jans);
return jac;
}
Aggregations