MultipleArcTransition<VertexImpl, VertexEvent, VertexState> {
@Override
public VertexState transition(VertexImpl vertex, VertexEvent vertexEvent) {
VertexEventRecoverVertex recoverEvent = (VertexEventRecoverVertex) vertexEvent;
VertexState desiredState = recoverEvent.getDesiredState();
switch (desiredState) {
case RUNNING:
break;
case SUCCEEDED:
case KILLED:
case FAILED:
case ERROR:
switch (desiredState) {
case SUCCEEDED:
vertex.succeededTaskCount = vertex.numTasks;
vertex.completedTaskCount = vertex.numTasks;
break;
case KILLED:
vertex.killedTaskCount = vertex.numTasks;
break;
case FAILED:
case ERROR:
vertex.failedTaskCount = vertex.numTasks;
break;
}
if (vertex.tasks != null) {
TaskState taskState = TaskState.KILLED;
switch (desiredState) {
case SUCCEEDED:
taskState = TaskState.SUCCEEDED;
break;
case KILLED:
taskState = TaskState.KILLED;
break;
case FAILED:
case ERROR:
taskState = TaskState.FAILED;
break;
}
for (Task task : vertex.tasks.values()) {
vertex.eventHandler.handle(
new TaskEventRecoverTask(task.getTaskId(),
taskState));
}
}
LOG.info("DAG informed Vertex of its final completed state"
+ ", vertex=" + vertex.logIdentifier
+ ", state=" + desiredState);
return desiredState;
default:
LOG.info("Unhandled desired state provided by DAG"
+ ", vertex=" + vertex.logIdentifier
+ ", state=" + desiredState);
vertex.finished(VertexState.ERROR);
}
VertexState endState;
switch (vertex.recoveredState) {
case NEW:
// Trigger init and start as desired state is RUNNING
// Drop all root events
Iterator<TezEvent> iterator = vertex.recoveredEvents.iterator();
while (iterator.hasNext()) {
if (iterator.next().getEventType().equals(
EventType.ROOT_INPUT_DATA_INFORMATION_EVENT)) {
iterator.remove();
}
}
vertex.eventHandler.handle(new VertexEvent(vertex.vertexId,
VertexEventType.V_INIT));
vertex.eventHandler.handle(new VertexEvent(vertex.vertexId,
VertexEventType.V_START));
endState = VertexState.NEW;
break;
case INITED:
try {
vertex.initializeCommitters();
} catch (Exception e) {
LOG.info("Failed to initialize committers", e);
vertex.finished(VertexState.FAILED,
VertexTerminationCause.INIT_FAILURE);
endState = VertexState.FAILED;
break;
}
// Recover tasks
if (vertex.tasks != null) {
for (Task task : vertex.tasks.values()) {
vertex.eventHandler.handle(
new TaskEventRecoverTask(task.getTaskId()));
}
}
// Update tasks with their input payloads as needed
vertex.eventHandler.handle(new VertexEvent(vertex.vertexId,
VertexEventType.V_START));
if (vertex.getInputVertices().isEmpty()) {
endState = VertexState.INITED;
} else {
endState = VertexState.RECOVERING;
}
break;
case RUNNING:
vertex.tasksNotYetScheduled = false;
try {
vertex.initializeCommitters();
} catch (Exception e) {
LOG.info("Failed to initialize committers", e);
vertex.finished(VertexState.FAILED,
VertexTerminationCause.INIT_FAILURE);
endState = VertexState.FAILED;
break;
}
// if commit in progress and desired state is not a succeeded one,
// move to failed
if (vertex.recoveryCommitInProgress) {
LOG.info("Recovered vertex was in the middle of a commit"
+ ", failing Vertex=" + vertex.logIdentifier);
vertex.finished(VertexState.FAILED,
VertexTerminationCause.COMMIT_FAILURE);
endState = VertexState.FAILED;
break;
}
assert vertex.tasks.size() == vertex.numTasks;
if (vertex.tasks != null && vertex.numTasks != 0) {
for (Task task : vertex.tasks.values()) {
vertex.eventHandler.handle(
new TaskEventRecoverTask(task.getTaskId()));
}
vertex.vertexManager.onVertexStarted(vertex.pendingReportedSrcCompletions);
endState = VertexState.RUNNING;
} else {
endState = VertexState.SUCCEEDED;
vertex.finished(endState);
}
break;
case SUCCEEDED:
case FAILED:
case KILLED:
if (vertex.recoveredState == VertexState.SUCCEEDED
&& vertex.hasCommitter
&& vertex.summaryCompleteSeen && !vertex.vertexCompleteSeen) {
LOG.warn("Cannot recover vertex as all recovery events not"
+ " found, vertex=" + vertex.logIdentifier
+ ", hasCommitters=" + vertex.hasCommitter
+ ", summaryCompletionSeen=" + vertex.summaryCompleteSeen
+ ", finalCompletionSeen=" + vertex.vertexCompleteSeen);
vertex.finished(VertexState.FAILED,
VertexTerminationCause.COMMIT_FAILURE);
endState = VertexState.FAILED;
} else {
vertex.tasksNotYetScheduled = false;
// recover tasks
if (vertex.tasks != null && vertex.numTasks != 0) {
TaskState taskState = TaskState.KILLED;
switch (vertex.recoveredState) {
case SUCCEEDED:
taskState = TaskState.SUCCEEDED;
break;
case KILLED:
taskState = TaskState.KILLED;
break;
case FAILED:
taskState = TaskState.FAILED;
break;
}
for (Task task : vertex.tasks.values()) {
vertex.eventHandler.handle(
new TaskEventRecoverTask(task.getTaskId(),
taskState));
}
vertex.vertexManager.onVertexStarted(vertex.pendingReportedSrcCompletions);
endState = VertexState.RUNNING;
} else {
endState = vertex.recoveredState;
vertex.finished(endState);
}
}
break;
default:
LOG.warn("Invalid recoveredState found when trying to recover"
+ " vertex, recoveredState=" + vertex.recoveredState);
vertex.finished(VertexState.ERROR);
endState = VertexState.ERROR;
break;
}
if (!endState.equals(VertexState.RECOVERING)) {
LOG.info("Recovered Vertex State"
+ ", vertexId=" + vertex.logIdentifier
+ ", state=" + endState
+ ", numInitedSourceVertices=" + vertex.numInitedSourceVertices
+ ", numStartedSourceVertices=" + vertex.numStartedSourceVertices