Hadoop HA中EditLogTailer的作用

/**
 * EditLogTailer represents a thread which periodically reads from edits
 * journals and applies the transactions contained within to a given
 * FSNamesystem.
 */

triggerActiveLogRoll()在standby的namenode中被调用,触发active namenode上的行为

  /**
   * NameNodeProxy factory method.
   * @return a Callable to roll logs on remote NameNode.
   */
  @VisibleForTesting
  Callable<Void> getNameNodeProxy() {
    // 此处为工厂模式
    return new MultipleNameNodeProxy<Void>() {
      @Override
      protected Void doWork() throws IOException {
        cachedActiveProxy.rollEditLog();
        return null;
      }
    };
  }

  /**
   * Trigger the active node to roll its logs.
   */
  @VisibleForTesting
  void triggerActiveLogRoll() {
    LOG.info("Triggering log roll on remote NameNode");
    Future<Void> future = null;
    try {
      // 使用线程池,通过另一个线程调用
      future = rollEditsRpcExecutor.submit(getNameNodeProxy());
      // 等待
      future.get(rollEditsTimeoutMs, TimeUnit.MILLISECONDS);
      lastRollTriggerTxId = lastLoadedTxnId;
    } catch (ExecutionException e) {
      LOG.warn("Unable to trigger a roll of the active NN", e);
    } catch (TimeoutException e) {
      if (future != null) {
        future.cancel(true);
      }
      LOG.warn(String.format(
          "Unable to finish rolling edits in %d ms", rollEditsTimeoutMs));
    } catch (InterruptedException e) {
      LOG.warn("Unable to trigger a roll of the active NN", e);
    }
  }

经过触发该函数后,通过protobuf触发active namenode上的NameNodeRpcServer.rollEditLog()

  @Override // NamenodeProtocol
  public CheckpointSignature rollEditLog() throws IOException {
    checkNNStartup();
    namesystem.checkSuperuserPrivilege();
    return namesystem.rollEditLog();
  }

之后的调用过程为

NameNodeRpcServer.rollEditLog()
  ->FSNameSystem.rollEditLog()
  ->FSImage.rollEditLog(int layoutVersion)
  ->FSEditlog.rollEditLog(int layoutVersion)

standby namenode执行日志

active namenode执行日志

posted @ 2021-12-08 14:19  Yu\.W  阅读(286)  评论(0编辑  收藏  举报