This is an automated email from the ASF dual-hosted git repository.

williamsong pushed a commit to branch snapshot-3
in repository https://gitbox.apache.org/repos/asf/ratis.git

commit d09cbac4c2e1e60aba5a68641036ff9fec2848c4
Author: szywilliam <[email protected]>
AuthorDate: Fri May 17 11:24:14 2024 +0800

    reply ALREADY_INSTALLED to old snapshot installation request
---
 .../java/org/apache/ratis/server/impl/ConfigurationManager.java    | 4 ++--
 .../src/main/java/org/apache/ratis/server/impl/ServerState.java    | 4 +++-
 .../org/apache/ratis/server/impl/SnapshotInstallationHandler.java  | 7 ++++---
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/ConfigurationManager.java
 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/ConfigurationManager.java
index 0e020b7e3..0746cd772 100644
--- 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/ConfigurationManager.java
+++ 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/ConfigurationManager.java
@@ -59,10 +59,10 @@ public class ConfigurationManager {
     }
   }
 
-  synchronized void addConfiguration(RaftConfiguration conf) {
+  synchronized void addConfiguration(RaftConfiguration conf, long commitIndex) 
{
     final long logIndex = conf.getLogEntryIndex();
     final RaftConfiguration found = configurations.get(logIndex);
-    if (found != null) {
+    if (found != null && logIndex <= commitIndex) {
       Preconditions.assertTrue(found.equals(conf));
       return;
     }
diff --git 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java
index e21f63caa..487054796 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java
@@ -377,7 +377,9 @@ class ServerState {
   }
 
   void setRaftConf(RaftConfiguration conf) {
-    configurationManager.addConfiguration(conf);
+    final long lastCommittedIndex = server.getState().log.isInitialized() ?
+        server.getRaftLog().getLastCommittedIndex() : 
RaftLog.INVALID_LOG_INDEX;
+    configurationManager.addConfiguration(conf, lastCommittedIndex);
     server.getServerRpc().addRaftPeers(conf.getAllPeers());
     final Collection<RaftPeer> listeners = 
conf.getAllPeers(RaftPeerRole.LISTENER);
     if (!listeners.isEmpty()) {
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 9794314b8..68b2ee4e6 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
@@ -174,9 +174,10 @@ 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().getLastCommittedIndex() < 
lastIncludedIndex,
-            "%s log's commit index is %s, last included index in snapshot is 
%s",
-            getMemberId(), state.getLog().getLastCommittedIndex(), 
lastIncludedIndex);
+        if (state.getLog().getLastCommittedIndex() >= lastIncludedIndex) {
+          return ServerProtoUtils.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);

Reply via email to