Search in sources :

Example 1 with TaskState

use of org.apache.tez.dag.api.oldrecords.TaskState in project tez by apache.

the class TaskImpl method canCommit.

@Override
public boolean canCommit(TezTaskAttemptID taskAttemptID) {
    writeLock.lock();
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Commit go/no-go request from " + taskAttemptID);
        }
        TaskState state = getState();
        if (state == TaskState.SCHEDULED) {
            // the actual running task ran and is done and asking for commit. we are still stuck
            // in the scheduled state which indicates a backlog in event processing. lets wait for the
            // backlog to clear. returning false will make the attempt come back to us.
            LOG.info("Event processing delay. " + "Attempt committing before state machine transitioned to running : Task {}", taskId);
            return false;
        }
        // have been in scheduled state in task impl.
        if (state != TaskState.RUNNING) {
            LOG.info("Task not running. Issuing kill to bad commit attempt " + taskAttemptID);
            eventHandler.handle(new TaskAttemptEventKillRequest(taskAttemptID, "Task not running. Bad attempt.", TaskAttemptTerminationCause.TERMINATED_ORPHANED));
            return false;
        }
        if (commitAttempt == null) {
            TaskAttempt ta = getAttempt(taskAttemptID);
            if (ta == null) {
                throw new TezUncheckedException("Unknown task for commit: " + taskAttemptID);
            }
            // Its ok to get a non-locked state snapshot since we handle changes of
            // state in the task attempt. Dont want to deadlock here.
            TaskAttemptState taState = ta.getStateNoLock();
            if (taState == TaskAttemptState.RUNNING) {
                commitAttempt = taskAttemptID;
                LOG.info(taskAttemptID + " given a go for committing the task output.");
                return true;
            } else {
                LOG.info(taskAttemptID + " with state: " + taState + " given a no-go for commit because its not running.");
                return false;
            }
        } else {
            if (commitAttempt.equals(taskAttemptID)) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug(taskAttemptID + " already given a go for committing the task output.");
                }
                return true;
            }
            // succeeds then this and others will be killed
            if (LOG.isDebugEnabled()) {
                LOG.debug(commitAttempt + " is current committer. Commit waiting for:  " + taskAttemptID);
            }
            return false;
        }
    } finally {
        writeLock.unlock();
    }
}
Also used : TezUncheckedException(org.apache.tez.dag.api.TezUncheckedException) TaskAttemptState(org.apache.tez.dag.api.oldrecords.TaskAttemptState) TaskAttempt(org.apache.tez.dag.app.dag.TaskAttempt) TaskState(org.apache.tez.dag.api.oldrecords.TaskState) TaskAttemptEventKillRequest(org.apache.tez.dag.app.dag.event.TaskAttemptEventKillRequest)

Example 2 with TaskState

use of org.apache.tez.dag.api.oldrecords.TaskState in project tez by apache.

the class TestHistoryEventTimelineConversion method testConvertTaskFinishedEvent.

@Test(timeout = 5000)
public void testConvertTaskFinishedEvent() {
    String vertexName = "testVertexName";
    long startTime = random.nextLong();
    long finishTime = random.nextLong();
    TaskState state = TaskState.values()[random.nextInt(TaskState.values().length)];
    String diagnostics = "diagnostics message";
    TezCounters counters = new TezCounters();
    TaskFinishedEvent event = new TaskFinishedEvent(tezTaskID, vertexName, startTime, finishTime, tezTaskAttemptID, state, diagnostics, counters, 3);
    List<TimelineEntity> entities = HistoryEventTimelineConversion.convertToTimelineEntities(event);
    Assert.assertEquals(1, entities.size());
    TimelineEntity timelineEntity = entities.get(0);
    Assert.assertEquals(tezTaskID.toString(), timelineEntity.getEntityId());
    Assert.assertEquals(EntityTypes.TEZ_TASK_ID.name(), timelineEntity.getEntityType());
    final Map<String, Set<Object>> primaryFilters = timelineEntity.getPrimaryFilters();
    Assert.assertEquals(4, primaryFilters.size());
    Assert.assertTrue(primaryFilters.get(ATSConstants.APPLICATION_ID).contains(applicationId.toString()));
    Assert.assertTrue(primaryFilters.get(EntityTypes.TEZ_DAG_ID.name()).contains(tezDAGID.toString()));
    Assert.assertTrue(primaryFilters.get(EntityTypes.TEZ_VERTEX_ID.name()).contains(tezVertexID.toString()));
    Assert.assertTrue(primaryFilters.get(ATSConstants.STATUS).contains(state.name()));
    Assert.assertEquals(1, timelineEntity.getEvents().size());
    TimelineEvent evt = timelineEntity.getEvents().get(0);
    Assert.assertEquals(HistoryEventType.TASK_FINISHED.name(), evt.getEventType());
    Assert.assertEquals(finishTime, evt.getTimestamp());
    final Map<String, Object> otherInfo = timelineEntity.getOtherInfo();
    Assert.assertEquals(7, otherInfo.size());
    Assert.assertEquals(finishTime, otherInfo.get(ATSConstants.FINISH_TIME));
    Assert.assertEquals(finishTime - startTime, otherInfo.get(ATSConstants.TIME_TAKEN));
    Assert.assertEquals(state.name(), otherInfo.get(ATSConstants.STATUS));
    Assert.assertEquals(tezTaskAttemptID.toString(), otherInfo.get(ATSConstants.SUCCESSFUL_ATTEMPT_ID));
    Assert.assertEquals(3, otherInfo.get(ATSConstants.NUM_FAILED_TASKS_ATTEMPTS));
    Assert.assertEquals(diagnostics, otherInfo.get(ATSConstants.DIAGNOSTICS));
    Assert.assertTrue(otherInfo.containsKey(ATSConstants.COUNTERS));
}
Also used : TimelineEvent(org.apache.hadoop.yarn.api.records.timeline.TimelineEvent) TaskFinishedEvent(org.apache.tez.dag.history.events.TaskFinishedEvent) Set(java.util.Set) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) TaskState(org.apache.tez.dag.api.oldrecords.TaskState) TezCounters(org.apache.tez.common.counters.TezCounters) Test(org.junit.Test)

Aggregations

TaskState (org.apache.tez.dag.api.oldrecords.TaskState)2 Set (java.util.Set)1 TimelineEntity (org.apache.hadoop.yarn.api.records.timeline.TimelineEntity)1 TimelineEvent (org.apache.hadoop.yarn.api.records.timeline.TimelineEvent)1 TezCounters (org.apache.tez.common.counters.TezCounters)1 TezUncheckedException (org.apache.tez.dag.api.TezUncheckedException)1 TaskAttemptState (org.apache.tez.dag.api.oldrecords.TaskAttemptState)1 TaskAttempt (org.apache.tez.dag.app.dag.TaskAttempt)1 TaskAttemptEventKillRequest (org.apache.tez.dag.app.dag.event.TaskAttemptEventKillRequest)1 TaskFinishedEvent (org.apache.tez.dag.history.events.TaskFinishedEvent)1 Test (org.junit.Test)1