@Override
  protected Flow executeFromState(MasterProcedureEnv env, RecoverStandbyState state)
    throws ProcedureSuspendedException, ProcedureYieldException, InterruptedException {
    SyncReplicationReplayWALManager syncReplicationReplayWALManager =
      env.getMasterServices().getSyncReplicationReplayWALManager();
    switch (state) {
      case RENAME_SYNC_REPLICATION_WALS_DIR:
        try {
          syncReplicationReplayWALManager.renameToPeerReplayWALDir(peerId);
        } catch (IOException e) {
          LOG.warn("Failed to rename remote wal dir for peer id={}", peerId, e);
          setFailure("master-recover-standby", e);
          return Flow.NO_MORE_STATE;
        }
        setNextState(RecoverStandbyState.REGISTER_PEER_TO_WORKER_STORAGE);
        return Flow.HAS_MORE_STATE;
      case REGISTER_PEER_TO_WORKER_STORAGE:
        syncReplicationReplayWALManager.registerPeer(peerId);
        setNextState(RecoverStandbyState.DISPATCH_WALS);
        return Flow.HAS_MORE_STATE;
      case DISPATCH_WALS:
        dispathWals(syncReplicationReplayWALManager);
        setNextState(RecoverStandbyState.UNREGISTER_PEER_FROM_WORKER_STORAGE);
        return Flow.HAS_MORE_STATE;
      case UNREGISTER_PEER_FROM_WORKER_STORAGE:
        syncReplicationReplayWALManager.unregisterPeer(peerId);
        setNextState(RecoverStandbyState.SNAPSHOT_SYNC_REPLICATION_WALS_DIR);
        return Flow.HAS_MORE_STATE;
      case SNAPSHOT_SYNC_REPLICATION_WALS_DIR:
        try {
          syncReplicationReplayWALManager.renameToPeerSnapshotWALDir(peerId);
        } catch (IOException e) {
          LOG.warn("Failed to cleanup replay wals dir for peer id={}, , retry", peerId, e);
          throw new ProcedureYieldException();
        }
        return Flow.NO_MORE_STATE;
      default:
        throw new UnsupportedOperationException("unhandled state=" + state);
    }
  }
The procedure for replaying all the remote wals for transitting a sync replication peer from
STANDBY to DOWNGRADE_ACTIVE.
hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/RecoverStandbyProcedure.java