diff --git a/ratis-common/src/main/java/org/apache/ratis/util/ProtoUtils.java b/ratis-common/src/main/java/org/apache/ratis/util/ProtoUtils.java index cd22ebe6b4..161715bf80 100644 --- a/ratis-common/src/main/java/org/apache/ratis/util/ProtoUtils.java +++ b/ratis-common/src/main/java/org/apache/ratis/util/ProtoUtils.java @@ -35,6 +35,8 @@ import org.apache.ratis.protocol.RaftPeer; import org.apache.ratis.protocol.RaftPeerId; import org.apache.ratis.thirdparty.com.google.protobuf.ByteString; +import org.apache.ratis.thirdparty.com.google.protobuf.MessageOrBuilder; +import org.apache.ratis.thirdparty.com.google.protobuf.TextFormat; import java.io.IOException; import java.io.ObjectOutputStream; @@ -250,4 +252,8 @@ static String toString(RaftRpcReplyProto proto) { + "#" + proto.getCallId() + ":" + (proto.getSuccess()? "OK": "FAIL"); } + + static String shortDebugString(MESSAGE message) { + return message != null ? TextFormat.shortDebugString(message) : "null"; + } } diff --git a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolService.java b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolService.java index b123c44a77..a13e74b89d 100644 --- a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolService.java +++ b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolService.java @@ -25,7 +25,6 @@ import org.apache.ratis.server.protocol.RaftServerProtocol; import org.apache.ratis.server.util.ServerStringUtils; import org.apache.ratis.thirdparty.com.google.protobuf.MessageOrBuilder; -import org.apache.ratis.thirdparty.com.google.protobuf.TextFormat; import org.apache.ratis.thirdparty.io.grpc.Status; import org.apache.ratis.thirdparty.io.grpc.StatusRuntimeException; import org.apache.ratis.thirdparty.io.grpc.stub.StreamObserver; @@ -176,7 +175,7 @@ public void onCompleted() { requestFuture.get().thenAccept(reply -> { BatchLogger.print(BatchLogKey.COMPLETED_REPLY, getName(), suffix -> LOG.info("{}: Completed {}, lastReply: {} {}", - getId(), op, TextFormat.shortDebugString(reply), suffix)); + getId(), op, ProtoUtils.shortDebugString(reply), suffix)); responseObserver.onCompleted(); }); } diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotInstallationHandler.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotInstallationHandler.java index faefaaa38c..eac690feb2 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotInstallationHandler.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotInstallationHandler.java @@ -36,7 +36,6 @@ import org.apache.ratis.server.protocol.TermIndex; import org.apache.ratis.server.raftlog.LogProtoUtils; import org.apache.ratis.server.util.ServerStringUtils; -import org.apache.ratis.thirdparty.com.google.protobuf.TextFormat; import org.apache.ratis.util.BatchLogger; import org.apache.ratis.util.CodeInjectionForTesting; import org.apache.ratis.util.LifeCycle; @@ -145,7 +144,7 @@ private InstallSnapshotReplyProto installSnapshotImpl(InstallSnapshotRequestProt final LogEntryProto proto = request.getLastRaftConfigurationLogEntryProto(); state.truncate(proto.getIndex()); if (!state.getRaftConf().equals(LogProtoUtils.toRaftConfiguration(proto))) { - LOG.info("{}: set new configuration {} from snapshot", getMemberId(), TextFormat.shortDebugString(proto)); + LOG.info("{}: set new configuration {} from snapshot", getMemberId(), ProtoUtils.shortDebugString(proto)); state.setRaftConf(proto); state.writeRaftConfiguration(proto); server.getStateMachine().event().notifyConfigurationChanged(