From 79dd21901926074285fb70acd758f56a99ea881c Mon Sep 17 00:00:00 2001 From: dengchao <2326884052@qq.com> Date: Mon, 30 Sep 2024 17:45:22 +0800 Subject: [PATCH 1/2] fix not update chunk_index --- .../apache/ratis/server/impl/SnapshotInstallationHandler.java | 1 + 1 file changed, 1 insertion(+) 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 9b84e8f1d1..ed3e0bb6a7 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 @@ -185,6 +185,7 @@ 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); } From 44a687f88570551f7ac90ee404c331925b0bc181 Mon Sep 17 00:00:00 2001 From: dengchao <2326884052@qq.com> Date: Wed, 9 Oct 2024 09:31:51 +0800 Subject: [PATCH 2/2] change assert to throw IOException --- .../ratis/server/impl/SnapshotInstallationHandler.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 ed3e0bb6a7..537b384c64 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 @@ -193,8 +193,11 @@ private InstallSnapshotReplyProto checkAndInstallSnapshot(InstallSnapshotRequest //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()) {