You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "liyuheng55555 (via GitHub)" <gi...@apache.org> on 2024/06/05 08:49:48 UTC

[PR] Verify connection [iotdb]

liyuheng55555 opened a new pull request, #12667:
URL: https://github.com/apache/iotdb/pull/12667

   (no comment)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Verify connection && Refactor async connection framework [iotdb]

Posted by "OneSizeFitsQuorum (via GitHub)" <gi...@apache.org>.
OneSizeFitsQuorum commented on code in PR #12667:
URL: https://github.com/apache/iotdb/pull/12667#discussion_r1637912295


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/client/async/ConfigNodeToConfigNodeInternalServiceAsyncRequestManager.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.client.async;
+
+import org.apache.iotdb.common.rpc.thrift.TConfigNodeLocation;
+import org.apache.iotdb.common.rpc.thrift.TNodeLocations;
+import org.apache.iotdb.commons.client.request.AsyncRequestContext;
+import org.apache.iotdb.commons.client.request.AsyncRequestRPCHandler;
+import org.apache.iotdb.commons.client.request.ConfigNodeInternalServiceAsyncRequestManager;
+import org.apache.iotdb.confignode.client.ConfigNodeToConfigNodeRequestType;
+import org.apache.iotdb.confignode.client.async.handlers.rpc.ConfigNodeAsyncRequestRPCHandler;
+import org.apache.iotdb.confignode.client.async.handlers.rpc.ConfigNodeTSStatusRPCHandler;
+import org.apache.iotdb.confignode.client.async.handlers.rpc.SubmitTestConnectionTaskToConfigNodeRPCHandler;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ConfigNodeToConfigNodeInternalServiceAsyncRequestManager

Review Comment:
   CNToCNInternalServiceAsyncRequestManager



##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/request/AsyncRequestContext.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.commons.client.request;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * Asynchronous Client handler.
+ *
+ * @param <Request> ClassName of RPC request
+ * @param <Response> ClassName of RPC response
+ */
+public class AsyncRequestContext<Request, Response, RequestType, NodeLocation> {
+
+  // Type of RPC request
+  protected final RequestType requestType;
+
+  /**
+   * Map key: The indices of asynchronous RPC requests.
+   *
+   * <p>Map value: The corresponding RPC request
+   */
+  private final Map<Integer, Request> requestMap;
+
+  /**
+   * Map key: The indices of asynchronous RPC requests.
+   *
+   * <p>Map value: The target Nodes of corresponding indices
+   *
+   * <p>All kinds of AsyncHandler will remove its targetNode from the nodeLocationMap only if its
+   * corresponding RPC request success
+   */
+  private final Map<Integer, NodeLocation> nodeLocationMap;
+
+  /**
+   * Map key: The indices(targetNode's ID) of asynchronous RPC requests.
+   *
+   * <p>Map value: The response of corresponding indices
+   *
+   * <p>All kinds of AsyncHandler will add response to the responseMap after its corresponding RPC
+   * request finished
+   */
+  private final Map<Integer, Response> responseMap;
+
+  private CountDownLatch countDownLatch;
+
+  /** Custom constructor. */
+  public AsyncRequestContext(RequestType requestType) {
+    this.requestType = requestType;
+    this.requestMap = new ConcurrentHashMap<>();
+    this.nodeLocationMap = new ConcurrentHashMap<>();
+    this.responseMap = new ConcurrentHashMap<>();
+  }
+
+  public void putRequest(int requestId, Request request) {
+    requestMap.put(requestId, request);
+  }
+
+  public void putNodeLocation(int requestId, NodeLocation nodeLocation) {
+    nodeLocationMap.put(requestId, nodeLocation);
+  }
+
+  /** Constructor for null requests. */
+  public AsyncRequestContext(RequestType requestType, Map<Integer, NodeLocation> nodeLocationMap) {
+    this.requestType = requestType;
+    this.nodeLocationMap = nodeLocationMap;
+

Review Comment:
   remove empty line



##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/request/ConfigNodeInternalServiceAsyncRequestManager.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * 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.commons.client.request;
+
+import org.apache.iotdb.common.rpc.thrift.TConfigNodeLocation;
+import org.apache.iotdb.common.rpc.thrift.TEndPoint;
+import org.apache.iotdb.commons.client.ClientPoolFactory;
+import org.apache.iotdb.commons.client.IClientManager;
+import org.apache.iotdb.commons.client.async.AsyncConfigNodeInternalServiceClient;
+
+public abstract class ConfigNodeInternalServiceAsyncRequestManager<RequestType>

Review Comment:
   CN



##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/request/DataNodeInternalServiceRequestManager.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * 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.commons.client.request;
+
+import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation;
+import org.apache.iotdb.common.rpc.thrift.TEndPoint;
+import org.apache.iotdb.commons.client.ClientPoolFactory;
+import org.apache.iotdb.commons.client.IClientManager;
+import org.apache.iotdb.commons.client.async.AsyncDataNodeInternalServiceClient;
+
+public abstract class DataNodeInternalServiceRequestManager<RequestType>

Review Comment:
   DN



##########
iotdb-protocol/thrift-commons/src/main/thrift/common.thrift:
##########
@@ -191,6 +191,40 @@ struct TLicense {
     9: required i16 mlNodeNumLimit
 }
 
+enum TServiceType {
+  ConfigNodeInternalService,
+  DataNodeInternalService,
+  DataNodeMPPService,
+  DataNodeExternalService,
+}
+
+struct TServiceProvider {
+  1: required TEndPoint endPoint
+  2: required TServiceType serviceType
+}
+
+struct TSender {
+  1: optional TDataNodeLocation dataNodeLocation
+  2: optional TConfigNodeLocation configNodeLocation
+}
+
+struct TTestConnectionResult {
+  1: required TServiceProvider serviceProvider
+  2: required TSender sender
+  3: required bool success
+  4: optional string reason
+}
+
+struct TTestConnectionResp {
+  1: optional TSStatus status

Review Comment:
   check



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ClusterManager.java:
##########
@@ -79,4 +104,195 @@ private void generateClusterId() {
       LOGGER.warn(CONSENSUS_WRITE_ERROR, e);
     }
   }
+
+  public TTestConnectionResp submitTestConnectionTaskToEveryNode() {
+    TTestConnectionResp resp = new TTestConnectionResp();
+    resp.resultList = new ArrayList<>();
+    resp.setStatus(new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()));
+    TNodeLocations nodeLocations = new TNodeLocations();
+    nodeLocations.setConfigNodeLocations(configManager.getNodeManager().getRegisteredConfigNodes());
+    nodeLocations.setDataNodeLocations(
+        configManager.getNodeManager().getRegisteredDataNodes().stream()
+            .map(TDataNodeConfiguration::getLocation)
+            .collect(Collectors.toList()));
+    // For ConfigNode
+    Map<Integer, TConfigNodeLocation> configNodeLocationMap =
+        configManager.getNodeManager().getRegisteredConfigNodes().stream()
+            .collect(Collectors.toMap(TConfigNodeLocation::getConfigNodeId, location -> location));
+    ConfigNodeAsyncRequestContext<TNodeLocations, TTestConnectionResp>
+        configNodeAsyncRequestContext =
+            new ConfigNodeAsyncRequestContext<>(
+                ConfigNodeToConfigNodeRequestType.SUBMIT_TEST_CONNECTION_TASK,
+                nodeLocations,
+                configNodeLocationMap);
+    ConfigNodeToConfigNodeInternalServiceAsyncRequestManager.getInstance()
+        .sendAsyncRequest(configNodeAsyncRequestContext);
+    Map<Integer, TConfigNodeLocation> anotherConfigNodeLocationMap =
+        configManager.getNodeManager().getRegisteredConfigNodes().stream()
+            .collect(Collectors.toMap(TConfigNodeLocation::getConfigNodeId, location -> location));
+    configNodeAsyncRequestContext
+        .getResponseMap()
+        .forEach(
+            (nodeId, configNodeResp) -> {
+              if (configNodeResp.isSetResultList()) {
+                resp.getResultList().addAll(configNodeResp.getResultList());
+              } else {
+                resp.getResultList()
+                    .addAll(
+                        badConfigNodeConnectionResult(
+                            anotherConfigNodeLocationMap.get(nodeId), nodeLocations));
+              }
+            });
+    // For DataNode

Review Comment:
   try to make dn and cn parallel



##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/request/Utils.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.commons.client.request;
+
+import org.apache.iotdb.common.rpc.thrift.TEndPoint;
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.common.rpc.thrift.TSender;
+import org.apache.iotdb.common.rpc.thrift.TServiceProvider;
+import org.apache.iotdb.common.rpc.thrift.TServiceType;
+import org.apache.iotdb.common.rpc.thrift.TTestConnectionResult;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+public class Utils {
+  public static <ServiceProviderLocation, RequestType>
+      List<TTestConnectionResult> testConnectionsImpl(
+          List<ServiceProviderLocation> nodeLocations,
+          TSender sender,
+          Function<ServiceProviderLocation, Integer> getId,
+          Function<ServiceProviderLocation, TEndPoint> getEndPoint,
+          TServiceType serviceType,
+          RequestType requestType,
+          Consumer<AsyncRequestContext<Object, TSStatus, RequestType, ServiceProviderLocation>>
+              sendRequest) {
+    // prepare request context
+    Map<Integer, ServiceProviderLocation> nodeLocationMap =
+        nodeLocations.stream().collect(Collectors.toMap(getId, location -> location));
+    AsyncRequestContext<Object, TSStatus, RequestType, ServiceProviderLocation> requestContext =
+        new AsyncRequestContext<>(requestType, new Object(), nodeLocationMap);

Review Comment:
   check new Object()



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/client/async/ConfigNodeToDataNodeInternalServiceAsyncRequestManager.java:
##########
@@ -0,0 +1,378 @@
+/*
+ * 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.client.async;
+
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupId;
+import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation;
+import org.apache.iotdb.common.rpc.thrift.TFlushReq;
+import org.apache.iotdb.common.rpc.thrift.TNodeLocations;
+import org.apache.iotdb.common.rpc.thrift.TSetConfigurationReq;
+import org.apache.iotdb.common.rpc.thrift.TSetSpaceQuotaReq;
+import org.apache.iotdb.common.rpc.thrift.TSetTTLReq;
+import org.apache.iotdb.common.rpc.thrift.TSetThrottleQuotaReq;
+import org.apache.iotdb.commons.client.request.AsyncRequestContext;
+import org.apache.iotdb.commons.client.request.AsyncRequestRPCHandler;
+import org.apache.iotdb.commons.client.request.DataNodeInternalServiceRequestManager;
+import org.apache.iotdb.confignode.client.ConfigNodeToDataNodeRequestType;
+import org.apache.iotdb.confignode.client.async.handlers.rpc.CheckTimeSeriesExistenceRPCHandler;
+import org.apache.iotdb.confignode.client.async.handlers.rpc.CountPathsUsingTemplateRPCHandler;
+import org.apache.iotdb.confignode.client.async.handlers.rpc.DataNodeAsyncRequestRPCHandler;
+import org.apache.iotdb.confignode.client.async.handlers.rpc.DataNodeTSStatusRPCHandler;
+import org.apache.iotdb.confignode.client.async.handlers.rpc.FetchSchemaBlackListRPCHandler;
+import org.apache.iotdb.confignode.client.async.handlers.rpc.PipeHeartbeatRPCHandler;
+import org.apache.iotdb.confignode.client.async.handlers.rpc.PipePushMetaRPCHandler;
+import org.apache.iotdb.confignode.client.async.handlers.rpc.SchemaUpdateRPCHandler;
+import org.apache.iotdb.confignode.client.async.handlers.rpc.SubmitTestConnectionTaskRPCHandler;
+import org.apache.iotdb.confignode.client.async.handlers.rpc.TransferLeaderRPCHandler;
+import org.apache.iotdb.confignode.client.async.handlers.rpc.subscription.CheckSchemaRegionUsingTemplateRPCHandler;
+import org.apache.iotdb.confignode.client.async.handlers.rpc.subscription.ConsumerGroupPushMetaRPCHandler;
+import org.apache.iotdb.confignode.client.async.handlers.rpc.subscription.TopicPushMetaRPCHandler;
+import org.apache.iotdb.mpp.rpc.thrift.TActiveTriggerInstanceReq;
+import org.apache.iotdb.mpp.rpc.thrift.TAlterViewReq;
+import org.apache.iotdb.mpp.rpc.thrift.TCheckSchemaRegionUsingTemplateReq;
+import org.apache.iotdb.mpp.rpc.thrift.TCheckTimeSeriesExistenceReq;
+import org.apache.iotdb.mpp.rpc.thrift.TConstructSchemaBlackListReq;
+import org.apache.iotdb.mpp.rpc.thrift.TConstructSchemaBlackListWithTemplateReq;
+import org.apache.iotdb.mpp.rpc.thrift.TConstructViewSchemaBlackListReq;
+import org.apache.iotdb.mpp.rpc.thrift.TCountPathsUsingTemplateReq;
+import org.apache.iotdb.mpp.rpc.thrift.TCreateDataRegionReq;
+import org.apache.iotdb.mpp.rpc.thrift.TCreateFunctionInstanceReq;
+import org.apache.iotdb.mpp.rpc.thrift.TCreatePipePluginInstanceReq;
+import org.apache.iotdb.mpp.rpc.thrift.TCreateSchemaRegionReq;
+import org.apache.iotdb.mpp.rpc.thrift.TCreateTriggerInstanceReq;
+import org.apache.iotdb.mpp.rpc.thrift.TDeactivateTemplateReq;
+import org.apache.iotdb.mpp.rpc.thrift.TDeleteDataForDeleteSchemaReq;
+import org.apache.iotdb.mpp.rpc.thrift.TDeleteTimeSeriesReq;
+import org.apache.iotdb.mpp.rpc.thrift.TDeleteViewSchemaReq;
+import org.apache.iotdb.mpp.rpc.thrift.TDropFunctionInstanceReq;
+import org.apache.iotdb.mpp.rpc.thrift.TDropPipePluginInstanceReq;
+import org.apache.iotdb.mpp.rpc.thrift.TDropTriggerInstanceReq;
+import org.apache.iotdb.mpp.rpc.thrift.TFetchSchemaBlackListReq;
+import org.apache.iotdb.mpp.rpc.thrift.TInactiveTriggerInstanceReq;
+import org.apache.iotdb.mpp.rpc.thrift.TInvalidateMatchedSchemaCacheReq;
+import org.apache.iotdb.mpp.rpc.thrift.TPipeHeartbeatReq;
+import org.apache.iotdb.mpp.rpc.thrift.TPushConsumerGroupMetaReq;
+import org.apache.iotdb.mpp.rpc.thrift.TPushMultiPipeMetaReq;
+import org.apache.iotdb.mpp.rpc.thrift.TPushMultiTopicMetaReq;
+import org.apache.iotdb.mpp.rpc.thrift.TPushPipeMetaReq;
+import org.apache.iotdb.mpp.rpc.thrift.TPushSingleConsumerGroupMetaReq;
+import org.apache.iotdb.mpp.rpc.thrift.TPushSinglePipeMetaReq;
+import org.apache.iotdb.mpp.rpc.thrift.TPushSingleTopicMetaReq;
+import org.apache.iotdb.mpp.rpc.thrift.TPushTopicMetaReq;
+import org.apache.iotdb.mpp.rpc.thrift.TRegionLeaderChangeReq;
+import org.apache.iotdb.mpp.rpc.thrift.TRegionRouteReq;
+import org.apache.iotdb.mpp.rpc.thrift.TResetPeerListReq;
+import org.apache.iotdb.mpp.rpc.thrift.TRollbackSchemaBlackListReq;
+import org.apache.iotdb.mpp.rpc.thrift.TRollbackSchemaBlackListWithTemplateReq;
+import org.apache.iotdb.mpp.rpc.thrift.TRollbackViewSchemaBlackListReq;
+import org.apache.iotdb.mpp.rpc.thrift.TUpdateTemplateReq;
+import org.apache.iotdb.mpp.rpc.thrift.TUpdateTriggerLocationReq;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Asynchronously send RPC requests to DataNodes. See queryengine.thrift for more details. */
+public class ConfigNodeToDataNodeInternalServiceAsyncRequestManager

Review Comment:
   CNToDNInternalServiceAsyncRequestManager



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Verify connection && Refactor async connection framework [iotdb]

Posted by "OneSizeFitsQuorum (via GitHub)" <gi...@apache.org>.
OneSizeFitsQuorum merged PR #12667:
URL: https://github.com/apache/iotdb/pull/12667


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Verify connection && Refactor async connection framework [iotdb]

Posted by "liyuheng55555 (via GitHub)" <gi...@apache.org>.
liyuheng55555 commented on code in PR #12667:
URL: https://github.com/apache/iotdb/pull/12667#discussion_r1638027713


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ClusterManager.java:
##########
@@ -79,4 +104,195 @@ private void generateClusterId() {
       LOGGER.warn(CONSENSUS_WRITE_ERROR, e);
     }
   }
+
+  public TTestConnectionResp submitTestConnectionTaskToEveryNode() {
+    TTestConnectionResp resp = new TTestConnectionResp();
+    resp.resultList = new ArrayList<>();
+    resp.setStatus(new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()));
+    TNodeLocations nodeLocations = new TNodeLocations();
+    nodeLocations.setConfigNodeLocations(configManager.getNodeManager().getRegisteredConfigNodes());
+    nodeLocations.setDataNodeLocations(
+        configManager.getNodeManager().getRegisteredDataNodes().stream()
+            .map(TDataNodeConfiguration::getLocation)
+            .collect(Collectors.toList()));
+    // For ConfigNode
+    Map<Integer, TConfigNodeLocation> configNodeLocationMap =
+        configManager.getNodeManager().getRegisteredConfigNodes().stream()
+            .collect(Collectors.toMap(TConfigNodeLocation::getConfigNodeId, location -> location));
+    ConfigNodeAsyncRequestContext<TNodeLocations, TTestConnectionResp>
+        configNodeAsyncRequestContext =
+            new ConfigNodeAsyncRequestContext<>(
+                ConfigNodeToConfigNodeRequestType.SUBMIT_TEST_CONNECTION_TASK,
+                nodeLocations,
+                configNodeLocationMap);
+    ConfigNodeToConfigNodeInternalServiceAsyncRequestManager.getInstance()
+        .sendAsyncRequest(configNodeAsyncRequestContext);
+    Map<Integer, TConfigNodeLocation> anotherConfigNodeLocationMap =
+        configManager.getNodeManager().getRegisteredConfigNodes().stream()
+            .collect(Collectors.toMap(TConfigNodeLocation::getConfigNodeId, location -> location));
+    configNodeAsyncRequestContext
+        .getResponseMap()
+        .forEach(
+            (nodeId, configNodeResp) -> {
+              if (configNodeResp.isSetResultList()) {
+                resp.getResultList().addAll(configNodeResp.getResultList());
+              } else {
+                resp.getResultList()
+                    .addAll(
+                        badConfigNodeConnectionResult(
+                            anotherConfigNodeLocationMap.get(nodeId), nodeLocations));
+              }
+            });
+    // For DataNode

Review Comment:
   seems not very easy



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Verify connection && Refactor async connection framework [iotdb]

Posted by "liyuheng55555 (via GitHub)" <gi...@apache.org>.
liyuheng55555 commented on code in PR #12667:
URL: https://github.com/apache/iotdb/pull/12667#discussion_r1638048470


##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/request/Utils.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.commons.client.request;
+
+import org.apache.iotdb.common.rpc.thrift.TEndPoint;
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.common.rpc.thrift.TSender;
+import org.apache.iotdb.common.rpc.thrift.TServiceProvider;
+import org.apache.iotdb.common.rpc.thrift.TServiceType;
+import org.apache.iotdb.common.rpc.thrift.TTestConnectionResult;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+public class Utils {
+  public static <ServiceProviderLocation, RequestType>
+      List<TTestConnectionResult> testConnectionsImpl(
+          List<ServiceProviderLocation> nodeLocations,
+          TSender sender,
+          Function<ServiceProviderLocation, Integer> getId,
+          Function<ServiceProviderLocation, TEndPoint> getEndPoint,
+          TServiceType serviceType,
+          RequestType requestType,
+          Consumer<AsyncRequestContext<Object, TSStatus, RequestType, ServiceProviderLocation>>
+              sendRequest) {
+    // prepare request context
+    Map<Integer, ServiceProviderLocation> nodeLocationMap =
+        nodeLocations.stream().collect(Collectors.toMap(getId, location -> location));
+    AsyncRequestContext<Object, TSStatus, RequestType, ServiceProviderLocation> requestContext =
+        new AsyncRequestContext<>(requestType, new Object(), nodeLocationMap);

Review Comment:
   cannot



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Verify connection && Refactor async connection framework [iotdb]

Posted by "liyuheng55555 (via GitHub)" <gi...@apache.org>.
liyuheng55555 commented on code in PR #12667:
URL: https://github.com/apache/iotdb/pull/12667#discussion_r1636000528


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/client/cn/AsyncConfigNodeRequestRPCHandler.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.db.protocol.client.cn;
+
+import org.apache.iotdb.common.rpc.thrift.TConfigNodeLocation;
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.client.request.AsyncRequestContext;
+import org.apache.iotdb.commons.client.request.AsyncRequestRPCHandler;
+
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+
+// TODO: ConfigNodeRequestType可抽
+public abstract class AsyncConfigNodeRequestRPCHandler<Response>

Review Comment:
   rename to ConfigNodeAsyncRequestRPCHandler



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/client/cn/AsyncConfigNodeTSStatusRPCHandler.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.db.protocol.client.cn;
+
+import org.apache.iotdb.common.rpc.thrift.TConfigNodeLocation;
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.rpc.RpcUtils;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+
+/** General RPC handler for TSStatus response type. */
+public class AsyncConfigNodeTSStatusRPCHandler extends AsyncConfigNodeRequestRPCHandler<TSStatus> {

Review Comment:
   rename



##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/async/AsyncDataNodeExternalServiceClient.java:
##########


Review Comment:
   maybe extract some code



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/client/dn/AsyncDataNodeRPCHandler.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.db.protocol.client.dn;
+
+import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation;
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.client.request.AsyncRequestContext;
+import org.apache.iotdb.commons.client.request.AsyncRequestRPCHandler;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+
+public abstract class AsyncDataNodeRPCHandler<Response>

Review Comment:
   rename



##########
iotdb-protocol/thrift-datanode/src/main/thrift/client.thrift:
##########
@@ -659,4 +659,10 @@ service IClientRPCService {
   TSBackupConfigurationResp getBackupConfiguration();
 
   TSConnectionInfoResp fetchAllConnectionsInfo();
+
+  /** For other node's call */
+  common.TSStatus testConnection()

Review Comment:
   rename to testConnectionEmptyRPC



##########
iotdb-protocol/thrift-commons/src/main/thrift/common.thrift:
##########


Review Comment:
   move ?



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/schema/SetTTLProcedure.java:
##########
@@ -108,15 +108,16 @@ private void setConfigNodeTTL(ConfigNodeProcedureEnv env) {
   private void updateDataNodeTTL(ConfigNodeProcedureEnv env) {
     Map<Integer, TDataNodeLocation> dataNodeLocationMap =
         env.getConfigManager().getNodeManager().getRegisteredDataNodeLocations();
-    AsyncClientHandler<TSetTTLReq, TSStatus> clientHandler =
-        new AsyncClientHandler<>(
-            DataNodeRequestType.SET_TTL,
+    AsyncDataNodeRequestContext<TSetTTLReq, TSStatus> clientHandler =

Review Comment:
   rename to DataNodeAsyncRequestContext



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Verify connection && Refactor async connection framework [iotdb]

Posted by "OneSizeFitsQuorum (via GitHub)" <gi...@apache.org>.
OneSizeFitsQuorum commented on code in PR #12667:
URL: https://github.com/apache/iotdb/pull/12667#discussion_r1638064371


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ClusterManager.java:
##########
@@ -79,4 +104,191 @@ private void generateClusterId() {
       LOGGER.warn(CONSENSUS_WRITE_ERROR, e);
     }
   }
+
+  public TTestConnectionResp submitTestConnectionTaskToEveryNode() {
+    TTestConnectionResp resp = new TTestConnectionResp();
+    resp.resultList = new ArrayList<>();
+    resp.setStatus(new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()));
+    TNodeLocations nodeLocations = new TNodeLocations();
+    nodeLocations.setConfigNodeLocations(configManager.getNodeManager().getRegisteredConfigNodes());
+    nodeLocations.setDataNodeLocations(
+        configManager.getNodeManager().getRegisteredDataNodes().stream()
+            .map(TDataNodeConfiguration::getLocation)
+            .collect(Collectors.toList()));
+    // For ConfigNode
+    Map<Integer, TConfigNodeLocation> configNodeLocationMap =
+        configManager.getNodeManager().getRegisteredConfigNodes().stream()
+            .collect(Collectors.toMap(TConfigNodeLocation::getConfigNodeId, location -> location));
+    ConfigNodeAsyncRequestContext<TNodeLocations, TTestConnectionResp>
+        configNodeAsyncRequestContext =
+            new ConfigNodeAsyncRequestContext<>(
+                CnToCnNodeRequestType.SUBMIT_TEST_CONNECTION_TASK,
+                nodeLocations,
+                configNodeLocationMap);
+    CnToCnInternalServiceAsyncRequestManager.getInstance()
+        .sendAsyncRequest(configNodeAsyncRequestContext);
+    Map<Integer, TConfigNodeLocation> anotherConfigNodeLocationMap =
+        configManager.getNodeManager().getRegisteredConfigNodes().stream()
+            .collect(Collectors.toMap(TConfigNodeLocation::getConfigNodeId, location -> location));
+    configNodeAsyncRequestContext
+        .getResponseMap()
+        .forEach(
+            (nodeId, configNodeResp) -> {
+              if (configNodeResp.isSetResultList()) {
+                resp.getResultList().addAll(configNodeResp.getResultList());
+              } else {
+                resp.getResultList()
+                    .addAll(
+                        badConfigNodeConnectionResult(
+                            anotherConfigNodeLocationMap.get(nodeId), nodeLocations));
+              }
+            });
+    // For DataNode
+    Map<Integer, TDataNodeLocation> dataNodeLocationMap =
+        configManager.getNodeManager().getRegisteredDataNodes().stream()
+            .map(TDataNodeConfiguration::getLocation)
+            .collect(Collectors.toMap(TDataNodeLocation::getDataNodeId, location -> location));
+    DataNodeAsyncRequestContext<TNodeLocations, TTestConnectionResp> dataNodeAsyncRequestContext =
+        new DataNodeAsyncRequestContext<>(
+            CnToDnRequestType.SUBMIT_TEST_CONNECTION_TASK, nodeLocations, dataNodeLocationMap);
+    CnToDnInternalServiceAsyncRequestManager.getInstance()
+        .sendAsyncRequest(dataNodeAsyncRequestContext);
+    Map<Integer, TDataNodeLocation> anotherDataNodeLocationMap =
+        configManager.getNodeManager().getRegisteredDataNodes().stream()
+            .map(TDataNodeConfiguration::getLocation)
+            .collect(Collectors.toMap(TDataNodeLocation::getDataNodeId, location -> location));
+    dataNodeAsyncRequestContext
+        .getResponseMap()
+        .forEach(
+            (nodeId, dataNodeResp) -> {
+              if (dataNodeResp.isSetResultList()) {
+                resp.getResultList().addAll(dataNodeResp.getResultList());
+              } else {
+                resp.getResultList()
+                    .addAll(
+                        badDataNodeConnectionResult(
+                            anotherDataNodeLocationMap.get(nodeId), nodeLocations));
+              }
+            });
+    return resp;
+  }
+
+  public List<TTestConnectionResult> doConnectionTest(TNodeLocations nodeLocations) {

Review Comment:
   return TTestConnectionResp?



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/sys/TestConnectionTask.java:
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.db.queryengine.plan.execution.config.sys;
+
+import org.apache.iotdb.common.rpc.thrift.TEndPoint;
+import org.apache.iotdb.common.rpc.thrift.TSender;
+import org.apache.iotdb.common.rpc.thrift.TServiceProvider;
+import org.apache.iotdb.common.rpc.thrift.TServiceType;
+import org.apache.iotdb.common.rpc.thrift.TTestConnectionResp;
+import org.apache.iotdb.common.rpc.thrift.TTestConnectionResult;
+import org.apache.iotdb.db.queryengine.common.header.ColumnHeader;
+import org.apache.iotdb.db.queryengine.common.header.ColumnHeaderConstant;
+import org.apache.iotdb.db.queryengine.common.header.DatasetHeaderFactory;
+import org.apache.iotdb.db.queryengine.plan.execution.config.ConfigTaskResult;
+import org.apache.iotdb.db.queryengine.plan.execution.config.IConfigTask;
+import org.apache.iotdb.db.queryengine.plan.execution.config.executor.IConfigTaskExecutor;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import org.apache.tsfile.common.conf.TSFileConfig;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.block.TsBlockBuilder;
+import org.apache.tsfile.utils.Binary;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class TestConnectionTask implements IConfigTask {
+
+  private final boolean needDetails;
+
+  public TestConnectionTask(boolean needDetails) {
+    this.needDetails = needDetails;
+  }
+
+  @Override
+  public ListenableFuture<ConfigTaskResult> execute(IConfigTaskExecutor configTaskExecutor)
+      throws InterruptedException {
+    return configTaskExecutor.testConnection(needDetails);
+  }
+
+  public static void buildTSBlock(
+      TTestConnectionResp resp,
+      int configNodeNum,
+      int dataNodeNum,
+      boolean needDetails,
+      SettableFuture<ConfigTaskResult> future) {
+    sortTestConnectionResp(resp);
+    if (!needDetails) {
+      Map<TServiceType, Integer> expectedNumMap =
+          calculateExpectedResultNum(configNodeNum, dataNodeNum);
+      List<TTestConnectionResult> newResultList = new ArrayList<>();
+      for (int i = 0; i < resp.getResultListSize(); ) {
+        TTestConnectionResult result = resp.getResultList().get(i);
+        final int expectNum = expectedNumMap.get(result.getServiceProvider().getServiceType());
+        final boolean allSameServiceProviderAllUp =
+            resp.getResultList().stream()
+                .skip(i)
+                .limit(expectNum)
+                .allMatch(
+                    result1 ->
+                        result.getServiceProvider().equals(result1.serviceProvider)
+                            && result1.isSuccess());
+        if (allSameServiceProviderAllUp) {
+          TTestConnectionResult allUpResult = new TTestConnectionResult(result);
+          allUpResult.setSender(new TSender());
+          newResultList.add(allUpResult);
+        } else {
+          newResultList.addAll(
+              resp.getResultList().stream()
+                  .skip(i)
+                  .limit(expectNum)
+                  .filter(result1 -> !result1.isSuccess())
+                  .collect(Collectors.toList()));
+        }
+        i += expectNum;
+      }
+      resp.setResultList(newResultList);
+    }
+    List<TSDataType> outputDataTypes =
+        ColumnHeaderConstant.testConnectionColumnHeaders.stream()
+            .map(ColumnHeader::getColumnType)
+            .collect(Collectors.toList());
+    TsBlockBuilder builder = new TsBlockBuilder(outputDataTypes);
+    int serviceProviderMaxLen = calculateServiceProviderMaxLen(resp);
+    int connectionMaxLen = calculateConnectionMaxLen(resp);
+    for (TTestConnectionResult result : resp.getResultList()) {
+      // ServiceProvider column
+      builder.getTimeColumnBuilder().writeLong(0);
+      StringBuilder serviceStr =
+          new StringBuilder(serviceProviderToString(result.getServiceProvider()));
+      while (serviceStr.length() < serviceProviderMaxLen) {
+        serviceStr.append(" ");
+      }
+      builder
+          .getColumnBuilder(0)
+          .writeBinary(new Binary(serviceStr.toString(), TSFileConfig.STRING_CHARSET));
+      // Sender column
+      String senderStr;
+      if (result.getSender().isSetConfigNodeLocation()) {
+        senderStr =
+            endPointToString(result.getSender().getConfigNodeLocation().getInternalEndPoint());
+        senderStr += " (ConfigNode)";
+      } else if (result.getSender().isSetDataNodeLocation()) {
+        senderStr =
+            endPointToString(result.getSender().getDataNodeLocation().getInternalEndPoint());
+        senderStr += " (DataNode)";
+      } else {
+        senderStr = "All";
+      }
+      builder.getColumnBuilder(1).writeBinary(new Binary(senderStr, TSFileConfig.STRING_CHARSET));
+      // Connection column
+      StringBuilder connectionStatus = new StringBuilder(connectionResultToString(result));
+      while (connectionStatus.length() < connectionMaxLen) {
+        connectionStatus.append(" ");
+      }
+      builder
+          .getColumnBuilder(2)
+          .writeBinary(new Binary(connectionStatus.toString(), TSFileConfig.STRING_CHARSET));
+      builder.declarePosition();
+    }
+
+    future.set(
+        new ConfigTaskResult(
+            TSStatusCode.SUCCESS_STATUS,
+            builder.build(),
+            DatasetHeaderFactory.getTestConnectionHeader()));
+  }
+
+  private static Map<TServiceType, Integer> calculateExpectedResultNum(
+      int configNodeNum, int dataNodeNum) {
+    Map<TServiceType, Integer> result = new HashMap<>();
+    result.put(TServiceType.ConfigNodeInternalService, configNodeNum + dataNodeNum);
+    result.put(TServiceType.DataNodeInternalService, configNodeNum + dataNodeNum);
+    result.put(TServiceType.DataNodeMPPService, dataNodeNum);
+    result.put(TServiceType.DataNodeExternalService, dataNodeNum);
+    return result;
+  }
+
+  private static String serviceProviderToString(TServiceProvider provider) {
+    String serviceStr = endPointToString(provider.getEndPoint());
+    serviceStr += " (" + provider.getServiceType() + ")";
+    return serviceStr;
+  }
+
+  private static String connectionResultToString(TTestConnectionResult result) {
+    if (result.isSuccess()) {
+      return "up";
+    }
+    return "down" + " (" + result.getReason() + ")";
+  }
+
+  private static String endPointToString(TEndPoint endPoint) {
+    return endPoint.getIp() + ":" + endPoint.getPort();
+  }
+
+  private static void sortTestConnectionResp(TTestConnectionResp origin) {
+    origin
+        .getResultList()
+        .sort(
+            (o1, o2) -> {
+              {
+                String serviceIp1 = o1.getServiceProvider().getEndPoint().getIp();
+                String serviceIp2 = o2.getServiceProvider().getEndPoint().getIp();
+                if (!serviceIp1.equals(serviceIp2)) {
+                  return serviceIp1.compareTo(serviceIp2);
+                }
+              }
+              {
+                int servicePort1 = o1.getServiceProvider().getEndPoint().getPort();
+                int servicePort2 = o2.getServiceProvider().getEndPoint().getPort();
+                if (servicePort1 != servicePort2) {
+                  return Integer.compare(servicePort1, servicePort2);
+                }
+              }
+              return 0;
+            });
+  }
+
+  private static int calculateServiceProviderMaxLen(TTestConnectionResp resp) {
+    return resp.getResultList().stream()
+        .map(TTestConnectionResult::getServiceProvider)
+        .map(TestConnectionTask::serviceProviderToString)
+        .mapToInt(String::length)
+        .max()
+        .getAsInt();
+  }
+
+  private static int calculateConnectionMaxLen(TTestConnectionResp resp) {
+    return resp.getResultList().stream()
+        .map(TestConnectionTask::connectionResultToString)
+        .mapToInt(String::length)
+        .max()
+        .getAsInt();
+  }
+
+  private static String addLineBreak(String origin, int interval) {

Review Comment:
   clean



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/client/async/handlers/rpc/SubmitTestConnectionTaskToConfigNodeRPCHandler.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.client.async.handlers.rpc;
+
+import org.apache.iotdb.common.rpc.thrift.TConfigNodeLocation;
+import org.apache.iotdb.common.rpc.thrift.TTestConnectionResp;
+import org.apache.iotdb.confignode.client.CnToCnNodeRequestType;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+
+public class SubmitTestConnectionTaskToConfigNodeRPCHandler
+    extends ConfigNodeAsyncRequestRPCHandler<TTestConnectionResp> {
+
+  private static final Logger LOGGER =
+      LoggerFactory.getLogger(SubmitTestConnectionTaskToConfigNodeRPCHandler.class);
+
+  public SubmitTestConnectionTaskToConfigNodeRPCHandler(
+      CnToCnNodeRequestType requestType,
+      int requestId,
+      TConfigNodeLocation targetConfigNode,
+      Map<Integer, TConfigNodeLocation> configNodeLocationMap,
+      Map<Integer, TTestConnectionResp> responseMap,
+      CountDownLatch countDownLatch) {
+    super(
+        requestType,
+        requestId,
+        targetConfigNode,
+        configNodeLocationMap,
+        responseMap,
+        countDownLatch);
+  }
+
+  @Override
+  public void onComplete(TTestConnectionResp resp) {
+    responseMap.put(requestId, resp);
+    nodeLocationMap.remove(requestId);
+    countDownLatch.countDown();
+  }
+
+  @Override
+  public void onError(Exception e) {
+    responseMap.put(requestId, new TTestConnectionResp());

Review Comment:
   e



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/client/cn/DnToCnRequestType.java:
##########
@@ -0,0 +1,25 @@
+/*
+ * 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.db.protocol.client.cn;
+
+public enum DnToCnRequestType {

Review Comment:
   add some comments



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ClusterManager.java:
##########
@@ -79,4 +104,195 @@ private void generateClusterId() {
       LOGGER.warn(CONSENSUS_WRITE_ERROR, e);
     }
   }
+
+  public TTestConnectionResp submitTestConnectionTaskToEveryNode() {
+    TTestConnectionResp resp = new TTestConnectionResp();
+    resp.resultList = new ArrayList<>();
+    resp.setStatus(new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()));
+    TNodeLocations nodeLocations = new TNodeLocations();
+    nodeLocations.setConfigNodeLocations(configManager.getNodeManager().getRegisteredConfigNodes());
+    nodeLocations.setDataNodeLocations(
+        configManager.getNodeManager().getRegisteredDataNodes().stream()
+            .map(TDataNodeConfiguration::getLocation)
+            .collect(Collectors.toList()));
+    // For ConfigNode
+    Map<Integer, TConfigNodeLocation> configNodeLocationMap =
+        configManager.getNodeManager().getRegisteredConfigNodes().stream()
+            .collect(Collectors.toMap(TConfigNodeLocation::getConfigNodeId, location -> location));
+    ConfigNodeAsyncRequestContext<TNodeLocations, TTestConnectionResp>
+        configNodeAsyncRequestContext =
+            new ConfigNodeAsyncRequestContext<>(
+                ConfigNodeToConfigNodeRequestType.SUBMIT_TEST_CONNECTION_TASK,
+                nodeLocations,
+                configNodeLocationMap);
+    ConfigNodeToConfigNodeInternalServiceAsyncRequestManager.getInstance()
+        .sendAsyncRequest(configNodeAsyncRequestContext);
+    Map<Integer, TConfigNodeLocation> anotherConfigNodeLocationMap =
+        configManager.getNodeManager().getRegisteredConfigNodes().stream()
+            .collect(Collectors.toMap(TConfigNodeLocation::getConfigNodeId, location -> location));
+    configNodeAsyncRequestContext
+        .getResponseMap()
+        .forEach(
+            (nodeId, configNodeResp) -> {
+              if (configNodeResp.isSetResultList()) {
+                resp.getResultList().addAll(configNodeResp.getResultList());
+              } else {
+                resp.getResultList()
+                    .addAll(
+                        badConfigNodeConnectionResult(
+                            anotherConfigNodeLocationMap.get(nodeId), nodeLocations));
+              }
+            });
+    // For DataNode

Review Comment:
   add todo here



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/client/dn/DnToDnRequestType.java:
##########
@@ -0,0 +1,24 @@
+/*
+ * 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.db.protocol.client.dn;
+
+public enum DnToDnRequestType {

Review Comment:
   add some comments



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org