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

tanxinyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new ac648a3a2a0 Deduplication IoTConsensus Configuration And Remove 
Unuseless File Delete (#12385)
ac648a3a2a0 is described below

commit ac648a3a2a0a89cd0a0682a6a50bc8e82afb5891
Author: Xiangpeng Hu <[email protected]>
AuthorDate: Tue Apr 23 11:47:52 2024 +0800

    Deduplication IoTConsensus Configuration And Remove Unuseless File Delete 
(#12385)
    
    * remove duplicate configuration
    
    * remove unuseless delete
    
    * change removeif
---
 .../iotdb/consensus/iot/IoTConsensusServerImpl.java   | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git 
a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensusServerImpl.java
 
b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensusServerImpl.java
index ecd8debea7b..e2d02b75338 100644
--- 
a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensusServerImpl.java
+++ 
b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensusServerImpl.java
@@ -81,9 +81,12 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.PriorityQueue;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
@@ -630,8 +633,8 @@ public class IoTConsensusServerImpl {
     // step 2, update configuration
     configuration.add(targetPeer);
     // step 3, persist configuration
-    logger.info("[IoTConsensus] persist new configuration: {}", configuration);
     persistConfiguration();
+    logger.info("[IoTConsensus] persist new configuration: {}", configuration);
   }
 
   public void removeSyncLogChannel(Peer targetPeer) throws 
ConsensusGroupModifyPeerException {
@@ -652,6 +655,7 @@ public class IoTConsensusServerImpl {
 
   public void persistConfiguration() {
     try {
+      removeDuplicateConfiguration();
       renameTmpConfigurationFileToRemoveSuffix();
       serializeConfigurationAndFsyncToDisk();
       deleteConfiguration();
@@ -707,7 +711,6 @@ public class IoTConsensusServerImpl {
       configuration.add(Peer.deserialize(buffer));
     }
     persistConfiguration();
-    Files.delete(oldConfigurationPath);
   }
 
   public static String generateConfigurationDatFileName(int nodeId, String 
suffix) {
@@ -983,6 +986,18 @@ public class IoTConsensusServerImpl {
     }
   }
 
+  public void removeDuplicateConfiguration() {
+    Set<Peer> seen = new HashSet<>();
+    Iterator<Peer> it = configuration.iterator();
+
+    while (it.hasNext()) {
+      Peer peer = it.next();
+      if (!seen.add(peer)) {
+        it.remove();
+      }
+    }
+  }
+
   /**
    * This method is used for write of IoTConsensus SyncLog. By this method, we 
can keep write order
    * in follower the same as the leader. And besides order insurance, we can 
make the

Reply via email to