StartAppAttemptTransition(详见6)

本文详细介绍了在Hadoop 2.7.6版本中,StartAppAttemptTransition如何处理APP_ACCEPTED事件,使得RMApp状态从SUBMITTED转变为ACCEPTED。内容包括创建RMAppAttempt,并触发RMAppStartAttemptEvent,进一步解析事件处理器RMAppAttemptImpl的角色。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

StartAppAttemptTransition(基于hadoop 2.7.6)

StartAppAttemptTransition是对RMAppEventType.APP_ACCEPTED事件的转换处理,转换处理后RMApp状态由SUBMITTED变为ACCEPTED.

主要逻辑:
1.创建RMAppAttempt,RMAppImpl会维护一个
<ApplicationAttemptId, RMAppAttempt>的映射表
2.触发RMAppStartAttemptEvent (RMAppAttemptEventType.START)事件,该事件的处理器是AttemptStartedTransition.

private static final class StartAppAttemptTransition extends RMAppTransition {
    @Override
    public void transition(RMAppImpl app, RMAppEvent event) {
      app.createAndStartNewAttempt(false);
    };
  }
private void
      createAndStartNewAttempt(boolean transferStateFromPreviousAttempt) {
    createNewAttempt();
    /**
    *触发RMAppAttemptEventType.START事件
    */
    handler.handle(new RMAppStartAttemptEvent(currentAttempt.getAppAttemptId(),
      transferStateFromPreviousAttempt));
  }
private void createNewAttempt() {
    ApplicationAttemptId appAttemptId =
        ApplicationAttemptId.newInstance(applicationId, attempts.size() + 1);
    RMAppAttempt attempt =
        new RMAppAttemptImpl(appAttemptId, rmContext, scheduler, masterService,
          submissionContext, conf,
          /**
           * 	这里有尝试次数限制
           */
          maxAppAttempts == (getNumFailedAppAttempts() + 1), amReq);
          /**
          * 记录在attempts映射表中
          */
    attempts.put(appAttemptId, attempt);
    currentAttempt = attempt;
  }

想查找RMAppAttemptEventType类型的处理器是哪个,到ResourceManager中查找为该事件类型注册的调度器。

rmDispatcher.register(RMAppAttemptEventType.class,
          new ApplicationAttemptEventDispatcher(rmContext));
@Private
  public static final class ApplicationAttemptEventDispatcher implements
      EventHandler<RMAppAttemptEvent> {
    private final RMContext rmContext;
    public ApplicationAttemptEventDispatcher(RMContext rmContext) {
      this.rmContext = rmContext;
    }
    
    @Override
    public void handle(RMAppAttemptEvent event) {
      ApplicationAttemptId appAttemptID =                                       event.getApplicationAttemptId();
      ApplicationId appAttemptId = appAttemptID.getApplicationId();
      RMApp rmApp = this.rmContext.getRMApps().get(appAttemptId);
      if (rmApp != null) {
        RMAppAttempt rmAppAttempt = rmApp.getRMAppAttempt(appAttemptID);
        if (rmAppAttempt != null) {
          try {
            rmAppAttempt.handle(event);
          } catch (Throwable t) {
            LOG.error("Error in handling event type " + event.getType()
                + " for applicationAttempt " + appAttemptId, t);
          }
        }
      }
    }
  }

从ApplicationAttemptEventDispatcher的handle()方法可以看出,事件处理器是RMAppAttemptImpl.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值