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

caogaofei 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 402e269d65 [IOTDB-5326] Add cluster_name parameter (#8708)
402e269d65 is described below

commit 402e269d650c4f1a641fe43c90efb0d849f5bed8
Author: YongzaoDan <[email protected]>
AuthorDate: Tue Jan 3 23:23:16 2023 +0800

    [IOTDB-5326] Add cluster_name parameter (#8708)
---
 .../confignode/conf/ConfigNodeDescriptor.java      |  3 ++
 .../consensus/response/DataNodeRegisterResp.java   |  7 ---
 .../iotdb/confignode/manager/ConfigManager.java    | 18 ++++---
 .../apache/iotdb/confignode/manager/IManager.java  |  4 +-
 .../manager/node/ClusterNodeStartUtils.java        | 25 ++++++++-
 .../iotdb/confignode/manager/node/NodeManager.java |  2 -
 .../iotdb/confignode/service/ConfigNode.java       | 16 +++---
 .../thrift/ConfigNodeRPCServiceProcessor.java      |  9 ++--
 docs/UserGuide/Cluster/Cluster-Setup.md            | 60 +++++++++++++++++-----
 docs/zh/UserGuide/Cluster/Cluster-Setup.md         | 42 ++++++++++++---
 .../apache/iotdb/it/env/AbstractNodeWrapper.java   |  2 +-
 .../it/cluster/IoTDBClusterNodeErrorStartUpIT.java | 35 +++++++++++++
 .../confignode/it/utils/ConfigNodeTestUtils.java   |  3 +-
 .../resources/conf/iotdb-common.properties         |  8 +++
 .../org/apache/iotdb/db/conf/IoTDBDescriptor.java  |  3 ++
 .../java/org/apache/iotdb/db/service/DataNode.java | 10 ++--
 .../src/main/thrift/confignode.thrift              | 31 +++++++----
 17 files changed, 208 insertions(+), 70 deletions(-)

diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java
index c78f69cb39..63d30fc6cd 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java
@@ -143,6 +143,9 @@ public class ConfigNodeDescriptor {
   }
 
   private void loadProperties(Properties properties) throws 
BadNodeUrlException, IOException {
+    conf.setClusterName(
+        properties.getProperty(IoTDBConstant.CLUSTER_NAME, 
conf.getClusterName()).trim());
+
     conf.setInternalAddress(
         properties
             .getProperty(IoTDBConstant.CN_INTERNAL_ADDRESS, 
conf.getInternalAddress())
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/DataNodeRegisterResp.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/DataNodeRegisterResp.java
index e3ab67070c..a6e8d9d713 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/DataNodeRegisterResp.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/DataNodeRegisterResp.java
@@ -35,8 +35,6 @@ public class DataNodeRegisterResp implements DataSet {
 
   private TSStatus status;
   private List<TConfigNodeLocation> configNodeList;
-
-  private String clusterName;
   private Integer dataNodeId;
 
   private TRuntimeConfiguration runtimeConfiguration;
@@ -57,10 +55,6 @@ public class DataNodeRegisterResp implements DataSet {
     this.configNodeList = configNodeList;
   }
 
-  public void setClusterName(String clusterName) {
-    this.clusterName = clusterName;
-  }
-
   public void setDataNodeId(Integer dataNodeId) {
     this.dataNodeId = dataNodeId;
   }
@@ -89,7 +83,6 @@ public class DataNodeRegisterResp implements DataSet {
     resp.setConfigNodeList(configNodeList);
 
     if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
-      resp.setClusterName(clusterName);
       resp.setDataNodeId(dataNodeId);
       resp.setRuntimeConfiguration(runtimeConfiguration);
     }
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 1fb519ea2b..a5ea78ed40 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
@@ -104,6 +104,7 @@ import 
org.apache.iotdb.confignode.rpc.thrift.TCreateFunctionReq;
 import org.apache.iotdb.confignode.rpc.thrift.TCreatePipeReq;
 import org.apache.iotdb.confignode.rpc.thrift.TCreateSchemaTemplateReq;
 import org.apache.iotdb.confignode.rpc.thrift.TCreateTriggerReq;
+import org.apache.iotdb.confignode.rpc.thrift.TDataNodeRegisterReq;
 import org.apache.iotdb.confignode.rpc.thrift.TDataNodeRestartReq;
 import org.apache.iotdb.confignode.rpc.thrift.TDataNodeRestartResp;
 import org.apache.iotdb.confignode.rpc.thrift.TDataPartitionTableResp;
@@ -291,16 +292,18 @@ public class ConfigManager implements IManager {
   }
 
   @Override
-  public DataSet registerDataNode(RegisterDataNodePlan registerDataNodePlan) {
+  public DataSet registerDataNode(TDataNodeRegisterReq req) {
     TSStatus status = confirmLeader();
     if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
       status =
           ClusterNodeStartUtils.confirmNodeRegistration(
               NodeType.DataNode,
-              registerDataNodePlan.getDataNodeConfiguration().getLocation(),
+              req.getClusterName(),
+              req.getDataNodeConfiguration().getLocation(),
               this);
       if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
-        return nodeManager.registerDataNode(registerDataNodePlan);
+        return nodeManager.registerDataNode(
+            new RegisterDataNodePlan(req.getDataNodeConfiguration()));
       }
     }
 
@@ -833,7 +836,10 @@ public class ConfigManager implements IManager {
       if (status == null) {
         status =
             ClusterNodeStartUtils.confirmNodeRegistration(
-                NodeType.ConfigNode, req.getConfigNodeLocation(), this);
+                NodeType.ConfigNode,
+                req.getClusterParameters().getClusterName(),
+                req.getConfigNodeLocation(),
+                this);
         if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
           return nodeManager.registerConfigNode(req);
         }
@@ -871,10 +877,6 @@ public class ConfigManager implements IManager {
     TSStatus errorStatus = new 
TSStatus(TSStatusCode.CONFIGURATION_ERROR.getStatusCode());
     TClusterParameters clusterParameters = req.getClusterParameters();
 
-    if (!clusterParameters.getClusterName().equals(CONF.getClusterName())) {
-      return errorStatus.setMessage(errorPrefix + "cluster_name" + 
errorSuffix);
-    }
-
     if (!clusterParameters
         .getConfigNodeConsensusProtocolClass()
         .equals(CONF.getConfigNodeConsensusProtocolClass())) {
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/manager/IManager.java 
b/confignode/src/main/java/org/apache/iotdb/confignode/manager/IManager.java
index ced0ecc058..c6d38aab6d 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/manager/IManager.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/manager/IManager.java
@@ -34,7 +34,6 @@ import 
org.apache.iotdb.confignode.consensus.request.read.region.GetRegionInfoLi
 import 
org.apache.iotdb.confignode.consensus.request.read.storagegroup.CountStorageGroupPlan;
 import 
org.apache.iotdb.confignode.consensus.request.read.storagegroup.GetStorageGroupPlan;
 import 
org.apache.iotdb.confignode.consensus.request.write.confignode.RemoveConfigNodePlan;
-import 
org.apache.iotdb.confignode.consensus.request.write.datanode.RegisterDataNodePlan;
 import 
org.apache.iotdb.confignode.consensus.request.write.datanode.RemoveDataNodePlan;
 import 
org.apache.iotdb.confignode.consensus.request.write.datanode.UpdateDataNodePlan;
 import 
org.apache.iotdb.confignode.consensus.request.write.storagegroup.SetDataReplicationFactorPlan;
@@ -56,6 +55,7 @@ import 
org.apache.iotdb.confignode.rpc.thrift.TCreateFunctionReq;
 import org.apache.iotdb.confignode.rpc.thrift.TCreatePipeReq;
 import org.apache.iotdb.confignode.rpc.thrift.TCreateSchemaTemplateReq;
 import org.apache.iotdb.confignode.rpc.thrift.TCreateTriggerReq;
+import org.apache.iotdb.confignode.rpc.thrift.TDataNodeRegisterReq;
 import org.apache.iotdb.confignode.rpc.thrift.TDataNodeRestartReq;
 import org.apache.iotdb.confignode.rpc.thrift.TDataNodeRestartResp;
 import org.apache.iotdb.confignode.rpc.thrift.TDataPartitionTableResp;
@@ -196,7 +196,7 @@ public interface IManager {
    *
    * @return DataNodeConfigurationDataSet
    */
-  DataSet registerDataNode(RegisterDataNodePlan registerDataNodePlan);
+  DataSet registerDataNode(TDataNodeRegisterReq req);
 
   /**
    * Restart DataNode
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/ClusterNodeStartUtils.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/ClusterNodeStartUtils.java
index fde4479c4b..d1a118a9f2 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/ClusterNodeStartUtils.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/ClusterNodeStartUtils.java
@@ -52,7 +52,7 @@ public class ClusterNodeStartUtils {
       new 
TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()).setMessage("Accept Node 
restart.");
 
   public static TSStatus confirmNodeRegistration(
-      NodeType nodeType, Object nodeLocation, ConfigManager configManager) {
+      NodeType nodeType, String clusterName, Object nodeLocation, 
ConfigManager configManager) {
 
     final String CONF_FILE_NAME =
         NodeType.ConfigNode.equals(nodeType)
@@ -60,6 +60,25 @@ public class ClusterNodeStartUtils {
             : IoTDBConstant.DATA_NODE_CONF_FILE_NAME;
     TSStatus status = new TSStatus();
 
+    /* Reject start if the cluster name is error */
+    if (!CLUSTER_NAME.equals(clusterName)) {
+      status.setCode(TSStatusCode.REJECT_NODE_START.getStatusCode());
+      status.setMessage(
+          String.format(
+              "Reject %s start. Because the ClusterName of the current %s and 
the target cluster are inconsistent. "
+                  + "ClusterName of the current Node: %s, ClusterName of the 
target cluster: %s."
+                  + POSSIBLE_SOLUTIONS
+                  + "\t1. Change the target_config_node_list parameter in %s 
to join the correct cluster."
+                  + "\n\t2. Change the cluster_name parameter in %s to match 
the target cluster",
+              nodeType.getNodeType(),
+              nodeType.getNodeType(),
+              clusterName,
+              CLUSTER_NAME,
+              CONF_FILE_NAME,
+              CONF_FILE_NAME));
+      return status;
+    }
+
     /* Check if there exist conflict TEndPoints */
     List<TEndPoint> conflictEndPoints;
     switch (nodeType) {
@@ -119,11 +138,13 @@ public class ClusterNodeStartUtils {
               "Reject %s restart. Because the ClusterName of the current %s 
and the target cluster are inconsistent. "
                   + "ClusterName of the current Node: %s, ClusterName of the 
target cluster: %s."
                   + POSSIBLE_SOLUTIONS
-                  + "\t1. Change the target_config_node_list parameter in %s 
to join the correct cluster.",
+                  + "\t1. Change the target_config_node_list parameter in %s 
to join the correct cluster."
+                  + "\n\t2. Change the cluster_name parameter in %s to match 
the target cluster",
               nodeType.getNodeType(),
               nodeType.getNodeType(),
               clusterName,
               CLUSTER_NAME,
+              CONF_FILE_NAME,
               CONF_FILE_NAME));
       return status;
     }
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/NodeManager.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/NodeManager.java
index 577044e63e..866ceeab96 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/NodeManager.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/NodeManager.java
@@ -270,7 +270,6 @@ public class NodeManager {
 
     resp.setStatus(ClusterNodeStartUtils.ACCEPT_NODE_REGISTRATION);
     resp.setConfigNodeList(getRegisteredConfigNodes());
-    resp.setClusterName(CONF.getClusterName());
     resp.setDataNodeId(
         
registerDataNodePlan.getDataNodeConfiguration().getLocation().getDataNodeId());
     resp.setRuntimeConfiguration(getRuntimeConfiguration());
@@ -384,7 +383,6 @@ public class NodeManager {
     configManager.getProcedureManager().addConfigNode(req);
     return new TConfigNodeRegisterResp()
         .setStatus(ClusterNodeStartUtils.ACCEPT_NODE_REGISTRATION)
-        .setClusterName(CONF.getClusterName())
         .setConfigNodeId(nodeId);
   }
 
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 397ede2a01..a1f76fae76 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
@@ -95,7 +95,7 @@ public class ConfigNode implements ConfigNodeMBean {
       if (SystemPropertiesUtils.isRestarted()) {
         LOGGER.info("{} is in restarting process...", 
ConfigNodeConstant.GLOBAL_NAME);
 
-        /* Always restore ClusterId and ConfigNodeId first */
+        /* Always restore ClusterName and ConfigNodeId first */
         
CONF.setClusterName(SystemPropertiesUtils.loadClusterNameWhenRestarted());
         
CONF.setConfigNodeId(SystemPropertiesUtils.loadConfigNodeIdWhenRestarted());
 
@@ -107,8 +107,9 @@ public class ConfigNode implements ConfigNodeMBean {
         configManager.initConsensusManager();
         setUpRPCService();
         LOGGER.info(
-            "{} has successfully restarted and joined the cluster.",
-            ConfigNodeConstant.GLOBAL_NAME);
+            "{} has successfully restarted and joined the cluster: {}.",
+            ConfigNodeConstant.GLOBAL_NAME,
+            CONF.getClusterName());
         return;
       }
 
@@ -140,7 +141,9 @@ public class ConfigNode implements ConfigNodeMBean {
         // The initial startup of Seed-ConfigNode finished
 
         LOGGER.info(
-            "{} has successfully started and joined the cluster.", 
ConfigNodeConstant.GLOBAL_NAME);
+            "{} has successfully started and joined the cluster: {}.",
+            ConfigNodeConstant.GLOBAL_NAME,
+            CONF.getClusterName());
         return;
       }
 
@@ -152,9 +155,10 @@ public class ConfigNode implements ConfigNodeMBean {
       // The initial startup of Non-Seed-ConfigNode is not yet finished,
       // we should wait for leader's scheduling
       LOGGER.info(
-          "{} {} has registered successfully. Waiting for the leader's 
scheduling to join the cluster.",
+          "{} {} has registered successfully. Waiting for the leader's 
scheduling to join the cluster: {}.",
           ConfigNodeConstant.GLOBAL_NAME,
-          CONF.getConfigNodeId());
+          CONF.getConfigNodeId(),
+          CONF.getClusterName());
 
       boolean isJoinedCluster = false;
       for (int retry = 0; retry < SCHEDULE_WAITING_RETRY_NUM; retry++) {
diff --git 
a/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
 
b/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
index db3d6aaf25..f2973db275 100644
--- 
a/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
+++ 
b/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
@@ -44,7 +44,6 @@ import 
org.apache.iotdb.confignode.consensus.request.read.region.GetRegionInfoLi
 import 
org.apache.iotdb.confignode.consensus.request.read.storagegroup.CountStorageGroupPlan;
 import 
org.apache.iotdb.confignode.consensus.request.read.storagegroup.GetStorageGroupPlan;
 import 
org.apache.iotdb.confignode.consensus.request.write.confignode.RemoveConfigNodePlan;
-import 
org.apache.iotdb.confignode.consensus.request.write.datanode.RegisterDataNodePlan;
 import 
org.apache.iotdb.confignode.consensus.request.write.datanode.RemoveDataNodePlan;
 import 
org.apache.iotdb.confignode.consensus.request.write.datanode.UpdateDataNodePlan;
 import 
org.apache.iotdb.confignode.consensus.request.write.storagegroup.SetDataReplicationFactorPlan;
@@ -202,9 +201,7 @@ public class ConfigNodeRPCServiceProcessor implements 
IConfigNodeRPCService.Ifac
   @Override
   public TDataNodeRegisterResp registerDataNode(TDataNodeRegisterReq req) {
     TDataNodeRegisterResp resp =
-        ((DataNodeRegisterResp)
-                configManager.registerDataNode(
-                    new RegisterDataNodePlan(req.getDataNodeConfiguration())))
+        ((DataNodeRegisterResp) configManager.registerDataNode(req))
             .convertToRpcDataNodeRegisterResp();
 
     // Print log to record the ConfigNode that performs the 
RegisterDatanodeRequest
@@ -488,7 +485,9 @@ public class ConfigNodeRPCServiceProcessor implements 
IConfigNodeRPCService.Ifac
 
     // The initial startup of Non-Seed-ConfigNode finished
     LOGGER.info(
-        "{} has successfully started and joined the cluster.", 
ConfigNodeConstant.GLOBAL_NAME);
+        "{} has successfully started and joined the cluster: {}.",
+        ConfigNodeConstant.GLOBAL_NAME,
+        ConfigNodeDescriptor.getInstance().getConf().getClusterName());
     return StatusUtils.OK;
   }
 
diff --git a/docs/UserGuide/Cluster/Cluster-Setup.md 
b/docs/UserGuide/Cluster/Cluster-Setup.md
index ddbb400067..01e8cd53d0 100644
--- a/docs/UserGuide/Cluster/Cluster-Setup.md
+++ b/docs/UserGuide/Cluster/Cluster-Setup.md
@@ -113,6 +113,7 @@ and set the following parameters base on the
 
 | **Configuration**                          | **Description**                 
                                                                                
   | **Default**                                     |
 
|--------------------------------------------|--------------------------------------------------------------------------------------------------------------------|-------------------------------------------------|
+| cluster\_name                              | Cluster name for which the Node 
to join in                                                                      
   | defaultCluster                                  |
 | config\_node\_consensus\_protocol\_class   | Consensus protocol of 
ConfigNode                                                                      
             | org.apache.iotdb.consensus.ratis.RatisConsensus |
 | schema\_replication\_factor                | Schema replication factor, no 
more than DataNode number                                                       
     | 1                                               |
 | schema\_region\_consensus\_protocol\_class | Consensus protocol of schema 
replicas                                                                        
      | org.apache.iotdb.consensus.ratis.RatisConsensus |
@@ -140,16 +141,16 @@ and set the following parameters based on the IP address 
and available port of t
 Open the DataNode configuration file ./conf/iotdb-datanode.properties,
 and set the following parameters based on the IP address and available port of 
the server or VM:
 
-| **Configuration**                   | **Description**                        
          | **Default**     | **Usage**                                         
                                                                                
    |
-|-------------------------------------|--------------------------------------------------|-----------------|---------------------------------------------------------------------------------------------------------------------------------------|
-| dn\_rpc\_address                    | Client RPC Service address             
          | 127.0.0.1       | Set to the IPV4 address or domain name of the 
server                                                                          
        |
-| dn\_rpc\_port                       | Client RPC Service port                
          | 6667            | Set to any unoccupied port                        
                                                                                
    |
-| dn\_internal\_address               | Control flow address of DataNode 
inside cluster  | 127.0.0.1       | Set to the IPV4 address or domain name of 
the server                                                                      
            |
-| dn\_internal\_port                  | Control flow port of DataNode inside 
cluster     | 10730            | Set to any unoccupied port                     
                                                                                
       |
-| dn\_mpp\_data\_exchange\_port       | Data flow port of DataNode inside 
cluster        | 10740            | Set to any unoccupied port                  
                                                                                
          |
-| dn\_data\_region\_consensus\_port   | Data replicas communication port for 
consensus   | 10750           | Set to any unoccupied port                      
                                                                                
      |
-| dn\_schema\_region\_consensus\_port | Schema replicas communication port for 
consensus | 10760           | Set to any unoccupied port                        
                                                                                
    |
-| dn\_target\_config\_node\_list      | Running ConfigNode of the Cluster      
          | 127.0.0.1:10710 | Set to any running ConfigNode's 
cn\_internal\_address:cn\_internal\_port. You can set multiple values, separate 
them with commas(",") |
+| **Configuration**                   | **Description**                        
                | **Default**     | **Usage**                                   
                                                                                
          |
+|-------------------------------------|--------------------------------------------------------|-----------------|---------------------------------------------------------------------------------------------------------------------------------------|
+| dn\_rpc\_address                    | Client RPC Service address             
                | 127.0.0.1       | Set to the IPV4 address or domain name of 
the server                                                                      
            |
+| dn\_rpc\_port                       | Client RPC Service port                
                | 6667            | Set to any unoccupied port                  
                                                                                
          |
+| dn\_internal\_address               | Control flow address of DataNode 
inside cluster        | 127.0.0.1       | Set to the IPV4 address or domain 
name of the server                                                              
                    |
+| dn\_internal\_port                  | Control flow port of DataNode inside 
cluster           | 10730           | Set to any unoccupied port                
                                                                                
            |
+| dn\_mpp\_data\_exchange\_port       | Data flow port of DataNode inside 
cluster              | 10740           | Set to any unoccupied port             
                                                                                
               |
+| dn\_data\_region\_consensus\_port   | Data replicas communication port for 
consensus         | 10750           | Set to any unoccupied port                
                                                                                
            |
+| dn\_schema\_region\_consensus\_port | Schema replicas communication port for 
consensus       | 10760           | Set to any unoccupied port                  
                                                                                
          |
+| dn\_target\_config\_node\_list      | Running ConfigNode of the Cluster      
                | 127.0.0.1:10710 | Set to any running ConfigNode's 
cn\_internal\_address:cn\_internal\_port. You can set multiple values, separate 
them with commas(",") |
 
 **Notice: The preceding configuration parameters cannot be changed after the 
node is started. Ensure that all ports are not occupied. Otherwise, the Node 
cannot be started.**
 
@@ -172,7 +173,21 @@ The total process are three steps:
 **The first Node started in the cluster must be ConfigNode. The first started 
ConfigNode must follow the tutorial in this section.**
 
 The first ConfigNode to start is the Seed-ConfigNode, which marks the creation 
of the new cluster.
-Before start the Seed-ConfigNode, please open its configuration file 
./conf/iotdb-confignode.properties and check the following parameters:
+Before start the Seed-ConfigNode, please open the common configuration file 
./conf/iotdb-common.properties and check the following parameters:
+
+| **Configuration**                          | **Check**                       
                |
+|--------------------------------------------|-------------------------------------------------|
+| cluster\_name                              | Is set to the expected name     
                |
+| config\_node\_consensus\_protocol\_class   | Is set to the expected 
consensus protocol       |
+| schema\_replication\_factor                | Is set to the expected schema 
replication count |
+| schema\_region\_consensus\_protocol\_class | Is set to the expected 
consensus protocol       |
+| data\_replication\_factor                  | Is set to the expected data 
replication count   |
+| data\_region\_consensus\_protocol\_class   | Is set to the expected 
consensus protocol       |
+
+**Notice:** Please set these parameters carefully based on the [Deployment 
Recommendation](https://iotdb.apache.org/UserGuide/Master/Cluster/Deployment-Recommendation.html).
+These parameters are not modifiable after the Node first startup.
+
+Then open its configuration file ./conf/iotdb-confignode.properties and check 
the following parameters:
 
 | **Configuration**              | **Check**                                   
                                                        |
 
|--------------------------------|-----------------------------------------------------------------------------------------------------|
@@ -206,8 +221,18 @@ A common configuration is to add extra two ConfigNodes to 
make the cluster has t
 
 Ensure that all configuration parameters in the ./conf/iotdb-common.properites 
are the same as those in the Seed-ConfigNode; 
 otherwise, it may fail to start or generate runtime errors.
+Therefore, please check the following parameters in common configuration file:
+
+| **Configuration**                          | **Check**                       
       |
+|--------------------------------------------|----------------------------------------|
+| cluster\_name                              | Is consistent with the 
Seed-ConfigNode |
+| config\_node\_consensus\_protocol\_class   | Is consistent with the 
Seed-ConfigNode |
+| schema\_replication\_factor                | Is consistent with the 
Seed-ConfigNode |
+| schema\_region\_consensus\_protocol\_class | Is consistent with the 
Seed-ConfigNode |
+| data\_replication\_factor                  | Is consistent with the 
Seed-ConfigNode |
+| data\_region\_consensus\_protocol\_class   | Is consistent with the 
Seed-ConfigNode |
 
-Before start the new ConfigNode, please open its configuration file 
./conf/iotdb-confignode.properties and check the following parameters:
+Then, please open its configuration file ./conf/iotdb-confignode.properties 
and check the following parameters:
 
 | **Configuration**              | **Check**                                   
                                                                                
                           |
 
|--------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|
@@ -237,8 +262,15 @@ For more details about other configuration parameters of 
ConfigNode, see the
 **Before adding DataNodes, ensure that there exists at least one ConfigNode is 
running in the cluster.**
 
 You can add any number of DataNodes to the cluster.
-Before adding a new DataNode, please
-open its configuration file ./conf/iotdb-datanode.properties and check the 
following parameters:
+Before adding a new DataNode, 
+
+please open its common configuration file ./conf/iotdb-common.properties and 
check the following parameters:
+
+| **Configuration**                          | **Check**                       
       |
+|--------------------------------------------|----------------------------------------|
+| cluster\_name                              | Is consistent with the 
Seed-ConfigNode |
+
+Then open its configuration file ./conf/iotdb-datanode.properties and check 
the following parameters:
 
 | **Configuration**                   | **Check**                              
                                                                                
                              |
 
|-------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
diff --git a/docs/zh/UserGuide/Cluster/Cluster-Setup.md 
b/docs/zh/UserGuide/Cluster/Cluster-Setup.md
index e8257e54fc..2637f80854 100644
--- a/docs/zh/UserGuide/Cluster/Cluster-Setup.md
+++ b/docs/zh/UserGuide/Cluster/Cluster-Setup.md
@@ -111,6 +111,7 @@ mvn clean package -pl distribution -am -DskipTests
 
 | **配置项**                                    | **说明**                          
       | **默认**                                          |
 
|--------------------------------------------|----------------------------------------|-------------------------------------------------|
+| cluster\_name                              | 节点希望加入的集群的名称                    
       | defaultCluster                                  |
 | config\_node\_consensus\_protocol\_class   | ConfigNode 使用的共识协议              
       | org.apache.iotdb.consensus.ratis.RatisConsensus |
 | schema\_replication\_factor                | 元数据副本数,DataNode 数量不应少于此数目       
       | 1                                               |
 | schema\_region\_consensus\_protocol\_class | 元数据副本组的共识协议                     
       | org.apache.iotdb.consensus.ratis.RatisConsensus |
@@ -141,8 +142,8 @@ mvn clean package -pl distribution -am -DskipTests
 | dn\_rpc\_address                    | 客户端 RPC 服务的地址             | 127.0.0.1  
     | 设置为服务器的 IPV4 地址或域名                                                       
         |
 | dn\_rpc\_port                       | 客户端 RPC 服务的端口             | 6667       
     | 设置为任意未占用端口                                                               
         |
 | dn\_internal\_address               | DataNode 在集群内部接收控制流使用的地址  | 127.0.0.1  
     | 设置为服务器的 IPV4 地址或域名                                                       
         |
-| dn\_internal\_port                  | DataNode 在集群内部接收控制流使用的端口  | 10730      
      | 设置为任意未占用端口                                                              
          |
-| dn\_mpp\_data\_exchange\_port       | DataNode 在集群内部接收数据流使用的端口  | 10740      
      | 设置为任意未占用端口                                                              
          |
+| dn\_internal\_port                  | DataNode 在集群内部接收控制流使用的端口  | 10730      
     | 设置为任意未占用端口                                                               
         |
+| dn\_mpp\_data\_exchange\_port       | DataNode 在集群内部接收数据流使用的端口  | 10740      
     | 设置为任意未占用端口                                                               
         |
 | dn\_data\_region\_consensus\_port   | DataNode 的数据副本间共识协议通信的端口  | 10750      
     | 设置为任意未占用端口                                                               
         |
 | dn\_schema\_region\_consensus\_port | DataNode 的元数据副本间共识协议通信的端口 | 10760      
     | 设置为任意未占用端口                                                               
         |
 | dn\_target\_config\_node\_list      | 集群中正在运行的 ConfigNode 地址    | 
127.0.0.1:10710 | 设置为任意正在运行的 ConfigNode 的 
cn\_internal\_address:cn\_internal\_port,可设置多个,用逗号(",")隔开 |
@@ -167,7 +168,20 @@ mvn clean package -pl distribution -am -DskipTests
 **集群第一个启动的节点必须是 ConfigNode,第一个启动的 ConfigNode 必须遵循本小节教程。**
 
 第一个启动的 ConfigNode 是 Seed-ConfigNode,标志着新集群的创建。
-在启动 Seed-ConfigNode 前,请打开它的配置文件 ./conf/iotdb-confignode.properties,并检查如下参数:
+在启动 Seed-ConfigNode 前,请打开通用配置文件 ./conf/iotdb-common.properties,并检查如下参数:
+
+| **配置项**                                    | **检查**        |
+|--------------------------------------------|---------------|
+| cluster\_name                              | 已设置为期望的集群名称   |
+| config\_node\_consensus\_protocol\_class   | 已设置为期望的共识协议   |
+| schema\_replication\_factor                | 已设置为期望的元数据副本数 |
+| schema\_region\_consensus\_protocol\_class | 已设置为期望的共识协议   |
+| data\_replication\_factor                  | 已设置为期望的数据副本数  |
+| data\_region\_consensus\_protocol\_class   | 已设置为期望的共识协议   |
+
+**注意:** 
请根据[部署推荐](https://iotdb.apache.org/zh/UserGuide/Master/Cluster/Deployment-Recommendation.html)配置合适的通用参数,这些参数在首次配置后即不可修改。
+
+接着请打开它的配置文件 ./conf/iotdb-confignode.properties,并检查如下参数:
 
 | **配置项**                        | **检查**                                      
             |
 
|--------------------------------|----------------------------------------------------------|
@@ -198,9 +212,19 @@ ConfigNode 的其它配置参数可参考
 
 可向集群添加更多 ConfigNode,以保证 ConfigNode 的高可用。常用的配置为额外增加两个 ConfigNode,使集群共有三个 
ConfigNode。
 
-新增的 ConfigNode 需要保证 ./conf/iotdb-common.properites 中的所有配置参数与种子 ConfigNode 
完全一致,否则可能启动失败或产生运行时错误。
+新增的 ConfigNode 需要保证 ./conf/iotdb-common.properites 中的所有配置参数与 Seed-ConfigNode 
完全一致,否则可能启动失败或产生运行时错误。
+因此,请着重检查通用配置文件中的以下参数:
 
-在增加一个新的 ConfigNode 之前,请打开它的配置文件 ./conf/iotdb-confignode.properties,并检查以下参数:
+| **配置项**                                    | **检查**                 |
+|--------------------------------------------|------------------------|
+| cluster\_name                              | 与 Seed-ConfigNode 保持一致 |
+| config\_node\_consensus\_protocol\_class   | 与 Seed-ConfigNode 保持一致 |
+| schema\_replication\_factor                | 与 Seed-ConfigNode 保持一致 |
+| schema\_region\_consensus\_protocol\_class | 与 Seed-ConfigNode 保持一致 |
+| data\_replication\_factor                  | 与 Seed-ConfigNode 保持一致 |
+| data\_region\_consensus\_protocol\_class   | 与 Seed-ConfigNode 保持一致 |
+
+接着请打开它的配置文件 ./conf/iotdb-confignode.properties,并检查以下参数:
 
 | **配置项**                        | **检查**                                      
                 |
 
|--------------------------------|--------------------------------------------------------------|
@@ -230,7 +254,13 @@ ConfigNode 的其它配置参数可参考
 **确保集群已有正在运行的 ConfigNode 后,才能开始增加 DataNode。**
 
 可以向集群中添加任意个 DataNode。
-在添加新的 DataNode 前,请打开它的配置文件 ./conf/iotdb-datanode.properties 并检查以下参数:
+在添加新的 DataNode 前,请先打开通用配置文件 ./conf/iotdb-common.properties 并检查以下参数:
+
+| **配置项**                                    | **检查**                 |
+|--------------------------------------------|------------------------|
+| cluster\_name                              | 与 Seed-ConfigNode 保持一致 |
+
+接着打开它的配置文件 ./conf/iotdb-datanode.properties 并检查以下参数:
 
 | **配置项**                             | **检查**                                 
                   |
 
|-------------------------------------|-----------------------------------------------------------|
diff --git 
a/integration-test/src/main/java/org/apache/iotdb/it/env/AbstractNodeWrapper.java
 
b/integration-test/src/main/java/org/apache/iotdb/it/env/AbstractNodeWrapper.java
index 9db38c0e40..2ce9384941 100644
--- 
a/integration-test/src/main/java/org/apache/iotdb/it/env/AbstractNodeWrapper.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/it/env/AbstractNodeWrapper.java
@@ -208,7 +208,7 @@ public abstract class AbstractNodeWrapper implements 
BaseNodeWrapper {
 
   @Override
   public void waitingToShutDown() {
-    while (this.instance.isAlive()) {
+    while (this.instance != null && this.instance.isAlive()) {
       try {
         Thread.sleep(100);
       } catch (InterruptedException e) {
diff --git 
a/integration-test/src/test/java/org/apache/iotdb/confignode/it/cluster/IoTDBClusterNodeErrorStartUpIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/confignode/it/cluster/IoTDBClusterNodeErrorStartUpIT.java
index d331af6226..369f676d8e 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/confignode/it/cluster/IoTDBClusterNodeErrorStartUpIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/confignode/it/cluster/IoTDBClusterNodeErrorStartUpIT.java
@@ -92,6 +92,41 @@ public class IoTDBClusterNodeErrorStartUpIT {
     
CONF.setConfigNodeConsesusProtocolClass(originalConfigNodeConsensusProtocolClass);
   }
 
+  @Test
+  public void testIllegalNodeRegistration()
+      throws ClientManagerException, IOException, InterruptedException, 
TException {
+    ConfigNodeWrapper configNodeWrapper = 
EnvFactory.getEnv().generateRandomConfigNodeWrapper();
+    DataNodeWrapper dataNodeWrapper = 
EnvFactory.getEnv().generateRandomDataNodeWrapper();
+
+    try (SyncConfigNodeIServiceClient client =
+        (SyncConfigNodeIServiceClient) 
EnvFactory.getEnv().getLeaderConfigNodeConnection()) {
+      /* Register with error cluster name */
+      TConfigNodeRegisterReq configNodeRegisterReq =
+          
ConfigNodeTestUtils.generateTConfigNodeRegisterReq(configNodeWrapper);
+      
configNodeRegisterReq.getClusterParameters().setClusterName(ERROR_CLUSTER_NAME);
+      configNodeRegisterReq
+          .getClusterParameters()
+          .setConfigNodeConsensusProtocolClass(testConsensusProtocolClass);
+      TConfigNodeRegisterResp configNodeRegisterResp =
+          client.registerConfigNode(configNodeRegisterReq);
+      Assert.assertEquals(
+          TSStatusCode.REJECT_NODE_START.getStatusCode(),
+          configNodeRegisterResp.getStatus().getCode());
+      Assert.assertTrue(
+          configNodeRegisterResp.getStatus().getMessage().contains("cluster 
are inconsistent"));
+
+      TDataNodeRegisterReq dataNodeRegisterReq =
+          ConfigNodeTestUtils.generateTDataNodeRegisterReq(dataNodeWrapper);
+      dataNodeRegisterReq.setClusterName(ERROR_CLUSTER_NAME);
+      TDataNodeRegisterResp dataNodeRegisterResp = 
client.registerDataNode(dataNodeRegisterReq);
+      Assert.assertEquals(
+          TSStatusCode.REJECT_NODE_START.getStatusCode(),
+          dataNodeRegisterResp.getStatus().getCode());
+      Assert.assertTrue(
+          dataNodeRegisterResp.getStatus().getMessage().contains("cluster are 
inconsistent"));
+    }
+  }
+
   @Test
   public void testConflictNodeRegistration()
       throws ClientManagerException, InterruptedException, TException, 
IOException {
diff --git 
a/integration-test/src/test/java/org/apache/iotdb/confignode/it/utils/ConfigNodeTestUtils.java
 
b/integration-test/src/test/java/org/apache/iotdb/confignode/it/utils/ConfigNodeTestUtils.java
index 66376ae959..31ad85822b 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/confignode/it/utils/ConfigNodeTestUtils.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/confignode/it/utils/ConfigNodeTestUtils.java
@@ -276,7 +276,8 @@ public class ConfigNodeTestUtils {
   }
 
   public static TDataNodeRegisterReq 
generateTDataNodeRegisterReq(DataNodeWrapper dataNodeWrapper) {
-    return new TDataNodeRegisterReq(generateTDataNodeConfiguration(-1, 
dataNodeWrapper));
+    return new TDataNodeRegisterReq(
+        generateTDataNodeConfiguration(-1, dataNodeWrapper), 
CONF.getClusterName());
   }
 
   public static TDataNodeRestartReq generateTDataNodeRestartReq(
diff --git a/node-commons/src/assembly/resources/conf/iotdb-common.properties 
b/node-commons/src/assembly/resources/conf/iotdb-common.properties
index 89d357a6b9..ec90b9915b 100644
--- a/node-commons/src/assembly/resources/conf/iotdb-common.properties
+++ b/node-commons/src/assembly/resources/conf/iotdb-common.properties
@@ -16,6 +16,14 @@
 # specific language governing permissions and limitations
 # under the License.
 
+####################
+### Cluster Configuration
+####################
+
+# Used for indicate cluster name and distinguish different cluster.
+# Datatype: string
+cluster_name=defaultCluster
+
 ####################
 ### Replication configuration
 ####################
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java 
b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
index 9bb241d73f..a60d5a0684 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
@@ -199,6 +199,9 @@ public class IoTDBDescriptor {
 
   public void loadProperties(Properties properties) {
 
+    conf.setClusterName(
+        properties.getProperty(IoTDBConstant.CLUSTER_NAME, 
conf.getClusterName()).trim());
+
     conf.setRpcAddress(
         properties.getProperty(IoTDBConstant.DN_RPC_ADDRESS, 
conf.getRpcAddress()).trim());
 
diff --git a/server/src/main/java/org/apache/iotdb/db/service/DataNode.java 
b/server/src/main/java/org/apache/iotdb/db/service/DataNode.java
index 59e85e6ac0..8b9b6f49e8 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/DataNode.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/DataNode.java
@@ -338,6 +338,7 @@ public class DataNode implements DataNodeMBean {
     int retry = DEFAULT_RETRY;
     TDataNodeRegisterReq req = new TDataNodeRegisterReq();
     req.setDataNodeConfiguration(generateDataNodeConfiguration());
+    req.setClusterName(config.getClusterName());
     TDataNodeRegisterResp dataNodeRegisterResp = null;
     while (retry > 0) {
       try (ConfigNodeClient configNodeClient = new ConfigNodeClient()) {
@@ -370,16 +371,15 @@ public class DataNode implements DataNodeMBean {
     if (dataNodeRegisterResp.getStatus().getCode() == 
TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
 
       /* Store runtime configurations when register success */
-      String clusterName = dataNodeRegisterResp.getClusterName();
-      config.setClusterName(dataNodeRegisterResp.getClusterName());
       int dataNodeID = dataNodeRegisterResp.getDataNodeId();
       config.setDataNodeId(dataNodeID);
-      
IoTDBStartCheck.getInstance().serializeClusterNameAndDataNodeId(clusterName, 
dataNodeID);
+      IoTDBStartCheck.getInstance()
+          .serializeClusterNameAndDataNodeId(config.getClusterName(), 
dataNodeID);
 
       storeRuntimeConfigurations(
           dataNodeRegisterResp.getConfigNodeList(), 
dataNodeRegisterResp.getRuntimeConfiguration());
 
-      logger.info("Successfully register to the cluster");
+      logger.info("Successfully register to the cluster: {}", 
config.getClusterName());
     } else {
       /* Throw exception when register failed */
       logger.error(dataNodeRegisterResp.getStatus().getMessage());
@@ -430,7 +430,7 @@ public class DataNode implements DataNodeMBean {
       /* Store runtime configurations when restart request is accepted */
       storeRuntimeConfigurations(
           dataNodeRestartResp.getConfigNodeList(), 
dataNodeRestartResp.getRuntimeConfiguration());
-      logger.info("Restart request is accepted.");
+      logger.info("Restart request to cluster: {} is accepted.", 
config.getClusterName());
     } else {
       /* Throw exception when restart is rejected */
       throw new StartupException(dataNodeRestartResp.getStatus().getMessage());
diff --git a/thrift-confignode/src/main/thrift/confignode.thrift 
b/thrift-confignode/src/main/thrift/confignode.thrift
index 79db50193c..9cdd54d33c 100644
--- a/thrift-confignode/src/main/thrift/confignode.thrift
+++ b/thrift-confignode/src/main/thrift/confignode.thrift
@@ -94,14 +94,14 @@ struct TRuntimeConfiguration {
 
 struct TDataNodeRegisterReq {
   1: required common.TDataNodeConfiguration dataNodeConfiguration
+  2: required string clusterName
 }
 
 struct TDataNodeRegisterResp {
   1: required common.TSStatus status
   2: required list<common.TConfigNodeLocation> configNodeList
-  3: optional string clusterName
-  4: optional i32 dataNodeId
-  5: optional TRuntimeConfiguration runtimeConfiguration
+  3: optional i32 dataNodeId
+  4: optional TRuntimeConfiguration runtimeConfiguration
 }
 
 struct TDataNodeRestartReq {
@@ -354,8 +354,7 @@ struct TConfigNodeRegisterReq {
 
 struct TConfigNodeRegisterResp {
   1: required common.TSStatus status
-  2: optional string clusterName
-  3: optional i32 configNodeId
+  2: optional i32 configNodeId
 }
 
 struct TConfigNodeRestartReq {
@@ -725,14 +724,17 @@ service IConfigNodeRPCService {
    * Register a new DataNode into the cluster
    *
    * @return SUCCESS_STATUS if the new DataNode registered successfully
-   *         DATANODE_ALREADY_REGISTERED if the DataNode already registered
+   *         REJECT_NODE_START if the configuration chek of the DataNode to be 
registered fails,
+   *                           and a detailed error message will be returned.
    */
   TDataNodeRegisterResp registerDataNode(TDataNodeRegisterReq req)
 
   /**
-   * Restart a existed DataNode
+   * Restart an existed DataNode
    *
-   * @return SUCCESS_STATUS if restart DataNode success
+   * @return SUCCESS_STATUS if DataNode restart request is accepted
+   *         REJECT_NODE_START if the configuration chek of the DataNode to be 
restarted fails,
+   *                           and a detailed error message will be returned.
    */
   TDataNodeRestartResp restartDataNode(TDataNodeRestartReq req)
 
@@ -924,9 +926,9 @@ service IConfigNodeRPCService {
   /**
    * The Non-Seed-ConfigNode submit a registration request to the 
ConfigNode-leader when first startup
    *
-   * @return SUCCESS_STATUS if the AddConfigNodeProcedure submitted 
successfully
-   *         ERROR_GLOBAL_CONFIG if some global configurations in the 
Non-Seed-ConfigNode
-   *                             are inconsist with the ConfigNode-leader
+   * @return SUCCESS_STATUS if the AddConfigNodeProcedure submitted 
successfully.
+   *         REJECT_NODE_START if the configuration chek of the ConfigNode to 
be registered fails,
+   *                           and a detailed error message will be returned.
    */
   TConfigNodeRegisterResp registerConfigNode(TConfigNodeRegisterReq req)
 
@@ -936,6 +938,13 @@ service IConfigNodeRPCService {
   /** The ConfigNode-leader will notify the Non-Seed-ConfigNode that the 
registration success */
   common.TSStatus notifyRegisterSuccess()
 
+  /**
+   * Restart an existed ConfigNode
+   *
+   * @return SUCCESS_STATUS if ConfigNode restart request is accepted
+   *         REJECT_NODE_START if the configuration chek of the ConfigNode to 
be restarted fails,
+   *                           and a detailed error message will be returned.
+   */
   common.TSStatus restartConfigNode(TConfigNodeRestartReq req)
 
   /**


Reply via email to