Skip to content

Commit

Permalink
RATIS-2166. Update nextChunkIndex when snapshot is ALREADY_INSTALLED (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
133tosakarin authored and OneSizeFitsQuorum committed Oct 9, 2024
1 parent 5d1a5ea commit 536419c
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,19 @@ private InstallSnapshotReplyProto checkAndInstallSnapshot(InstallSnapshotRequest
// considering a follower peer requiring a snapshot installation does not
// have a lot of requests
if (state.getLog().getLastCommittedIndex() >= lastIncludedIndex) {
nextChunkIndex.set(snapshotChunkRequest.getRequestIndex() + 1);
return toInstallSnapshotReplyProto(leaderId, getMemberId(),
currentTerm, snapshotChunkRequest.getRequestIndex(), InstallSnapshotResult.ALREADY_INSTALLED);
}

//TODO: We should only update State with installed snapshot once the request is done.
state.installSnapshot(request);

int idx = nextChunkIndex.getAndIncrement();
Preconditions.assertEquals(snapshotChunkRequest.getRequestIndex(), idx, "nextChunkIndex");
final int expectedChunkIndex = nextChunkIndex.getAndIncrement();
if (expectedChunkIndex != snapshotChunkRequest.getRequestIndex()) {
throw new IOException("Unexpected request chunk index: " + snapshotChunkRequest.getRequestIndex()
+ " (the expected index is " + expectedChunkIndex + ")");
}
// update the committed index
// re-load the state machine if this is the last chunk
if (snapshotChunkRequest.getDone()) {
Expand Down

0 comments on commit 536419c

Please sign in to comment.