protected void doReplaceWriter(Path oldPath, Path newPath, W nextWriter) throws IOException {
    Preconditions.checkNotNull(nextWriter);
    waitForSafePoint();
    /**
     * For {@link FSHLog},here would shut down {@link FSHLog.SyncRunner}.
     */
    doCleanUpResources();
    // we will call rollWriter in init method, where we want to create the first writer and
    // obviously the previous writer is null, so here we need this null check. And why we must call
    // logRollAndSetupWalProps before closeWriter is that, we will call markClosedAndClean after
    // closing the writer asynchronously, we need to make sure the WALProps is put into
    // walFile2Props before we call markClosedAndClean
    if (writer != null) {
      long oldFileLen = writer.getLength();
      logRollAndSetupWalProps(oldPath, newPath, oldFileLen);
      closeWriter(writer, oldPath);
    } else {
      logRollAndSetupWalProps(oldPath, newPath, 0);
    }
    this.writer = nextWriter;
    /**
     * Here is used for {@link AsyncFSWAL} and {@link FSHLog} to set the under layer filesystem
     * output after writer is replaced.
     */
    onWriterReplaced(nextWriter);
    this.fileLengthAtLastSync = nextWriter.getLength();
    this.highestProcessedAppendTxidAtLastSync = 0L;
    consumeLock.lock();
    try {
      consumerScheduled.set(true);
      int currentEpoch = epochAndState >>> 2;
      int nextEpoch = currentEpoch == MAX_EPOCH ? 0 : currentEpoch + 1;
      // set a new epoch and also clear waitingRoll and writerBroken
      this.epochAndState = nextEpoch << 2;
      // Reset rollRequested status
      rollRequested.set(false);
      consumeExecutor.execute(consumer);
    } finally {
      consumeLock.unlock();
    }
  }
Notice that you need to clear the {@link #rollRequested} flag in this method, as the new writer
will begin to work before returning from this method. If we clear the flag after returning from
this call, we may miss a roll request. The implementation class should choose a proper place to
clear the {@link #rollRequested} flag, so we do not miss a roll request, typically before you
start writing to the new writer.
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AbstractFSWAL.java