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 <[email protected]> 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. *
