Search in sources :

Example 11 with ScheduleTaskRequest

use of org.apache.tez.dag.api.VertexManagerPluginContext.ScheduleTaskRequest in project tez by apache.

the class VertexImpl method scheduleTasks.

@Override
public void scheduleTasks(List<ScheduleTaskRequest> tasksToSchedule) {
    try {
        unsetTasksNotYetScheduled();
        // update state under write lock
        writeLock.lock();
        try {
            for (ScheduleTaskRequest task : tasksToSchedule) {
                if (numTasks <= task.getTaskIndex()) {
                    throw new TezUncheckedException("Invalid taskId: " + task.getTaskIndex() + " for vertex: " + logIdentifier);
                }
                TaskLocationHint locationHint = task.getTaskLocationHint();
                if (locationHint != null) {
                    if (taskLocationHints == null) {
                        taskLocationHints = new TaskLocationHint[numTasks];
                    }
                    taskLocationHints[task.getTaskIndex()] = locationHint;
                }
            }
        } finally {
            writeLock.unlock();
        }
        /**
         * read lock is not needed here. For e.g after starting task
         * scheduling on the vertex, it would not change numTasks. Rest of
         * the methods creating remote task specs have their
         * own locking mechanisms. Ref: TEZ-3297
         */
        for (ScheduleTaskRequest task : tasksToSchedule) {
            TezTaskID taskId = TezTaskID.getInstance(vertexId, task.getTaskIndex());
            TaskSpec baseTaskSpec = createRemoteTaskSpec(taskId.getId());
            boolean fromRecovery = recoveryData == null ? false : recoveryData.getTaskRecoveryData(taskId) != null;
            eventHandler.handle(new TaskEventScheduleTask(taskId, baseTaskSpec, getTaskLocationHint(taskId), fromRecovery));
        }
    } catch (AMUserCodeException e) {
        String msg = "Exception in " + e.getSource() + ", vertex=" + getLogIdentifier();
        LOG.error(msg, e);
        // send event to fail the vertex
        eventHandler.handle(new VertexEventManagerUserCodeError(getVertexId(), e));
        // throw an unchecked exception to stop the vertex manager that invoked this.
        throw new TezUncheckedException(e);
    }
}
Also used : TaskLocationHint(org.apache.tez.dag.api.TaskLocationHint) TezUncheckedException(org.apache.tez.dag.api.TezUncheckedException) VertexEventManagerUserCodeError(org.apache.tez.dag.app.dag.event.VertexEventManagerUserCodeError) TaskSpec(org.apache.tez.runtime.api.impl.TaskSpec) TaskEventScheduleTask(org.apache.tez.dag.app.dag.event.TaskEventScheduleTask) ScheduleTaskRequest(org.apache.tez.dag.api.VertexManagerPluginContext.ScheduleTaskRequest) TezTaskID(org.apache.tez.dag.records.TezTaskID)

Example 12 with ScheduleTaskRequest

use of org.apache.tez.dag.api.VertexManagerPluginContext.ScheduleTaskRequest in project tez by apache.

the class TestCartesianProductVertexManagerPartitioned method testOnVertexStartHelper.

private void testOnVertexStartHelper(boolean broadcastRunning) throws Exception {
    vertexManager.onVertexStateUpdated(new VertexStateUpdate("v0", VertexState.CONFIGURED));
    vertexManager.onVertexStateUpdated(new VertexStateUpdate("v1", VertexState.CONFIGURED));
    if (broadcastRunning) {
        vertexManager.onVertexStateUpdated(new VertexStateUpdate("v2", VertexState.RUNNING));
    }
    List<TaskAttemptIdentifier> completions = new ArrayList<>();
    completions.add(allCompletions.get(0));
    completions.add(allCompletions.get(1));
    completions.add(allCompletions.get(4));
    completions.add(allCompletions.get(8));
    vertexManager.onVertexStarted(completions);
    if (!broadcastRunning) {
        verify(context, never()).scheduleTasks(Matchers.<List<ScheduleTaskRequest>>any());
        vertexManager.onVertexStateUpdated(new VertexStateUpdate("v2", VertexState.RUNNING));
    }
    List<ScheduleTaskRequest> scheduleTaskRequests;
    verify(context, times(1)).scheduleTasks(scheduleTaskRequestCaptor.capture());
    scheduleTaskRequests = scheduleTaskRequestCaptor.getValue();
    assertEquals(1, scheduleTaskRequests.size());
    assertEquals(0, scheduleTaskRequests.get(0).getTaskIndex());
}
Also used : VertexStateUpdate(org.apache.tez.dag.api.event.VertexStateUpdate) ArrayList(java.util.ArrayList) TaskAttemptIdentifier(org.apache.tez.runtime.api.TaskAttemptIdentifier) ScheduleTaskRequest(org.apache.tez.dag.api.VertexManagerPluginContext.ScheduleTaskRequest)

Example 13 with ScheduleTaskRequest

use of org.apache.tez.dag.api.VertexManagerPluginContext.ScheduleTaskRequest in project tez by apache.

the class TestFairCartesianProductVertexManager method verifyScheduleRequest.

private void verifyScheduleRequest(int expectedTimes, int... expectedTid) {
    verify(ctx, times(expectedTimes)).scheduleTasks(scheduleRequestCaptor.capture());
    if (expectedTimes > 0) {
        List<ScheduleTaskRequest> requests = scheduleRequestCaptor.getValue();
        int i = 0;
        for (int tid : expectedTid) {
            assertEquals(tid, requests.get(i).getTaskIndex());
            i++;
        }
    }
}
Also used : ScheduleTaskRequest(org.apache.tez.dag.api.VertexManagerPluginContext.ScheduleTaskRequest) VertexLocationHint(org.apache.tez.dag.api.VertexLocationHint)

Aggregations

ScheduleTaskRequest (org.apache.tez.dag.api.VertexManagerPluginContext.ScheduleTaskRequest)13 TaskLocationHint (org.apache.tez.dag.api.TaskLocationHint)6 VertexLocationHint (org.apache.tez.dag.api.VertexLocationHint)6 Test (org.junit.Test)6 VertexManagerPluginContext (org.apache.tez.dag.api.VertexManagerPluginContext)5 LinkedList (java.util.LinkedList)4 PlanTaskLocationHint (org.apache.tez.dag.api.records.DAGProtos.PlanTaskLocationHint)4 StateChangeNotifierForTest (org.apache.tez.dag.app.dag.TestStateChangeNotifier.StateChangeNotifierForTest)4 VertexEventRouteEvent (org.apache.tez.dag.app.dag.event.VertexEventRouteEvent)4 TezTaskAttemptID (org.apache.tez.dag.records.TezTaskAttemptID)4 EventMetaData (org.apache.tez.runtime.api.impl.EventMetaData)4 TezEvent (org.apache.tez.runtime.api.impl.TezEvent)4 EdgeManagerForTest (org.apache.tez.test.EdgeManagerForTest)4 GraceShuffleVertexManagerForTest (org.apache.tez.test.GraceShuffleVertexManagerForTest)4 VertexManagerPluginForTest (org.apache.tez.test.VertexManagerPluginForTest)4 EdgeManagerPluginOnDemand (org.apache.tez.dag.api.EdgeManagerPluginOnDemand)3 EventRouteMetadata (org.apache.tez.dag.api.EdgeManagerPluginOnDemand.EventRouteMetadata)3 VertexStateUpdate (org.apache.tez.dag.api.event.VertexStateUpdate)3 TaskAttemptEventInfo (org.apache.tez.dag.app.TaskAttemptEventInfo)3 BigInteger (java.math.BigInteger)2