szetszwo commented on code in PR #1168:
URL: https://github.com/apache/ratis/pull/1168#discussion_r1805936992
##########
ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotInstallationHandler.java:
##########
@@ -156,27 +157,31 @@ private InstallSnapshotReplyProto
installSnapshotImpl(InstallSnapshotRequestProt
return failedReply;
}
- private InstallSnapshotReplyProto
checkAndInstallSnapshot(InstallSnapshotRequestProto request,
+ private CompletableFuture<InstallSnapshotReplyProto>
checkAndInstallSnapshot(InstallSnapshotRequestProto request,
RaftPeerId leaderId) throws IOException {
final long currentTerm;
final long leaderTerm = request.getLeaderTerm();
final InstallSnapshotRequestProto.SnapshotChunkProto snapshotChunkRequest
= request.getSnapshotChunk();
final TermIndex lastIncluded =
TermIndex.valueOf(snapshotChunkRequest.getTermIndex());
final long lastIncludedIndex = lastIncluded.getIndex();
+ CompletableFuture<Void> future;
+ InstallSnapshotReplyProto reply;
synchronized (server) {
final boolean recognized =
state.recognizeLeader(RaftServerProtocol.Op.INSTALL_SNAPSHOT, leaderId,
leaderTerm);
currentTerm = state.getCurrentTerm();
if (!recognized) {
- return toInstallSnapshotReplyProto(leaderId, getMemberId(),
- currentTerm, snapshotChunkRequest.getRequestIndex(),
InstallSnapshotResult.NOT_LEADER);
+ return
CompletableFuture.completedFuture(toInstallSnapshotReplyProto(leaderId,
getMemberId(),
+ currentTerm, snapshotChunkRequest.getRequestIndex(),
InstallSnapshotResult.NOT_LEADER));
}
- server.changeToFollowerAndPersistMetadata(leaderTerm, true,
"installSnapshot");
+ future = server.changeToFollowerAndPersistMetadata(leaderTerm, true,
"installSnapshot");
state.setLeader(leaderId, "installSnapshot");
server.updateLastRpcTime(FollowerState.UpdateType.INSTALL_SNAPSHOT_START);
if (snapshotChunkRequest.getRequestIndex() == 0) {
nextChunkIndex.set(0);
} else if (nextChunkIndex.get() !=
snapshotChunkRequest.getRequestIndex()) {
+ // exception new throw, we need join future in another thread
+ CompletableFuture.runAsync(future::join);
Review Comment:
@133tosakarin , we need to remove all
`CompletableFuture.runAsync(future::join)`. They are not useful. See
https://github.com/apache/ratis/pull/1168#discussion_r1805936472
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]