This is an automated email from the ASF dual-hosted git repository. adoroszlai pushed a commit to branch branch-2 in repository https://gitbox.apache.org/repos/asf/ratis.git
commit a96bfeeb3578a4a548a973f4ab58093bc83577f4 Author: William Song <[email protected]> AuthorDate: Fri Apr 28 01:09:57 2023 +0800 RATIS-1838. Compare commit index with last included index when installSnapshot (#878) (cherry picked from commit 19725221286da5d56d7dd9efc4070b48d6f8ae6d) --- .../apache/ratis/server/impl/SnapshotInstallationHandler.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 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 abb398367..334ef3059 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 @@ -157,7 +157,7 @@ class SnapshotInstallationHandler { final InstallSnapshotRequestProto.SnapshotChunkProto snapshotChunkRequest = request.getSnapshotChunk(); final TermIndex lastIncluded = TermIndex.valueOf(snapshotChunkRequest.getTermIndex()); final long lastIncludedIndex = lastIncluded.getIndex(); - synchronized (this) { + synchronized (server) { final boolean recognized = state.recognizeLeader(leaderId, leaderTerm); currentTerm = state.getCurrentTerm(); if (!recognized) { @@ -174,9 +174,9 @@ class SnapshotInstallationHandler { // Check and append the snapshot chunk. We simply put this in lock // considering a follower peer requiring a snapshot installation does not // have a lot of requests - Preconditions.assertTrue(state.getLog().getNextIndex() <= lastIncludedIndex, - "%s log's next id is %s, last included index in snapshot is %s", - getMemberId(), state.getLog().getNextIndex(), lastIncludedIndex); + Preconditions.assertTrue(state.getLog().getLastCommittedIndex() < lastIncludedIndex, + "%s log's commit index is %s, last included index in snapshot is %s", + getMemberId(), state.getLog().getLastCommittedIndex(), lastIncludedIndex); //TODO: We should only update State with installed snapshot once the request is done. state.installSnapshot(request); @@ -204,7 +204,7 @@ class SnapshotInstallationHandler { final TermIndex firstAvailableLogTermIndex = TermIndex.valueOf( request.getNotification().getFirstAvailableTermIndex()); final long firstAvailableLogIndex = firstAvailableLogTermIndex.getIndex(); - synchronized (this) { + synchronized (server) { final boolean recognized = state.recognizeLeader(leaderId, leaderTerm); currentTerm = state.getCurrentTerm(); if (!recognized) {
