向ApplicationMasterService注册AppAttempt

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhusirong/article/details/83622821

向ApplicationMasterService注册AppAttempt

    1.实例化应答类AllocateResponse,将ResponseId初始化-1.
    2.在ApplicationMasterService服务中根据attemptId占个坑,后面ApplicationMaster通过allocate发送心跳时,会检查其对应的attempt是否注册过.

代码清单:

public void ApplicationMasterService.registerAppAttempt(ApplicationAttemptId attemptId) {
    AllocateResponse response =
        recordFactory.newRecordInstance(AllocateResponse.class);
    // set response id to -1 before application master for the following
    // attemptID get registered
    response.setResponseId(-1);
    LOG.info("Registering app attempt : " + attemptId);
    responseMap.put(attemptId, new AllocateResponseLock(response));
    rmContext.getNMTokenSecretManager().registerApplicationAttempt(attemptId);
  }

在客户端提交一个应用的时候,ApplicationMasterService.registerAppAttempt()
会在response中设置responseId为-1.
ApplicationMaster进程开始运行,通过registerApplicationMaster()会在response中设置id为0,即增1,每次请求,ApplicationMaster自己都会携带上一次收到的响应的responseId,同时,ApplicaitonMaster会保留上一次的response对象,通过对比此次请求的序号和上一次的response的序号以校验合法性:

  • 如果请求中的sequenceId与上次请求id一致,则说明这次是一个新的、有序请求,合法
  • 如果请求中的sequenceId+1等于上次请求的sequence id,说明这次请求试一次重复请求,这时候直接将上一次的response再返回一次.
  • 如果请求中的sequenceId+1小于上次请求的sequence id,说明这是一次非常陈旧的请求,直接抛出异常.

猜你喜欢

转载自blog.csdn.net/zhusirong/article/details/83622821