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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
