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

[iotdb] branch master updated: [IOTDB-3042] ConfigNode stop process (#5755)

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

qiaojialin 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 057a8b96cc [IOTDB-3042] ConfigNode stop process (#5755)
057a8b96cc is described below

commit 057a8b96cc0061a4c99f0e816649762e1b648aea
Author: YongzaoDan <33...@users.noreply.github.com>
AuthorDate: Sun May 1 16:38:16 2022 +0800

    [IOTDB-3042] ConfigNode stop process (#5755)
---
 .../src/assembly/resources/sbin/stop-confignode.sh |  15 ++-
 .../confignode/manager/ClusterSchemaManager.java   |   3 +-
 .../confignode/persistence/ClusterSchemaInfo.java  |  10 ++
 .../iotdb/confignode/persistence/DataNodeInfo.java |  14 ++-
 .../confignode/persistence/PartitionInfo.java      |  23 ++--
 .../iotdb/confignode/service/ConfigNode.java       |  27 ++---
 .../utils/ConfigNodeEnvironmentUtils.java          | 134 ---------------------
 .../iotdb/commons/partition/DataPartition.java     |   9 ++
 .../iotdb/commons/partition/SchemaPartition.java   |   9 ++
 9 files changed, 81 insertions(+), 163 deletions(-)

diff --git a/confignode/src/assembly/resources/sbin/stop-confignode.sh b/confignode/src/assembly/resources/sbin/stop-confignode.sh
index d4725bd180..0fc7b7b4c3 100644
--- a/confignode/src/assembly/resources/sbin/stop-confignode.sh
+++ b/confignode/src/assembly/resources/sbin/stop-confignode.sh
@@ -21,13 +21,20 @@
 
 CONFIGNODE_CONF="`dirname "$0"`/../conf"
 rpc_port=`sed '/^rpc_port=/!d;s/.*=//' ${CONFIGNODE_CONF}/iotdb-confignode.properties`
-if type lsof > /dev/null; then
-  PID=$(lsof -t -i:${rpc_port})
+
+if  type lsof > /dev/null 2>&1 ; then
+  PID=$(lsof -t -i:${rpc_port} -sTCP:LISTEN)
+elif type netstat > /dev/null 2>&1 ; then
+  PID=$(netstat -anp 2>/dev/null | grep ":${rpc_port} " | grep ' LISTEN ' | awk '{print $NF}' | sed "s|/.*||g" )
 else
-  PID=$(ps ax | grep -i 'ConfigNode' | grep java | grep -v grep | awk '{print $1}')
+  echo ""
+  echo " Error: No necessary tool."
+  echo " Please install 'lsof' or 'netstat'."
+  exit 1
 fi
+
 if [ -z "$PID" ]; then
-  echo "No ConfigNode server to stop"
+  echo "No ConfigNode to stop"
   exit 1
 else
   kill -s TERM $PID
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/manager/ClusterSchemaManager.java b/confignode/src/main/java/org/apache/iotdb/confignode/manager/ClusterSchemaManager.java
index fedc366d1e..96aff29971 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/manager/ClusterSchemaManager.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/manager/ClusterSchemaManager.java
@@ -136,7 +136,8 @@ public class ClusterSchemaManager {
       TConsensusGroupId consensusGroupId =
           new TConsensusGroupId(type, partitionInfo.generateNextRegionGroupId());
       regionReplicaSet.setRegionId(consensusGroupId);
-      regionReplicaSet.setDataNodeLocations(onlineDataNodes.subList(0, replicaCount));
+      regionReplicaSet.setDataNodeLocations(
+          new ArrayList<>(onlineDataNodes.subList(0, replicaCount)));
       createRegionsReq.addRegion(regionReplicaSet);
 
       switch (type) {
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/ClusterSchemaInfo.java b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/ClusterSchemaInfo.java
index d684975c07..b1a72820ed 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/ClusterSchemaInfo.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/ClusterSchemaInfo.java
@@ -43,6 +43,7 @@ import org.apache.iotdb.rpc.TSStatusCode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -56,6 +57,7 @@ public class ClusterSchemaInfo {
   // StorageGroup read write lock
   private final ReentrantReadWriteLock storageGroupReadWriteLock;
 
+  // TODO: serialize and deserialize
   private MTreeAboveSG mTree;
 
   private ClusterSchemaInfo() {
@@ -328,6 +330,14 @@ public class ClusterSchemaInfo {
     return result;
   }
 
+  public void serialize(ByteBuffer buffer) {
+    // TODO: Serialize ClusterSchemaInfo
+  }
+
+  public void deserialize(ByteBuffer buffer) {
+    // TODO: Deserialize ClusterSchemaInfo
+  }
+
   @TestOnly
   public void clear() {
     mTree.clear();
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/DataNodeInfo.java b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/DataNodeInfo.java
index a728cd39a1..cd1f37d9ac 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/DataNodeInfo.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/DataNodeInfo.java
@@ -26,6 +26,7 @@ import org.apache.iotdb.confignode.consensus.request.write.RegisterDataNodeReq;
 import org.apache.iotdb.confignode.consensus.response.DataNodeLocationsResp;
 import org.apache.iotdb.rpc.TSStatusCode;
 
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -45,12 +46,13 @@ public class DataNodeInfo {
   // TODO: serialize and deserialize
   private AtomicInteger nextDataNodeId = new AtomicInteger(0);
 
-  /** online data nodes */
+  // Online data nodes
   // TODO: serialize and deserialize
   private final ConcurrentNavigableMap<Integer, TDataNodeLocation> onlineDataNodes =
       new ConcurrentSkipListMap();
 
-  /** For remove node or draining node */
+  // For remove node or draining node
+  // TODO: serialize and deserialize
   private final Set<TDataNodeLocation> drainingDataNodes = new HashSet<>();
 
   private DataNodeInfo() {
@@ -169,6 +171,14 @@ public class DataNodeInfo {
     return nextDataNodeId.getAndIncrement();
   }
 
+  public void serialize(ByteBuffer buffer) {
+    // TODO: Serialize DataNodeInfo
+  }
+
+  public void deserialize(ByteBuffer buffer) {
+    // TODO: Deserialize DataNodeInfo
+  }
+
   @TestOnly
   public void clear() {
     nextDataNodeId = new AtomicInteger(0);
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/PartitionInfo.java b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/PartitionInfo.java
index b2aa633443..0799582995 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/PartitionInfo.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/PartitionInfo.java
@@ -39,6 +39,7 @@ import org.apache.iotdb.confignode.consensus.response.SchemaPartitionResp;
 import org.apache.iotdb.consensus.common.DataSet;
 import org.apache.iotdb.rpc.TSStatusCode;
 
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -49,22 +50,20 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
 /** manage data partition and schema partition */
 public class PartitionInfo {
 
-  // TODO: Serialize and Deserialize
-  private AtomicInteger nextRegionGroupId = new AtomicInteger(0);
-
   // Region read write lock
   private final ReentrantReadWriteLock regionReadWriteLock;
+  // TODO: Serialize and Deserialize
+  private AtomicInteger nextRegionGroupId = new AtomicInteger(0);
+  // TODO: Serialize and Deserialize
   private final Map<TConsensusGroupId, TRegionReplicaSet> regionMap;
 
-  // schema partition read write lock
+  // SchemaPartition read write lock
   private final ReentrantReadWriteLock schemaPartitionReadWriteLock;
-
-  // data partition read write lock
-  private final ReentrantReadWriteLock dataPartitionReadWriteLock;
-
   // TODO: Serialize and Deserialize
   private final SchemaPartition schemaPartition;
 
+  // DataPartition read write lock
+  private final ReentrantReadWriteLock dataPartitionReadWriteLock;
   // TODO: Serialize and Deserialize
   private final DataPartition dataPartition;
 
@@ -299,6 +298,14 @@ public class PartitionInfo {
     return result;
   }
 
+  public void serialize(ByteBuffer buffer) {
+    // TODO: Serialize PartitionInfo
+  }
+
+  public void deserialize(ByteBuffer buffer) {
+    // TODO: Deserialize PartitionInfo
+  }
+
   @TestOnly
   public void clear() {
     nextRegionGroupId = new AtomicInteger(0);
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/service/ConfigNode.java b/confignode/src/main/java/org/apache/iotdb/confignode/service/ConfigNode.java
index 9dbb4b30bc..4d7f34c2f8 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/service/ConfigNode.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/service/ConfigNode.java
@@ -18,11 +18,9 @@
  */
 package org.apache.iotdb.confignode.service;
 
-import org.apache.iotdb.commons.exception.ShutdownException;
 import org.apache.iotdb.commons.exception.StartupException;
 import org.apache.iotdb.commons.service.JMXService;
 import org.apache.iotdb.commons.service.RegisterManager;
-import org.apache.iotdb.commons.utils.TestOnly;
 import org.apache.iotdb.confignode.conf.ConfigNodeConstant;
 import org.apache.iotdb.confignode.manager.ConfigManager;
 import org.apache.iotdb.confignode.service.thrift.ConfigNodeRPCService;
@@ -54,7 +52,11 @@ public class ConfigNode implements ConfigNodeMBean {
       this.configManager = new ConfigManager();
     } catch (IOException e) {
       LOGGER.error("Can't start ConfigNode consensus group!", e);
-      stop();
+      try {
+        stop();
+      } catch (IOException e2) {
+        LOGGER.error("Meet error when stop ConfigNode!", e);
+      }
       System.exit(0);
     }
   }
@@ -79,29 +81,26 @@ public class ConfigNode implements ConfigNodeMBean {
       setUp();
     } catch (StartupException | IOException e) {
       LOGGER.error("Meet error while starting up.", e);
-      deactivate();
+      try {
+        deactivate();
+      } catch (IOException e2) {
+        LOGGER.error("Meet error when stop ConfigNode!", e);
+      }
       return;
     }
 
     LOGGER.info("{} has started.", ConfigNodeConstant.GLOBAL_NAME);
   }
 
-  public void deactivate() {
+  public void deactivate() throws IOException {
     LOGGER.info("Deactivating {}...", ConfigNodeConstant.GLOBAL_NAME);
     registerManager.deregisterAll();
     JMXService.deregisterMBean(mbeanName);
+    configManager.close();
     LOGGER.info("{} is deactivated.", ConfigNodeConstant.GLOBAL_NAME);
   }
 
-  @TestOnly
-  public void shutdown() throws ShutdownException {
-    LOGGER.info("Deactivating {}...", ConfigNodeConstant.GLOBAL_NAME);
-    registerManager.shutdownAll();
-    JMXService.deregisterMBean(mbeanName);
-    LOGGER.info("{} is deactivated.", ConfigNodeConstant.GLOBAL_NAME);
-  }
-
-  public void stop() {
+  public void stop() throws IOException {
     deactivate();
   }
 }
diff --git a/confignode/src/test/java/org/apache/iotdb/confignode/utils/ConfigNodeEnvironmentUtils.java b/confignode/src/test/java/org/apache/iotdb/confignode/utils/ConfigNodeEnvironmentUtils.java
deleted file mode 100644
index c178aadb1d..0000000000
--- a/confignode/src/test/java/org/apache/iotdb/confignode/utils/ConfigNodeEnvironmentUtils.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.iotdb.confignode.utils;
-
-import org.apache.iotdb.commons.exception.ShutdownException;
-import org.apache.iotdb.commons.utils.TestOnly;
-import org.apache.iotdb.confignode.conf.ConfigNodeConstant;
-import org.apache.iotdb.confignode.service.ConfigNode;
-
-import org.apache.commons.io.FileUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.IOException;
-
-import static org.junit.Assert.fail;
-
-/** Test environment for ConfigNode UT and IT */
-public class ConfigNodeEnvironmentUtils {
-
-  private static final Logger LOGGER = LoggerFactory.getLogger(ConfigNodeEnvironmentUtils.class);
-
-  private static ConfigNode daemon;
-
-  @TestOnly
-  public static void envSetUp() {
-    LOGGER.debug("ConfigNodeEnvironmentUtils setup...");
-
-    if (daemon == null) {
-      daemon = new ConfigNode();
-    }
-
-    try {
-      daemon.active();
-    } catch (Exception e) {
-      fail(e.getMessage());
-    }
-
-    createAllDir();
-  }
-
-  @TestOnly
-  public static void cleanEnv() {
-    LOGGER.debug("ConfigNodeEnvironmentUtils cleanEnv...");
-
-    if (daemon != null) {
-      daemon.stop();
-      daemon = null;
-    }
-
-    // delete all directory
-    cleanAllDir();
-  }
-
-  @TestOnly
-  public static void stopDaemon() {
-    if (daemon != null) {
-      daemon.stop();
-    }
-  }
-
-  @TestOnly
-  public static void shutdownDaemon() throws ShutdownException {
-    if (daemon != null) {
-      daemon.shutdown();
-    }
-  }
-
-  @TestOnly
-  public static void activeDaemon() {
-    if (daemon != null) {
-      daemon.active();
-    }
-  }
-
-  @TestOnly
-  public static void reactiveDaemon() {
-    if (daemon == null) {
-      daemon = new ConfigNode();
-      daemon.active();
-    } else {
-      activeDaemon();
-    }
-  }
-
-  @TestOnly
-  public static void restartDaemon() throws ShutdownException {
-    shutdownDaemon();
-    stopDaemon();
-    reactiveDaemon();
-  }
-
-  private static void createAllDir() {
-    createDir(ConfigNodeConstant.CONF_DIR);
-    createDir(ConfigNodeConstant.DATA_DIR);
-  }
-
-  private static void createDir(String dir) {
-    File file = new File(dir);
-    if (!file.mkdirs()) {
-      LOGGER.error("ConfigNodeEnvironmentUtils can't mkdir {}.", dir);
-    }
-  }
-
-  private static void cleanAllDir() {
-    cleanDir(ConfigNodeConstant.CONF_DIR);
-    cleanDir(ConfigNodeConstant.DATA_DIR);
-  }
-
-  public static void cleanDir(String dir) {
-    try {
-      FileUtils.deleteDirectory(new File(dir));
-    } catch (IOException e) {
-      LOGGER.error("ConfigNodeEnvironmentUtils can't remove dir {}.", dir, e);
-    }
-  }
-}
diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/partition/DataPartition.java b/node-commons/src/main/java/org/apache/iotdb/commons/partition/DataPartition.java
index 8c150d0ba4..df98015fb6 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/partition/DataPartition.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/partition/DataPartition.java
@@ -22,6 +22,7 @@ import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
 import org.apache.iotdb.common.rpc.thrift.TSeriesPartitionSlot;
 import org.apache.iotdb.common.rpc.thrift.TTimePartitionSlot;
 
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -231,4 +232,12 @@ public class DataPartition extends Partition {
         .computeIfAbsent(seriesPartitionSlot, key -> new HashMap<>())
         .put(timePartitionSlot, Collections.singletonList(regionReplicaSet));
   }
+
+  public void serialize(ByteBuffer buffer) {
+    // TODO: Serialize DataPartition
+  }
+
+  public void deserialize(ByteBuffer buffer) {
+    // TODO: Deserialize DataPartition
+  }
 }
diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/partition/SchemaPartition.java b/node-commons/src/main/java/org/apache/iotdb/commons/partition/SchemaPartition.java
index 2c8e415199..586c380e54 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/partition/SchemaPartition.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/partition/SchemaPartition.java
@@ -21,6 +21,7 @@ package org.apache.iotdb.commons.partition;
 import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
 import org.apache.iotdb.common.rpc.thrift.TSeriesPartitionSlot;
 
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -156,4 +157,12 @@ public class SchemaPartition extends Partition {
         .computeIfAbsent(storageGroup, key -> new HashMap<>())
         .put(seriesPartitionSlot, regionReplicaSet);
   }
+
+  public void serialize(ByteBuffer buffer) {
+    // TODO: Serialize SchemaPartition
+  }
+
+  public void deserialize(ByteBuffer buffer) {
+    // TODO: Deserialize DataPartition
+  }
 }