private void truncateWALs(MasterProcedureEnv env) {
    String firstWal = wals.get(0);
    try {
      env.getMasterServices().getSyncReplicationReplayWALManager().finishReplayWAL(firstWal);
    } catch (IOException e) {
      // As it is idempotent to rerun this task. Just ignore this exception and return.
      LOG.warn("Failed to truncate wal {} for peer id={}", firstWal, peerId, e);
      return;
    }
    for (int i = 1; i < wals.size(); i++) {
      String wal = wals.get(i);
      try {
        env.getMasterServices().getSyncReplicationReplayWALManager().finishReplayWAL(wal);
      } catch (IOException e1) {
        try {
          // retry
          env.getMasterServices().getSyncReplicationReplayWALManager().finishReplayWAL(wal);
        } catch (IOException e2) {
          // As the parent procedure only check the first wal length. Just ignore this exception.
          LOG.warn("Failed to truncate wal {} for peer id={}", wal, peerId, e2);
        }
      }
    }
  }
Only truncate wals one by one when task succeed. The parent procedure will check the first wal
length to know whether this task succeed.
hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/SyncReplicationReplayWALRemoteProcedure.java