Search in sources :

Example 11 with PTOutput

use of com.datatorrent.stram.plan.physical.PTOperator.PTOutput in project apex-core by apache.

the class PhysicalPlan method removeTerminatedPartition.

/**
   * Remove a partition that was reported as terminated by the execution layer.
   * Recursively removes all downstream operators with no remaining input.
   * @param p
   */
public void removeTerminatedPartition(PTOperator p) {
    // keep track of downstream operators for cascading remove
    Set<PTOperator> downstreamOpers = new HashSet<>(p.outputs.size());
    for (PTOutput out : p.outputs) {
        for (PTInput sinkIn : out.sinks) {
            downstreamOpers.add(sinkIn.target);
        }
    }
    PMapping currentMapping = this.logicalToPTOperator.get(p.operatorMeta);
    if (currentMapping != null) {
        List<PTOperator> copyPartitions = Lists.newArrayList(currentMapping.partitions);
        copyPartitions.remove(p);
        removePartition(p, currentMapping);
        currentMapping.partitions = copyPartitions;
    } else {
        // remove the operator
        removePTOperator(p);
    }
    // remove orphaned downstream operators
    for (PTOperator dop : downstreamOpers) {
        if (dop.inputs.isEmpty()) {
            removeTerminatedPartition(dop);
        }
    }
    deployChanges();
}
Also used : PTInput(com.datatorrent.stram.plan.physical.PTOperator.PTInput) PTOutput(com.datatorrent.stram.plan.physical.PTOperator.PTOutput) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 12 with PTOutput

use of com.datatorrent.stram.plan.physical.PTOperator.PTOutput in project apex-core by apache.

the class StreamMapping method addSlidingUnifiers.

private void addSlidingUnifiers() {
    OperatorMeta sourceOM = streamMeta.getSource().getOperatorMeta();
    if (sourceOM.getAttributes().contains(Context.OperatorContext.SLIDE_BY_WINDOW_COUNT)) {
        if (sourceOM.getValue(Context.OperatorContext.SLIDE_BY_WINDOW_COUNT) < sourceOM.getValue(Context.OperatorContext.APPLICATION_WINDOW_COUNT)) {
            plan.undeployOpers.addAll(slidingUnifiers);
            slidingUnifiers.clear();
            List<PTOutput> newUpstream = Lists.newArrayList();
            PTOperator slidingUnifier;
            for (PTOutput source : upstream) {
                slidingUnifier = StreamMapping.createSlidingUnifier(streamMeta, plan, sourceOM.getValue(Context.OperatorContext.APPLICATION_WINDOW_COUNT), sourceOM.getValue(Context.OperatorContext.SLIDE_BY_WINDOW_COUNT));
                addInput(slidingUnifier, source, null);
                this.slidingUnifiers.add(slidingUnifier);
                newUpstream.add(slidingUnifier.outputs.get(0));
            }
            upstream.clear();
            upstream.addAll(newUpstream);
        } else {
            LOG.warn("Sliding Window Count {} should be less than APPLICATION WINDOW COUNT {}", sourceOM.getValue(Context.OperatorContext.SLIDE_BY_WINDOW_COUNT), sourceOM.getValue(Context.OperatorContext.APPLICATION_WINDOW_COUNT));
        }
    }
}
Also used : OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) PTOutput(com.datatorrent.stram.plan.physical.PTOperator.PTOutput)

Example 13 with PTOutput

use of com.datatorrent.stram.plan.physical.PTOperator.PTOutput in project apex-core by apache.

the class StreamMapping method createUnifier.

public static PTOperator createUnifier(StreamMeta streamMeta, PhysicalPlan plan) {
    OperatorMeta um = streamMeta.getSource().getUnifierMeta();
    PTOperator pu = plan.newOperator(um, um.getName());
    Operator unifier = um.getOperator();
    PortMappingDescriptor mergeDesc = new PortMappingDescriptor();
    Operators.describe(unifier, mergeDesc);
    if (mergeDesc.outputPorts.size() != 1) {
        throw new AssertionError("Unifier must have a single output port, instead found : " + mergeDesc.outputPorts);
    }
    pu.unifiedOperatorMeta = streamMeta.getSource().getOperatorMeta();
    pu.outputs.add(new PTOutput(mergeDesc.outputPorts.keySet().iterator().next(), streamMeta, pu));
    plan.newOpers.put(pu, unifier);
    return pu;
}
Also used : Operator(com.datatorrent.api.Operator) OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) PTOutput(com.datatorrent.stram.plan.physical.PTOperator.PTOutput) PortMappingDescriptor(com.datatorrent.stram.plan.logical.Operators.PortMappingDescriptor)

Example 14 with PTOutput

use of com.datatorrent.stram.plan.physical.PTOperator.PTOutput in project apex-core by apache.

the class StreamMapping method setupCascadingUnifiers.

@SuppressWarnings("AssignmentToForLoopParameter")
private List<PTOutput> setupCascadingUnifiers(List<PTOutput> upstream, List<PTOperator> pooledUnifiers, int limit, int level) {
    List<PTOutput> nextLevel = Lists.newArrayList();
    PTOperator pu = null;
    for (int i = 0; i < upstream.size(); i++) {
        if (i % limit == 0) {
            if (upstream.size() - i < limit) {
                while (i < upstream.size()) {
                    nextLevel.add(upstream.get(i));
                    i++;
                }
                continue;
            }
            if (!pooledUnifiers.isEmpty()) {
                pu = pooledUnifiers.remove(0);
            } else {
                pu = createUnifier(streamMeta, plan);
            }
            assert (pu.outputs.size() == 1) : "unifier has single output";
            nextLevel.addAll(pu.outputs);
            this.cascadingUnifiers.add(pu);
        }
        PTOutput source = upstream.get(i);
        addInput(pu, source, null);
    }
    if (nextLevel.size() > limit) {
        return setupCascadingUnifiers(nextLevel, pooledUnifiers, limit, level);
    } else {
        return nextLevel;
    }
}
Also used : PTOutput(com.datatorrent.stram.plan.physical.PTOperator.PTOutput)

Example 15 with PTOutput

use of com.datatorrent.stram.plan.physical.PTOperator.PTOutput in project apex-core by apache.

the class StreamMapping method setInput.

private void setInput(PTOperator oper, InputPortMeta ipm, PTOperator sourceOper, PartitionKeys pks) {
    // TODO: see if this can be handled more efficiently
    for (PTInput in : oper.inputs) {
        if (in.source.source == sourceOper && in.logicalStream == streamMeta && ipm.getPortName().equals(in.portName)) {
            return;
        }
    }
    // link to upstream output(s) for this stream
    for (PTOutput upstreamOut : sourceOper.outputs) {
        if (upstreamOut.logicalStream == streamMeta) {
            PTInput input = new PTInput(ipm.getPortName(), streamMeta, oper, pks, upstreamOut, ipm.getValue(LogicalPlan.IS_CONNECTED_TO_DELAY_OPERATOR));
            oper.inputs.add(input);
        }
    }
}
Also used : PTInput(com.datatorrent.stram.plan.physical.PTOperator.PTInput) PTOutput(com.datatorrent.stram.plan.physical.PTOperator.PTOutput)

Aggregations

PTOutput (com.datatorrent.stram.plan.physical.PTOperator.PTOutput)20 PTInput (com.datatorrent.stram.plan.physical.PTOperator.PTInput)13 OperatorMeta (com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta)9 Checkpoint (com.datatorrent.stram.api.Checkpoint)6 LogicalPlan (com.datatorrent.stram.plan.logical.LogicalPlan)6 PartitioningTest (com.datatorrent.stram.PartitioningTest)5 GenericTestOperator (com.datatorrent.stram.engine.GenericTestOperator)5 TestPlanContext (com.datatorrent.stram.plan.TestPlanContext)5 Test (org.junit.Test)5 StatsListener (com.datatorrent.api.StatsListener)4 InputPortMeta (com.datatorrent.stram.plan.logical.LogicalPlan.InputPortMeta)4 ArrayList (java.util.ArrayList)3 Operator (com.datatorrent.api.Operator)2 PortMappingDescriptor (com.datatorrent.stram.plan.logical.Operators.PortMappingDescriptor)2 HashSet (java.util.HashSet)2 InputPort (com.datatorrent.api.Operator.InputPort)1 OutputPort (com.datatorrent.api.Operator.OutputPort)1 PartitionKeys (com.datatorrent.api.Partitioner.PartitionKeys)1 StreamCodec (com.datatorrent.api.StreamCodec)1 Pair (com.datatorrent.common.util.Pair)1