You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by yo...@apache.org on 2024/01/05 03:21:11 UTC

(iotdb) branch election-wait created (now df4a1444401)

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

yongzao pushed a change to branch election-wait
in repository https://gitbox.apache.org/repos/asf/iotdb.git


      at df4a1444401 Finish

This branch includes the following new commits:

     new df4a1444401 Finish

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(iotdb) 01/01: Finish

Posted by yo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

yongzao pushed a commit to branch election-wait
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit df4a1444401f109bfd7586685aa0e08bb96f3c8b
Author: YongzaoDan <53...@qq.com>
AuthorDate: Fri Jan 5 11:21:01 2024 +0800

    Finish
---
 .../iotdb/confignode/service/ConfigNode.java       | 25 ++++++++++++++--------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/ConfigNode.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/ConfigNode.java
index 41d83abf92c..b242e4a250e 100644
--- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/ConfigNode.java
+++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/ConfigNode.java
@@ -129,15 +129,7 @@ public class ConfigNode implements ConfigNodeMBean {
 
         int configNodeId = CONF.getConfigNodeId();
         configManager.initConsensusManager();
-        while (configManager.getConsensusManager().getLeader() == null) {
-          LOGGER.info("Leader has not been elected yet, wait for 1 second");
-          try {
-            Thread.sleep(1000);
-          } catch (InterruptedException e) {
-            Thread.currentThread().interrupt();
-            LOGGER.warn("Unexpected interruption during waiting for leader election.");
-          }
-        }
+        waitForLeaderElected();
         setUpMetricService();
         // Notice: We always set up Seed-ConfigNode's RPC service lastly to ensure
         // that the external service is not provided until ConfigNode is fully available
@@ -180,6 +172,9 @@ public class ConfigNode implements ConfigNodeMBean {
         // or the consensusGroup will not be initialized successfully otherwise.
         SystemPropertiesUtils.storeSystemParameters();
 
+        // Wait for ConfigNode-leader elected before applying itself
+        waitForLeaderElected();
+
         // Seed-ConfigNode should apply itself when first start
         configManager
             .getNodeManager()
@@ -390,6 +385,18 @@ public class ConfigNode implements ConfigNodeMBean {
     registerManager.register(configNodeRPCService);
   }
 
+  private void waitForLeaderElected() {
+    while (configManager.getConsensusManager().getLeader() == null) {
+      LOGGER.info("Leader has not been elected yet, wait for 1 second");
+      try {
+        TimeUnit.SECONDS.sleep(1);
+      } catch (InterruptedException e) {
+        Thread.currentThread().interrupt();
+        LOGGER.warn("Unexpected interruption during waiting for leader election.");
+      }
+    }
+  }
+
   /**
    * Deactivating ConfigNode internal services.
    *