@Override
  protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException {
    SyncReplicationReplayWALRemoteStateData.Builder builder =
      SyncReplicationReplayWALRemoteStateData.newBuilder().setPeerId(peerId)
        .setTargetServer(ProtobufUtil.toServerName(targetServer)).setState(state);
    wals.stream().forEach(builder::addWal);
    if (this.remoteError != null) {
      ErrorHandlingProtos.ForeignExceptionMessage fem =
        ForeignExceptionUtil.toProtoForeignException(remoteError);
      builder.setError(fem);
    }
    serializer.serialize(builder.build());
  }
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