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

[iotdb] branch IOTDB-5904 created (now 224e65e3e38)

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

rong pushed a change to branch IOTDB-5904
in repository https://gitbox.apache.org/repos/asf/iotdb.git


      at 224e65e3e38 better way to start PipeMetaSyncer

This branch includes the following new commits:

     new e7f61ac39b1 adjust LoadManager's init order on CN
     new 224e65e3e38 better way to start PipeMetaSyncer

The 2 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/02: adjust LoadManager's init order on CN

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

rong pushed a commit to branch IOTDB-5904
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit e7f61ac39b158ef6f7ad3eb538d26b96433391d8
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Sun May 21 17:08:03 2023 +0800

    adjust LoadManager's init order on CN
---
 .../org/apache/iotdb/confignode/manager/ConfigManager.java     | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java b/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
index a23b6b44412..8c784c1fcc3 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
@@ -291,12 +291,14 @@ public class ConfigManager implements IManager {
     this.modelManager = new ModelManager(this, modelInfo);
     this.pipeManager = new PipeManager(this, pipeInfo);
 
+    // 1. keep PipeManager initialization before LoadManager initialization, because
+    // LoadManager will register PipeManager as a listener.
+    // 2. keep RetryFailedTasksThread initialization after LoadManager initialization,
+    // because RetryFailedTasksThread will keep a reference of LoadManager.
+    this.loadManager = new LoadManager(this);
+
     this.retryFailedTasksThread = new RetryFailedTasksThread(this);
     this.clusterQuotaManager = new ClusterQuotaManager(this, quotaInfo);
-
-    // Please keep loadManager initializing at last because it may require other managers to
-    // register the eventBus
-    this.loadManager = new LoadManager(this);
   }
 
   public void initConsensusManager() throws IOException {


[iotdb] 02/02: better way to start PipeMetaSyncer

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

rong pushed a commit to branch IOTDB-5904
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 224e65e3e382abf98bb248297c089dde9841a3cb
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Sun May 21 19:09:00 2023 +0800

    better way to start PipeMetaSyncer
---
 .../manager/pipe/runtime/PipeMetaSyncer.java       | 47 +++++++++++++++++++---
 1 file changed, 41 insertions(+), 6 deletions(-)

diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/runtime/PipeMetaSyncer.java b/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/runtime/PipeMetaSyncer.java
index ba9bba61c6a..df080857e9a 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/runtime/PipeMetaSyncer.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/runtime/PipeMetaSyncer.java
@@ -37,11 +37,10 @@ public class PipeMetaSyncer {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(PipeMetaSyncer.class);
 
-  private static final ScheduledExecutorService SYNC_EXECUTOR =
-      IoTDBThreadPoolFactory.newSingleThreadScheduledExecutor(
-          ThreadName.PIPE_META_SYNC_SERVICE.getName());
   // TODO: make this configurable
+  private static final long INITIAL_SYNC_DELAY_MINUTES = 1;
   private static final long SYNC_INTERVAL_MINUTES = 3;
+  private static ScheduledExecutorService syncExecutor;
 
   private final ConfigManager configManager;
 
@@ -52,11 +51,37 @@ public class PipeMetaSyncer {
   }
 
   public synchronized void start() {
+    stop();
+
+    // 1. wait for consensus layer ready
+    while (configManager.getConsensusManager() == null) {
+      try {
+        LOGGER.info("consensus layer is not ready, sleep 1s...");
+        TimeUnit.SECONDS.sleep(1);
+      } catch (InterruptedException e) {
+        Thread.currentThread().interrupt();
+        LOGGER.warn("unexpected interruption during waiting for consensus layer ready.");
+      }
+    }
+
+    // 2. start sync executor
+    if (syncExecutor == null) {
+      syncExecutor =
+          IoTDBThreadPoolFactory.newSingleThreadScheduledExecutor(
+              ThreadName.PIPE_META_SYNC_SERVICE.getName());
+      LOGGER.info("syncExecutor is started successfully.");
+    }
+
+    // 3. start meta sync task
     if (metaSyncFuture == null) {
       metaSyncFuture =
           ScheduledExecutorUtil.safelyScheduleWithFixedDelay(
-              SYNC_EXECUTOR, this::sync, 0, SYNC_INTERVAL_MINUTES, TimeUnit.MINUTES);
-      LOGGER.info("PipeMetaSyncer is started successfully.");
+              syncExecutor,
+              this::sync,
+              INITIAL_SYNC_DELAY_MINUTES,
+              SYNC_INTERVAL_MINUTES,
+              TimeUnit.MINUTES);
+      LOGGER.info("metaSyncFuture is submitted successfully.");
     }
   }
 
@@ -74,7 +99,17 @@ public class PipeMetaSyncer {
     if (metaSyncFuture != null) {
       metaSyncFuture.cancel(false);
       metaSyncFuture = null;
-      LOGGER.info("PipeMetaSyncer is stopped successfully.");
+      LOGGER.info("metaSyncFuture is cancelled successfully.");
+    }
+
+    try {
+      if (syncExecutor != null) {
+        syncExecutor.shutdown();
+        syncExecutor = null;
+        LOGGER.info("syncExecutor is shutdown successfully.");
+      }
+    } catch (Throwable t) {
+      LOGGER.error("Failed to shutdown syncExecutor", t);
     }
   }
 }