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/07/18 11:45:44 UTC

[GitHub] [iotdb] Beyyes commented on a diff in pull request #6696: [IOTDB-3869] refactoring remove confignode to Procedure and support rollback

Beyyes commented on code in PR #6696:
URL: https://github.com/apache/iotdb/pull/6696#discussion_r923259990


##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/ProcedureManager.java:
##########
@@ -120,6 +122,18 @@ public void addConfigNode(TConfigNodeRegisterReq req) {
     this.executor.submitProcedure(addConfigNodeProcedure);
   }
 
+  /**
+   * generate a procedure, and execute remove confignodeby one by one

Review Comment:
   spelling 'confignodeby'



##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/ProcedureManager.java:
##########
@@ -120,6 +122,18 @@ public void addConfigNode(TConfigNodeRegisterReq req) {
     this.executor.submitProcedure(addConfigNodeProcedure);
   }
 
+  /**
+   * generate a procedure, and execute remove confignodeby one by one
+   *
+   * @param removeConfigNodePlan remove config node plan
+   */
+  public void removeConfigNode(RemoveConfigNodePlan removeConfigNodePlan) {
+    RemoveConfigNodeProcedure addConfigNodeProcedure =

Review Comment:
   variable naming, `addConfigNodeProcedure` to `removeConfigNodeProcedure`



##########
confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/RemoveConfigNodeProcedure.java:
##########
@@ -0,0 +1,177 @@
+/*
+ * 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.procedure.impl;
+
+import org.apache.iotdb.common.rpc.thrift.TConfigNodeLocation;
+import org.apache.iotdb.commons.exception.runtime.ThriftSerDeException;
+import org.apache.iotdb.commons.utils.ThriftConfigNodeSerDeUtils;
+import org.apache.iotdb.confignode.procedure.StateMachineProcedure;
+import org.apache.iotdb.confignode.procedure.env.ConfigNodeProcedureEnv;
+import org.apache.iotdb.confignode.procedure.exception.ProcedureException;
+import org.apache.iotdb.confignode.procedure.scheduler.SimpleProcedureScheduler;
+import org.apache.iotdb.confignode.procedure.state.ProcedureLockState;
+import org.apache.iotdb.confignode.procedure.state.RemoveConfigNodeState;
+import org.apache.iotdb.confignode.procedure.store.ProcedureFactory;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/** remove config node procedure */
+public class RemoveConfigNodeProcedure
+    extends StateMachineProcedure<ConfigNodeProcedureEnv, RemoveConfigNodeState> {
+  private static final Logger LOG = LoggerFactory.getLogger(RemoveConfigNodeProcedure.class);
+  private static final int retryThreshold = 5;
+
+  private TConfigNodeLocation tConfigNodeLocation;
+
+  public RemoveConfigNodeProcedure() {
+    super();
+  }
+
+  public RemoveConfigNodeProcedure(TConfigNodeLocation tConfigNodeLocation) {
+    super();
+    this.tConfigNodeLocation = tConfigNodeLocation;
+  }
+
+  @Override
+  protected Flow executeFromState(ConfigNodeProcedureEnv env, RemoveConfigNodeState state) {
+    if (tConfigNodeLocation == null) {
+      return Flow.NO_MORE_STATE;
+    }
+    try {
+      switch (state) {
+        case REMOVE_CONFIG_NODE_PREPARE:
+          setNextState(RemoveConfigNodeState.REMOVE_PEER);
+          break;
+        case REMOVE_PEER:
+          env.removeConfigNodePeer(tConfigNodeLocation);
+          setNextState(RemoveConfigNodeState.REMOVE_CONSENSUS_GROUP);
+          LOG.info("Remove peer {}", tConfigNodeLocation);
+          break;
+        case REMOVE_CONSENSUS_GROUP:
+          env.removeConsensusGroup(tConfigNodeLocation);
+          setNextState(RemoveConfigNodeState.STOP_CONFIG_NODE);
+          LOG.info("Remove Consensus Group {}", tConfigNodeLocation);
+          break;
+        case STOP_CONFIG_NODE:
+          env.stopConfigNode(tConfigNodeLocation);
+          LOG.info("Stop Config Node {}", tConfigNodeLocation);
+          return Flow.NO_MORE_STATE;
+      }
+    } catch (Exception e) {
+      if (isRollbackSupported(state)) {
+        setFailure(new ProcedureException("Remove Config Node failed " + state));
+      } else {
+        LOG.error(
+            "Retrievable error trying to remove config node {}, state {}",
+            tConfigNodeLocation,
+            state,
+            e);
+        if (getCycles() > retryThreshold) {
+          setFailure(new ProcedureException("State stuck at " + state));
+        }
+      }
+    }
+    return Flow.HAS_MORE_STATE;
+  }
+
+  @Override
+  protected void rollbackState(ConfigNodeProcedureEnv env, RemoveConfigNodeState state)
+      throws IOException, InterruptedException, ProcedureException {}

Review Comment:
   Is the `rollbackState` method of class `RemoveConfigNodeProcedure` needed to be implemented?



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