Search in sources :

Example 26 with MISTEdge

use of edu.snu.mist.common.graph.MISTEdge in project mist by snuspl.

the class MISTStreamImpl method transformToSingleInputContinuousStream.

/**
 * Transform the upstream to a new continuous stream
 * by applying the operation corresponding to the given configuration.
 * @param opConf configuration
 * @param upStream upstream
 * @param <OUT> output type
 * @return continuous stream
 */
protected <OUT> ContinuousStream<OUT> transformToSingleInputContinuousStream(final Map<String, String> opConf, final MISTStream upStream) {
    final ContinuousStream<OUT> downStream = new ContinuousStreamImpl<>(dag, opConf);
    dag.addVertex(downStream);
    dag.addEdge(upStream, downStream, new MISTEdge(Direction.LEFT));
    return downStream;
}
Also used : MISTEdge(edu.snu.mist.common.graph.MISTEdge)

Example 27 with MISTEdge

use of edu.snu.mist.common.graph.MISTEdge in project mist by snuspl.

the class ImmediateQueryMergingStarter method generate.

/**
 * This generates a new execution dag from the configuration dag.
 */
private ExecutionDag generate(final DAG<ConfigVertex, MISTEdge> configDag, final URL[] urls, final ClassLoader classLoader) throws IOException, ClassNotFoundException {
    // For execution dag
    final ExecutionDag executionDag = new ExecutionDag(new AdjacentListConcurrentMapDAG<>());
    final Map<ConfigVertex, ExecutionVertex> created = new HashMap<>(configDag.numberOfVertices());
    for (final ConfigVertex source : configDag.getRootVertices()) {
        final ExecutionVertex currExecutionVertex = executionVertexGenerator.generate(source, urls, classLoader);
        created.put(source, currExecutionVertex);
        configExecutionVertexMap.put(source, currExecutionVertex);
        executionVertexCountMap.put(currExecutionVertex, 1);
        executionVertexDagMap.put(currExecutionVertex, executionDag);
        executionDag.getDag().addVertex(currExecutionVertex);
        // do dfs creation
        for (final Map.Entry<ConfigVertex, MISTEdge> edges : configDag.getEdges(source).entrySet()) {
            final ConfigVertex childVertex = edges.getKey();
            final MISTEdge edge = edges.getValue();
            dfsCreation(currExecutionVertex, edge, childVertex, created, configDag, executionDag, urls, classLoader);
        }
    }
    return executionDag;
}
Also used : MISTEdge(edu.snu.mist.common.graph.MISTEdge)

Example 28 with MISTEdge

use of edu.snu.mist.common.graph.MISTEdge in project mist by snuspl.

the class ImmediateQueryMergingStarter method dfsCreation.

/**
 * Create the execution dag in dfs order.
 */
private void dfsCreation(final ExecutionVertex parent, final MISTEdge parentEdge, final ConfigVertex currVertex, final Map<ConfigVertex, ExecutionVertex> created, final DAG<ConfigVertex, MISTEdge> configDag, final ExecutionDag executionDag, final URL[] urls, final ClassLoader classLoader) throws IOException, ClassNotFoundException {
    final ExecutionVertex currExecutionVertex;
    if (created.get(currVertex) == null) {
        currExecutionVertex = executionVertexGenerator.generate(currVertex, urls, classLoader);
        created.put(currVertex, currExecutionVertex);
        executionVertexCountMap.put(currExecutionVertex, 1);
        executionVertexDagMap.put(currExecutionVertex, executionDag);
        executionDag.getDag().addVertex(currExecutionVertex);
        // do dfs creation
        for (final Map.Entry<ConfigVertex, MISTEdge> edges : configDag.getEdges(currVertex).entrySet()) {
            final ConfigVertex childVertex = edges.getKey();
            final MISTEdge edge = edges.getValue();
            dfsCreation(currExecutionVertex, edge, childVertex, created, configDag, executionDag, urls, classLoader);
        }
    } else {
        currExecutionVertex = created.get(currVertex);
    }
    configExecutionVertexMap.put(currVertex, currExecutionVertex);
    executionDag.getDag().addEdge(parent, currExecutionVertex, parentEdge);
}
Also used : MISTEdge(edu.snu.mist.common.graph.MISTEdge)

Example 29 with MISTEdge

use of edu.snu.mist.common.graph.MISTEdge in project mist by snuspl.

the class LogicalDagOptimizer method getOptimizedDAG.

/**
 * Apply optimization techniques to the logical DAG.
 * @return the optimized DAG
 */
public DAG<MISTStream, MISTEdge> getOptimizedDAG() {
    // check visited vertices
    final Set<MISTStream> visited = new HashSet<>();
    // from the root operators which are following sources.
    for (final MISTStream source : dag.getRootVertices()) {
        final Map<MISTStream, MISTEdge> rootEdges = dag.getEdges(source);
        visited.add(source);
        for (final MISTStream nextVertex : rootEdges.keySet()) {
            optimizeSubDag(nextVertex, visited);
        }
    }
    return dag;
}
Also used : MISTStream(edu.snu.mist.client.datastreams.MISTStream) MISTEdge(edu.snu.mist.common.graph.MISTEdge)

Example 30 with MISTEdge

use of edu.snu.mist.common.graph.MISTEdge in project mist by snuspl.

the class LogicalDagOptimizer method optimizeSubDag.

/**
 * Obtimize the operators and sinks recursively (DFS order) according to the mechanism.
 * @param currVertex  current vertex
 * @param visited visited vertices
 */
private void optimizeSubDag(final MISTStream currVertex, final Set<MISTStream> visited) {
    if (!visited.contains(currVertex)) {
        visited.add(currVertex);
        final Map<MISTStream, MISTEdge> edges = dag.getEdges(currVertex);
        // checking whether there is any conditionally branching edge diverged from current vertex
        if (!(currVertex instanceof ContinuousStreamImpl) || ((ContinuousStreamImpl) currVertex).getCondBranchCount() == 0) {
            // current vertex is not a continuous stream or this edge is an ordinary (non-branch) edge
            for (final MISTStream nextVertex : edges.keySet()) {
                optimizeSubDag(nextVertex, visited);
            }
        } else {
            // current vertex has some conditionally branching edges
            final Map<Integer, ContinuousStreamImpl> branchStreams = new HashMap<>();
            // gather the branching streams
            for (final MISTStream nextVertex : edges.keySet()) {
                if (nextVertex instanceof ContinuousStreamImpl) {
                    final ContinuousStreamImpl contNextVertex = (ContinuousStreamImpl) nextVertex;
                    if (contNextVertex.getBranchIndex() > 0) {
                        // this edge is a conditionally branching edge
                        branchStreams.put(contNextVertex.getBranchIndex(), contNextVertex);
                    }
                }
                optimizeSubDag(nextVertex, visited);
            }
            // gather condition udfs from each branch stream
            final List<String> udfs = new ArrayList<>(branchStreams.size());
            for (int i = 1; i <= branchStreams.size(); i++) {
                final ContinuousStreamImpl branchStream = branchStreams.get(i);
                final Map<String, String> conf = branchStream.getConfiguration();
                udfs.add(conf.get(ConfKeys.OperatorConf.UDF_STRING.name()));
            }
            // create a new conditional branch vertex to unify these branch streams
            final Map<String, String> opConf = new HashMap<>();
            try {
                opConf.put(ConfKeys.ConditionalBranchOperator.UDF_LIST_STRING.name(), SerializeUtils.serializeToString((Serializable) udfs));
            } catch (final IOException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
            final ContinuousStreamImpl unifiedBranchStream = new ContinuousStreamImpl(dag, opConf);
            dag.addVertex(unifiedBranchStream);
            dag.addEdge(currVertex, unifiedBranchStream, new MISTEdge(Direction.LEFT));
            // merging all the branching vertices from the current vertex into a single conditional branch vertex
            for (final ContinuousStreamImpl branchStream : branchStreams.values()) {
                final List<MISTStream> branchDownStreams = new ArrayList<>();
                for (final Map.Entry<MISTStream, MISTEdge> edgeFromBranch : dag.getEdges(branchStream).entrySet()) {
                    final MISTStream branchDownStream = edgeFromBranch.getKey();
                    branchDownStreams.add(branchDownStream);
                    dag.addEdge(unifiedBranchStream, branchDownStream, new MISTEdge(edgeFromBranch.getValue().getDirection(), branchStream.getBranchIndex()));
                }
                // to prevent the concurrent map modification, remove the edges from downStream separately
                for (final MISTStream branchDownStream : branchDownStreams) {
                    dag.removeEdge(branchStream, branchDownStream);
                }
                dag.removeEdge(currVertex, branchStream);
                dag.removeVertex(branchStream);
            }
        }
    }
}
Also used : ContinuousStreamImpl(edu.snu.mist.client.datastreams.ContinuousStreamImpl) Serializable(java.io.Serializable) IOException(java.io.IOException) MISTStream(edu.snu.mist.client.datastreams.MISTStream) MISTEdge(edu.snu.mist.common.graph.MISTEdge)

Aggregations

MISTEdge (edu.snu.mist.common.graph.MISTEdge)50 Test (org.junit.Test)23 Tuple2 (edu.snu.mist.common.types.Tuple2)12 MISTStream (edu.snu.mist.client.datastreams.MISTStream)11 Map (java.util.Map)11 DAG (edu.snu.mist.common.graph.DAG)9 Direction (edu.snu.mist.formats.avro.Direction)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 InjectionException (org.apache.reef.tang.exceptions.InjectionException)6 MISTQuery (edu.snu.mist.client.MISTQuery)5 MISTQueryBuilder (edu.snu.mist.client.MISTQueryBuilder)5 UDFTestUtils (edu.snu.mist.client.utils.UDFTestUtils)5 AdjacentListDAG (edu.snu.mist.common.graph.AdjacentListDAG)5 TimeWindowInformation (edu.snu.mist.common.windows.TimeWindowInformation)5 List (java.util.List)5 MqttMessage (org.eclipse.paho.client.mqttv3.MqttMessage)5 TestParameters (edu.snu.mist.client.utils.TestParameters)4 SerializeUtils (edu.snu.mist.common.SerializeUtils)4 ConfKeys (edu.snu.mist.common.configurations.ConfKeys)4