You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/06/11 11:37:42 UTC

[GitHub] [iotdb] leety1228 opened a new pull request, #6235: [IoTDB-3124][IoTDB-3051]Initialize ConfigNode with multi-seed mode and ConfigNode shrinking process

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

   ## Description
   
   
   ### Content1 ...
   
   ### Content2 ...
   
   ### Content3 ...
   
   <!--
   In each section, please describe design decisions made, including:
    - Choice of algorithms
    - Behavioral aspects. What configuration values are acceptable? How are corner cases and error 
       conditions handled, such as when there are insufficient resources?
    - Class organization and design (how the logic is split between classes, inheritance, composition, 
       design patterns)
    - Method organization and design (how the logic is split between methods, parameters and return types)
    - Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
   -->
   
   
   <!-- It's good to describe an alternative design (or mention an alternative name) for every design 
   (or naming) decision point and compare the alternatives with the designs that you've implemented 
   (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
   
   <!-- If there was a discussion of the design of the feature implemented in this PR elsewhere 
   (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), 
   link to that discussion from this PR description and explain what have changed in your final design 
   compared to your original proposal or the consensus version in the end of the discussion. 
   If something hasn't changed since the original discussion, you can omit a detailed discussion of 
   those aspects of the design here, perhaps apart from brief mentioning for the sake of readability 
   of this PR description. -->
   
   <!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
   
   <hr>
   
   This PR has:
   - [ ] been self-reviewed.
       - [ ] concurrent read
       - [ ] concurrent write
       - [ ] concurrent read and write 
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] added Javadocs for most classes and all non-trivial methods. 
   - [ ] added or updated version, __license__, or notice information
   - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious 
     for an unfamiliar reader.
   - [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold 
     for code coverage.
   - [ ] added integration tests.
   - [ ] been tested in a test IoTDB cluster.
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items 
   apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items 
   from the checklist above are strictly necessary, but it would be very helpful if you at least 
   self-review the PR. -->
   
   <hr>
   
   ##### Key changed/added classes (or packages if there are too many classes) in this PR
   


-- 
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


[GitHub] [iotdb] leety1228 closed pull request #6235: [IoTDB-3124][IoTDB-3051]Initialize ConfigNode with multi-seed mode and ConfigNode shrinking process

Posted by GitBox <gi...@apache.org>.
leety1228 closed pull request #6235: [IoTDB-3124][IoTDB-3051]Initialize ConfigNode with multi-seed mode and ConfigNode shrinking process
URL: https://github.com/apache/iotdb/pull/6235


-- 
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


[GitHub] [iotdb] neuyilan commented on a diff in pull request #6235: [IoTDB-3124][IoTDB-3051]Initialize ConfigNode with multi-seed mode and ConfigNode shrinking process

Posted by GitBox <gi...@apache.org>.
neuyilan commented on code in PR #6235:
URL: https://github.com/apache/iotdb/pull/6235#discussion_r897817525


##########
confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeRemoveCheck.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.conf;
+
+import org.apache.iotdb.common.rpc.thrift.TConfigNodeLocation;
+import org.apache.iotdb.common.rpc.thrift.TEndPoint;
+import org.apache.iotdb.commons.exception.BadNodeUrlException;
+import org.apache.iotdb.commons.utils.NodeUrlUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+
+public class ConfigNodeRemoveCheck {
+  private static final Logger LOGGER = LoggerFactory.getLogger(ConfigNodeStartupCheck.class);
+
+  private static final ConfigNodeConf conf = ConfigNodeDescriptor.getInstance().getConf();
+
+  private final File systemPropertiesFile;
+  private final Properties systemProperties;
+
+  public ConfigNodeRemoveCheck() {
+    systemPropertiesFile =
+        new File(conf.getSystemDir() + File.separator + ConfigNodeConstant.SYSTEM_FILE_NAME);
+    systemProperties = new Properties();
+  }
+
+  public TConfigNodeLocation removeCheck(TEndPoint endPoint) {
+    TConfigNodeLocation nodeLocation = new TConfigNodeLocation();
+    if (!systemPropertiesFile.exists()) {
+      LOGGER.error("The system properties file is not exists. IoTDB-ConfigNode is shutdown.");
+      return nodeLocation;
+    }
+    try (FileInputStream inputStream = new FileInputStream(systemPropertiesFile)) {
+      systemProperties.load(inputStream);
+      nodeLocation =
+          new TConfigNodeLocation(endPoint, new TEndPoint(endPoint.getIp(), getConsensusPort()));
+      if (getConfigNdoeList().contains(nodeLocation)) {
+        return nodeLocation;
+      }
+    } catch (IOException | BadNodeUrlException e) {
+      LOGGER.error("Load system properties file failed.", e);
+    }
+
+    return nodeLocation;
+  }
+

Review Comment:
   The method may return an `EMPTY` TConfigNodeLocation,
   so the method caller should check this or return null if the endPoint is not in the configNodeList. 
   what do you think?



##########
confignode/src/main/java/org/apache/iotdb/confignode/client/SyncConfigNodeClientPool.java:
##########
@@ -42,43 +44,143 @@ public class SyncConfigNodeClientPool {
 
   private final IClientManager<TEndPoint, SyncConfigNodeIServiceClient> clientManager;
 
+  private TEndPoint configNodeLeader;
+
   private SyncConfigNodeClientPool() {
     clientManager =
         new IClientManager.Factory<TEndPoint, SyncConfigNodeIServiceClient>()
             .createClientManager(
                 new DataNodeClientPoolFactory.SyncConfigNodeIServiceClientPoolFactory());
+    configNodeLeader = new TEndPoint();
   }
 
-  /** Only use registerConfigNode when the ConfigNode is first startup. */
-  public TConfigNodeRegisterResp registerConfigNode(
-      TEndPoint endPoint, TConfigNodeRegisterReq req) {
+  private boolean updateConfigNodeLeader(TSStatus status) {
+    if (status.getCode() == TSStatusCode.NEED_REDIRECTION.getStatusCode()) {
+      if (status.isSetRedirectNode()) {
+        configNodeLeader = status.getRedirectNode();
+      } else {
+        configNodeLeader = null;
+      }
+      return true;
+    }
+    return false;
+  }
+
+  public TConfigNodeConfigurationResp getConfigNodeConfiguration(
+      TConfigNodeLocation configNodeLocation) {
     // TODO: Unified retry logic
     for (int retry = 0; retry < retryNum; retry++) {
-      try (SyncConfigNodeIServiceClient client = clientManager.borrowClient(endPoint)) {
-        return client.registerConfigNode(req);
+      try (SyncConfigNodeIServiceClient client =
+          clientManager.borrowClient(configNodeLocation.getInternalEndPoint())) {
+        return client.getConfigNodeConfiguration(configNodeLocation);
       } catch (Exception e) {
-        LOGGER.warn("Register ConfigNode failed, retrying...", e);
+        LOGGER.warn("Get ConfigNode configuration failed, retrying...", e);
         doRetryWait();
       }
     }
+    LOGGER.error("Get ConfigNode configuration failed");
+    return new TConfigNodeConfigurationResp()
+        .setStatus(
+            new TSStatus(TSStatusCode.ALL_RETRY_FAILED.getStatusCode())
+                .setMessage("All retry failed."));
+  }
+
+  /** Only use registerConfigNode when the ConfigNode is first startup. */
+  public TConfigNodeRegisterResp registerConfigNode(
+      List<TEndPoint> endPointList, TConfigNodeRegisterReq req) {
+    // TODO: Unified retry logic
+    for (TEndPoint endPoint : endPointList) {
+      for (int retry = 0; retry < retryNum; retry++) {
+        try (SyncConfigNodeIServiceClient client = clientManager.borrowClient(endPoint)) {
+          TConfigNodeRegisterResp resp = client.registerConfigNode(req);
+          if (updateConfigNodeLeader(resp.status)) {
+            client.close();
+            return clientManager.borrowClient(configNodeLeader).registerConfigNode(req);
+          } else {

Review Comment:
   can we make sure the `configNodeLeader` is not null?



-- 
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