版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhusirong/article/details/83785912
StoreAppAttemptTransition(基于hadoop 2.7.6)
1.将AppAttempt状态存储到共享存储系统
2.触发RMAppAttemptEventType.ATTEMPT_NEW_SAVED
经过StoreAppAttemptTransition转换处理器后,正常情况RMStateStoreState保持ACTIVE状态不变;发生异常情况下,转换为FENCED状态.在HA模式下ResourceManager切换为standBy,不在HA模式下则快速失败.
代码清单:
private static class RMStateStore.StoreAppAttemptTransition implements
MultipleArcTransition<RMStateStore, RMStateStoreEvent,
RMStateStoreState> {
@Override
public RMStateStoreState transition(RMStateStore store,
RMStateStoreEvent event) {
if (!(event instanceof RMStateStoreAppAttemptEvent)) {
// should never happen
LOG.error("Illegal event type: " + event.getClass());
return RMStateStoreState.ACTIVE;
}
boolean isFenced = false;
ApplicationAttemptStateData attemptState =
((RMStateStoreAppAttemptEvent) event).getAppAttemptState();
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Storing info for attempt: " + attemptState.getAttemptId());
}
/**
* 将Application和AttemptState存储到共享存储系统(一般为ZKRMStateStore)
* 目录结构:
* ROOT_DIR_PATH
* |--- RM_APP_ROOT
* | |----- (#ApplicationId1)
* | | |----- (#ApplicationAttemptIds)
* | |
* | |----- (#ApplicationId2)
* | | |----- (#ApplicationAttemptIds)
*/
store.storeApplicationAttemptStateInternal(attemptState.getAttemptId(),
attemptState);
/**
* 触发RMAppAttemptEventType.ATTEMPT_NEW_SAVED
*/
store.notifyApplicationAttempt(new RMAppAttemptEvent
(attemptState.getAttemptId(),
RMAppAttemptEventType.ATTEMPT_NEW_SAVED));
} catch (Exception e) {
LOG.error("Error storing appAttempt: " + attemptState.getAttemptId(), e);
/**
* 出现异常情况的时候,在HA的情况下转为StandBy或在没有HA的情况下快速失败
*/
isFenced = store.notifyStoreOperationFailedInternal(e);
}
return finalState(isFenced);
};
}