This is an automated email from the ASF dual-hosted git repository. dragonyliu pushed a commit to branch branch-2 in repository https://gitbox.apache.org/repos/asf/ratis.git
commit 06e9401071c515b9f2e86c87445059faf154050e Author: Tsz-Wo Nicholas Sze <[email protected]> AuthorDate: Tue Aug 16 19:14:37 2022 -0700 RATIS-1676. SnapshotManager should use ServerStringUtils.toInstallSnapshotRequestString(..). (#717) (cherry picked from commit ef23b839b31fb24bc0f74156a6414f69f2b73a2c) --- .../apache/ratis/server/impl/ServerProtoUtils.java | 32 +--------------------- .../ratis/server/storage/SnapshotManager.java | 5 ++-- 2 files changed, 4 insertions(+), 33 deletions(-) diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerProtoUtils.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerProtoUtils.java index eccebb6fc..deae754c3 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerProtoUtils.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerProtoUtils.java @@ -30,7 +30,7 @@ import java.util.List; import java.util.Optional; /** Server proto utilities for internal use. */ -public final class ServerProtoUtils { +final class ServerProtoUtils { private ServerProtoUtils() {} private static RaftRpcReplyProto.Builder toRaftRpcReplyProtoBuilder( @@ -171,34 +171,4 @@ public final class ServerProtoUtils { return false; } } - - public static String convertToString(InstallSnapshotRequestProto request) { - final StringBuilder s = new StringBuilder(); - final InstallSnapshotRequestProto.SnapshotChunkProto snapshotChunk = - request.getSnapshotChunk(); - s.append(" { " + request.getServerRequest() + "leaderTerm: " + request.getLeaderTerm() + "\n"); - if (request.hasSnapshotChunk()) { - s.append("snapshotChunk: {\n requestId: " + snapshotChunk.getRequestId() + "\n") - .append(" requestIndex: " + snapshotChunk.getRequestIndex() + "\n") - .append(" raftConfiguration: " + snapshotChunk.getRaftConfiguration() + "\n") - .append(" termIndex: {\n term: " + snapshotChunk.getTermIndex().getTerm() + "\n index: " + - snapshotChunk.getTermIndex().getIndex() + "\n }\n"); - for (FileChunkProto chunk : snapshotChunk.getFileChunksList()) { - s.append(" fileChunks: {\n filename: " + chunk.getFilename() + "\n") - .append(" totalSize: " + chunk.getTotalSize() + "\n") - .append(" fileDigest: " + chunk.getFileDigest() + "\n") - .append(" chunkIndex: " + chunk.getChunkIndex() + "\n") - .append(" offset: " + chunk.getOffset() + "\n") - .append(" done: " + chunk.getDone() + "\n }\n"); - - } - s.append(" totalSize: " + snapshotChunk.getTotalSize() + "\n") - .append(" done: " + snapshotChunk.getDone()).append("\n}\n"); - } else if (request.hasNotification()) { - s.append(" notification: " + request.getNotification() + "\n"); - } - - s.append(request.getLastRaftConfigurationLogEntryProto()); - return s.toString(); - } } diff --git a/ratis-server/src/main/java/org/apache/ratis/server/storage/SnapshotManager.java b/ratis-server/src/main/java/org/apache/ratis/server/storage/SnapshotManager.java index c72e9f78e..aaa62a783 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/storage/SnapshotManager.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/storage/SnapshotManager.java @@ -31,7 +31,7 @@ import org.apache.ratis.io.MD5Hash; import org.apache.ratis.protocol.RaftPeerId; import org.apache.ratis.proto.RaftProtos.FileChunkProto; import org.apache.ratis.proto.RaftProtos.InstallSnapshotRequestProto; -import org.apache.ratis.server.impl.ServerProtoUtils; +import org.apache.ratis.server.util.ServerStringUtils; import org.apache.ratis.statemachine.SnapshotInfo; import org.apache.ratis.statemachine.StateMachine; import org.apache.ratis.util.FileUtils; @@ -75,7 +75,8 @@ public class SnapshotManager { FileUtils.createDirectories(tmpDir); tmpDir.deleteOnExit(); - LOG.info("Installing snapshot:{}, to tmp dir:{}", ServerProtoUtils.convertToString(request), tmpDir); + LOG.info("Installing snapshot:{}, to tmp dir:{}", + ServerStringUtils.toInstallSnapshotRequestString(request), tmpDir); // TODO: Make sure that subsequent requests for the same installSnapshot are coming in order, // and are not lost when whole request cycle is done. Check requestId and requestIndex here
