Search in sources :

Example 1 with VertexLocationHint

use of org.apache.tez.dag.api.VertexLocationHint in project tez by apache.

the class VertexImpl method setParallelismWrapper.

private void setParallelismWrapper(int parallelism, VertexLocationHint vertexLocationHint, Map<String, EdgeProperty> sourceEdgeProperties, Map<String, InputSpecUpdate> rootInputSpecUpdates, boolean fromVertexManager) throws AMUserCodeException {
    Preconditions.checkArgument(parallelism >= 0, "Parallelism must be >=0. Value: " + parallelism + " for vertex: " + logIdentifier);
    writeLock.lock();
    this.setParallelismCalledFlag = true;
    try {
        // disallow changing things after a vertex has started
        if (!tasksNotYetScheduled) {
            String msg = "setParallelism cannot be called after scheduling tasks. Vertex: " + getLogIdentifier();
            LOG.info(msg);
            throw new TezUncheckedException(msg);
        }
        if (fromVertexManager && canInitVertex()) {
            // vertex is fully defined. setParallelism has been called. VertexManager should have
            // informed us about this. Otherwise we would have notified listeners that we are fully
            // defined before we are actually fully defined
            Preconditions.checkState(vertexToBeReconfiguredByManager, "Vertex is fully configured but still" + " the reconfiguration API has been called. VertexManager must notify the framework using " + " context.vertexReconfigurationPlanned() before re-configuring the vertex." + " vertexId=" + logIdentifier);
        }
        // Input initializer/Vertex Manager/1-1 split expected to set parallelism.
        if (numTasks == -1) {
            if (getState() != VertexState.INITIALIZING) {
                throw new TezUncheckedException("Vertex state is not Initializing. Value: " + getState() + " for vertex: " + logIdentifier);
            }
            if (sourceEdgeProperties != null) {
                for (Map.Entry<String, EdgeProperty> entry : sourceEdgeProperties.entrySet()) {
                    LOG.info("Replacing edge manager for source:" + entry.getKey() + " destination: " + getLogIdentifier());
                    Vertex sourceVertex = appContext.getCurrentDAG().getVertex(entry.getKey());
                    Edge edge = sourceVertices.get(sourceVertex);
                    try {
                        edge.setEdgeProperty(entry.getValue());
                    } catch (Exception e) {
                        throw new TezUncheckedException("Fail to update EdgeProperty for Edge," + "sourceVertex:" + edge.getSourceVertexName() + "destinationVertex:" + edge.getDestinationVertexName(), e);
                    }
                }
            }
            if (rootInputSpecUpdates != null) {
                LOG.info("Got updated RootInputsSpecs: " + rootInputSpecUpdates.toString());
                // Sanity check for correct number of updates.
                for (Entry<String, InputSpecUpdate> rootInputSpecUpdateEntry : rootInputSpecUpdates.entrySet()) {
                    Preconditions.checkState(rootInputSpecUpdateEntry.getValue().isForAllWorkUnits() || (rootInputSpecUpdateEntry.getValue().getAllNumPhysicalInputs() != null && rootInputSpecUpdateEntry.getValue().getAllNumPhysicalInputs().size() == parallelism), "Not enough input spec updates for root input named " + rootInputSpecUpdateEntry.getKey());
                }
                this.rootInputSpecs.putAll(rootInputSpecUpdates);
            }
            int oldNumTasks = numTasks;
            this.numTasks = parallelism;
            stateChangeNotifier.stateChanged(vertexId, new VertexStateUpdateParallelismUpdated(vertexName, numTasks, oldNumTasks));
            this.createTasks();
            setVertexLocationHint(vertexLocationHint);
            LOG.info("Vertex " + getLogIdentifier() + " parallelism set to " + parallelism);
            if (canInitVertex()) {
                getEventHandler().handle(new VertexEvent(getVertexId(), VertexEventType.V_READY_TO_INIT));
            }
        } else {
            // This is an artificial restriction since there's no way of knowing whether a VertexManager
            // will attempt to update root input specs. When parallelism has not been initialized, the
            // Vertex will not be in started state so it's safe to update the specifications.
            // TODO TEZ-937 - add e mechanism to query vertex managers, or for VMs to indicate readines
            // for a vertex to start.
            Preconditions.checkState(rootInputSpecUpdates == null, "Root Input specs can only be updated when the vertex is configured with -1 tasks");
            int oldNumTasks = numTasks;
            // start buffering incoming events so that we can re-route existing events
            for (Edge edge : sourceVertices.values()) {
                edge.startEventBuffering();
            }
            if (parallelism == numTasks) {
                LOG.info("setParallelism same as current value: " + parallelism + " for vertex: " + logIdentifier);
                Preconditions.checkArgument(sourceEdgeProperties != null, "Source edge managers or RootInputSpecs must be set when not changing parallelism");
            } else {
                LOG.info("Resetting vertex location hints due to change in parallelism for vertex: " + logIdentifier);
                vertexLocationHint = null;
                if (parallelism > numTasks) {
                    addTasks((parallelism));
                } else if (parallelism < numTasks) {
                    removeTasks(parallelism);
                }
            }
            Preconditions.checkState(this.numTasks == parallelism, getLogIdentifier());
            // set new vertex location hints
            setVertexLocationHint(vertexLocationHint);
            LOG.info("Vertex " + getLogIdentifier() + " parallelism set to " + parallelism + " from " + oldNumTasks);
            // notify listeners
            stateChangeNotifier.stateChanged(vertexId, new VertexStateUpdateParallelismUpdated(vertexName, numTasks, oldNumTasks));
            assert tasks.size() == numTasks;
            // set new edge managers
            if (sourceEdgeProperties != null) {
                for (Map.Entry<String, EdgeProperty> entry : sourceEdgeProperties.entrySet()) {
                    LOG.info("Replacing edge manager for source:" + entry.getKey() + " destination: " + getLogIdentifier());
                    Vertex sourceVertex = appContext.getCurrentDAG().getVertex(entry.getKey());
                    Edge edge = sourceVertices.get(sourceVertex);
                    try {
                        edge.setEdgeProperty(entry.getValue());
                    } catch (Exception e) {
                        throw new TezUncheckedException(e);
                    }
                }
            }
            // stop buffering events
            for (Edge edge : sourceVertices.values()) {
                edge.stopEventBuffering();
            }
        }
    } finally {
        writeLock.unlock();
    }
}
Also used : VertexStateUpdateParallelismUpdated(org.apache.tez.dag.api.event.VertexStateUpdateParallelismUpdated) VertexEventRecoverVertex(org.apache.tez.dag.app.dag.event.VertexEventRecoverVertex) Vertex(org.apache.tez.dag.app.dag.Vertex) TezUncheckedException(org.apache.tez.dag.api.TezUncheckedException) InputSpecUpdate(org.apache.tez.runtime.api.InputSpecUpdate) TezUncheckedException(org.apache.tez.dag.api.TezUncheckedException) IOException(java.io.IOException) InvalidStateTransitonException(org.apache.hadoop.yarn.state.InvalidStateTransitonException) LimitExceededException(org.apache.tez.common.counters.LimitExceededException) TezException(org.apache.tez.dag.api.TezException) TaskLocationHint(org.apache.tez.dag.api.TaskLocationHint) VertexLocationHint(org.apache.tez.dag.api.VertexLocationHint) EdgeProperty(org.apache.tez.dag.api.EdgeProperty) VertexEvent(org.apache.tez.dag.app.dag.event.VertexEvent) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 2 with VertexLocationHint

use of org.apache.tez.dag.api.VertexLocationHint in project tez by apache.

the class TestHistoryEventsProtoConversion method testVertexReconfigureDoneEvent.

private void testVertexReconfigureDoneEvent() throws Exception {
    VertexLocationHint vertexLocationHint = VertexLocationHint.create(new ArrayList<TaskLocationHint>());
    InputSpecUpdate rootInputSpecUpdateBulk = InputSpecUpdate.createAllTaskInputSpecUpdate(2);
    InputSpecUpdate rootInputSpecUpdatePerTask = InputSpecUpdate.createPerTaskInputSpecUpdate(Lists.newArrayList(1, 2, 3));
    Map<String, InputSpecUpdate> rootInputSpecUpdates = new HashMap<String, InputSpecUpdate>();
    rootInputSpecUpdates.put("input1", rootInputSpecUpdateBulk);
    rootInputSpecUpdates.put("input2", rootInputSpecUpdatePerTask);
    Map<String, EdgeProperty> sourceEdgeManagers = new HashMap<String, EdgeProperty>();
    // add standard and custom edge
    sourceEdgeManagers.put("foo", EdgeProperty.create(DataMovementType.SCATTER_GATHER, DataSourceType.PERSISTED, SchedulingType.SEQUENTIAL, OutputDescriptor.create("Out1"), InputDescriptor.create("in1")));
    sourceEdgeManagers.put("foo1", EdgeProperty.create(EdgeManagerPluginDescriptor.create("bar1").setUserPayload(UserPayload.create(ByteBuffer.wrap(new String("payload").getBytes()), 100)), DataSourceType.PERSISTED, SchedulingType.SEQUENTIAL, OutputDescriptor.create("Out1"), InputDescriptor.create("in1")));
    final long reconfigureDoneTime = 100;
    final int numTasks = 2;
    VertexConfigurationDoneEvent event = new VertexConfigurationDoneEvent(TezVertexID.getInstance(TezDAGID.getInstance(ApplicationId.newInstance(0, 1), 1), 111), reconfigureDoneTime, numTasks, vertexLocationHint, sourceEdgeManagers, rootInputSpecUpdates, true);
    Assert.assertEquals(numTasks, event.getNumTasks());
    Assert.assertEquals(reconfigureDoneTime, event.getReconfigureDoneTime());
    VertexConfigurationDoneEvent deserializedEvent = (VertexConfigurationDoneEvent) testProtoConversion(event);
    Assert.assertEquals(event.getVertexID(), deserializedEvent.getVertexID());
    Assert.assertEquals(event.getNumTasks(), deserializedEvent.getNumTasks());
    Assert.assertEquals(event.isSetParallelismCalled(), deserializedEvent.isSetParallelismCalled());
    // vertexLocationHint
    Assert.assertEquals(event.getVertexLocationHint(), deserializedEvent.getVertexLocationHint());
    // rootInputSpec
    Assert.assertEquals(event.getRootInputSpecUpdates().size(), deserializedEvent.getRootInputSpecUpdates().size());
    InputSpecUpdate deserializedBulk = deserializedEvent.getRootInputSpecUpdates().get("input1");
    InputSpecUpdate deserializedPerTask = deserializedEvent.getRootInputSpecUpdates().get("input2");
    Assert.assertEquals(rootInputSpecUpdateBulk.isForAllWorkUnits(), deserializedBulk.isForAllWorkUnits());
    Assert.assertEquals(rootInputSpecUpdateBulk.getAllNumPhysicalInputs(), deserializedBulk.getAllNumPhysicalInputs());
    Assert.assertEquals(rootInputSpecUpdatePerTask.isForAllWorkUnits(), deserializedPerTask.isForAllWorkUnits());
    Assert.assertEquals(rootInputSpecUpdatePerTask.getAllNumPhysicalInputs(), deserializedPerTask.getAllNumPhysicalInputs());
    // sourceEdgeManager
    Assert.assertEquals(event.getSourceEdgeProperties().size(), deserializedEvent.getSourceEdgeProperties().size());
    Assert.assertEquals(event.getSourceEdgeProperties().get("foo").getDataMovementType(), deserializedEvent.getSourceEdgeProperties().get("foo").getDataMovementType());
    Assert.assertNull(deserializedEvent.getSourceEdgeProperties().get("foo").getEdgeManagerDescriptor());
    Assert.assertEquals(event.getSourceEdgeProperties().get("foo1").getDataMovementType(), deserializedEvent.getSourceEdgeProperties().get("foo1").getDataMovementType());
    Assert.assertEquals(event.getSourceEdgeProperties().get("foo1").getEdgeManagerDescriptor().getUserPayload().getVersion(), deserializedEvent.getSourceEdgeProperties().get("foo1").getEdgeManagerDescriptor().getUserPayload().getVersion());
    Assert.assertArrayEquals(event.getSourceEdgeProperties().get("foo1").getEdgeManagerDescriptor().getUserPayload().deepCopyAsArray(), deserializedEvent.getSourceEdgeProperties().get("foo1").getEdgeManagerDescriptor().getUserPayload().deepCopyAsArray());
    logEvents(event, deserializedEvent);
}
Also used : TaskLocationHint(org.apache.tez.dag.api.TaskLocationHint) HashMap(java.util.HashMap) InputSpecUpdate(org.apache.tez.runtime.api.InputSpecUpdate) EdgeProperty(org.apache.tez.dag.api.EdgeProperty) TaskLocationHint(org.apache.tez.dag.api.TaskLocationHint) VertexLocationHint(org.apache.tez.dag.api.VertexLocationHint) VertexLocationHint(org.apache.tez.dag.api.VertexLocationHint)

Example 3 with VertexLocationHint

use of org.apache.tez.dag.api.VertexLocationHint in project tez by apache.

the class TestVertexImpl method setupVertices.

private void setupVertices() {
    int vCnt = dagPlan.getVertexCount();
    LOG.info("Setting up vertices from dag plan, verticesCnt=" + vCnt);
    vertices = new HashMap<String, VertexImpl>();
    vertexIdMap = new HashMap<TezVertexID, VertexImpl>();
    Configuration dagConf = new Configuration(false);
    dagConf.set("abc", "foobar");
    for (int i = 0; i < vCnt; ++i) {
        VertexPlan vPlan = dagPlan.getVertex(i);
        String vName = vPlan.getName();
        TezVertexID vertexId = TezVertexID.getInstance(dagId, i + 1);
        VertexImpl v = null;
        VertexLocationHint locationHint = DagTypeConverters.convertFromDAGPlan(vPlan.getTaskLocationHintList());
        if (useCustomInitializer) {
            if (customInitializer == null) {
                v = new VertexImplWithControlledInitializerManager(vertexId, vPlan, vPlan.getName(), conf, dispatcher.getEventHandler(), taskCommunicatorManagerInterface, clock, thh, appContext, locationHint, dispatcher, updateTracker, dagConf);
            } else {
                v = new VertexImplWithRunningInputInitializer(vertexId, vPlan, vPlan.getName(), conf, dispatcher.getEventHandler(), taskCommunicatorManagerInterface, clock, thh, appContext, locationHint, dispatcher, customInitializer, updateTracker, dagConf);
            }
        } else {
            v = new VertexImpl(vertexId, vPlan, vPlan.getName(), conf, dispatcher.getEventHandler(), taskCommunicatorManagerInterface, clock, thh, true, appContext, locationHint, vertexGroups, taskSpecificLaunchCmdOption, updateTracker, dagConf);
        }
        vertices.put(vName, v);
        vertexIdMap.put(vertexId, v);
    }
}
Also used : VertexPlan(org.apache.tez.dag.api.records.DAGProtos.VertexPlan) PlanTaskConfiguration(org.apache.tez.dag.api.records.DAGProtos.PlanTaskConfiguration) Configuration(org.apache.hadoop.conf.Configuration) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) ByteString(com.google.protobuf.ByteString) TaskLocationHint(org.apache.tez.dag.api.TaskLocationHint) VertexLocationHint(org.apache.tez.dag.api.VertexLocationHint) PlanTaskLocationHint(org.apache.tez.dag.api.records.DAGProtos.PlanTaskLocationHint) TezVertexID(org.apache.tez.dag.records.TezVertexID) VertexLocationHint(org.apache.tez.dag.api.VertexLocationHint)

Example 4 with VertexLocationHint

use of org.apache.tez.dag.api.VertexLocationHint in project tez by apache.

the class VertexImpl method logLocationHints.

private static void logLocationHints(String vertexName, VertexLocationHint locationHint) {
    if (locationHint == null) {
        LOG.debug("No Vertex LocationHint specified for vertex=" + vertexName);
        return;
    }
    Multiset<String> hosts = HashMultiset.create();
    Multiset<String> racks = HashMultiset.create();
    int counter = 0;
    for (TaskLocationHint taskLocationHint : locationHint.getTaskLocationHints()) {
        StringBuilder sb = new StringBuilder();
        if (taskLocationHint.getHosts() == null) {
            sb.append("No Hosts");
        } else {
            sb.append("Hosts: ");
            for (String host : taskLocationHint.getHosts()) {
                hosts.add(host);
                sb.append(host).append(", ");
            }
        }
        if (taskLocationHint.getRacks() == null) {
            sb.append("No Racks");
        } else {
            sb.append("Racks: ");
            for (String rack : taskLocationHint.getRacks()) {
                racks.add(rack);
                sb.append(rack).append(", ");
            }
        }
        LOG.debug("Vertex: " + vertexName + ", Location: " + counter + " : " + sb.toString());
        counter++;
    }
    LOG.debug("Vertex: " + vertexName + ", Host Counts");
    for (Multiset.Entry<String> host : hosts.entrySet()) {
        LOG.debug("Vertex: " + vertexName + ", host: " + host.toString());
    }
    LOG.debug("Vertex: " + vertexName + ", Rack Counts");
    for (Multiset.Entry<String> rack : racks.entrySet()) {
        LOG.debug("Vertex: " + vertexName + ", rack: " + rack.toString());
    }
}
Also used : TaskLocationHint(org.apache.tez.dag.api.TaskLocationHint) HashMultiset(com.google.common.collect.HashMultiset) Multiset(com.google.common.collect.Multiset) TaskLocationHint(org.apache.tez.dag.api.TaskLocationHint) VertexLocationHint(org.apache.tez.dag.api.VertexLocationHint)

Example 5 with VertexLocationHint

use of org.apache.tez.dag.api.VertexLocationHint in project tez by apache.

the class DAGImpl method createVertex.

private static VertexImpl createVertex(DAGImpl dag, String vertexName, int vId) {
    TezVertexID vertexId = TezBuilderUtils.newVertexID(dag.getID(), vId);
    VertexPlan vertexPlan = dag.getJobPlan().getVertex(vId);
    VertexLocationHint vertexLocationHint = DagTypeConverters.convertFromDAGPlan(vertexPlan.getTaskLocationHintList());
    VertexImpl v = new VertexImpl(vertexId, vertexPlan, vertexName, dag.dagConf, dag.eventHandler, dag.taskCommunicatorManagerInterface, dag.clock, dag.taskHeartbeatHandler, !dag.commitAllOutputsOnSuccess, dag.appContext, vertexLocationHint, dag.vertexGroups, dag.taskSpecificLaunchCmdOption, dag.entityUpdateTracker, dag.dagOnlyConf);
    return v;
}
Also used : VertexPlan(org.apache.tez.dag.api.records.DAGProtos.VertexPlan) TezVertexID(org.apache.tez.dag.records.TezVertexID) VertexLocationHint(org.apache.tez.dag.api.VertexLocationHint)

Aggregations

VertexLocationHint (org.apache.tez.dag.api.VertexLocationHint)5 TaskLocationHint (org.apache.tez.dag.api.TaskLocationHint)4 HashMap (java.util.HashMap)2 EdgeProperty (org.apache.tez.dag.api.EdgeProperty)2 VertexPlan (org.apache.tez.dag.api.records.DAGProtos.VertexPlan)2 TezVertexID (org.apache.tez.dag.records.TezVertexID)2 InputSpecUpdate (org.apache.tez.runtime.api.InputSpecUpdate)2 HashMultiset (com.google.common.collect.HashMultiset)1 Multiset (com.google.common.collect.Multiset)1 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Configuration (org.apache.hadoop.conf.Configuration)1 InvalidStateTransitonException (org.apache.hadoop.yarn.state.InvalidStateTransitonException)1 LimitExceededException (org.apache.tez.common.counters.LimitExceededException)1 TezConfiguration (org.apache.tez.dag.api.TezConfiguration)1 TezException (org.apache.tez.dag.api.TezException)1 TezUncheckedException (org.apache.tez.dag.api.TezUncheckedException)1