Skip to content

Commit 09f6b39

Browse files
authored
RATIS-2166. Update nextChunkIndex when snapshot is ALREADY_INSTALLED (#1159)
1 parent de4e24d commit 09f6b39

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotInstallationHandler.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,19 @@ private InstallSnapshotReplyProto checkAndInstallSnapshot(InstallSnapshotRequest
185185
// considering a follower peer requiring a snapshot installation does not
186186
// have a lot of requests
187187
if (state.getLog().getLastCommittedIndex() >= lastIncludedIndex) {
188+
nextChunkIndex.set(snapshotChunkRequest.getRequestIndex() + 1);
188189
return toInstallSnapshotReplyProto(leaderId, getMemberId(),
189190
currentTerm, snapshotChunkRequest.getRequestIndex(), InstallSnapshotResult.ALREADY_INSTALLED);
190191
}
191192

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

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

0 commit comments

Comments
 (0)