HxpSerein commented on code in PR #13559: URL: https://github.com/apache/iotdb/pull/13559#discussion_r1778309124
########## iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/node/RemoveDataNodesProcedure.java: ########## @@ -38,82 +40,89 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; import static org.apache.iotdb.confignode.conf.ConfigNodeConstant.REMOVE_DATANODE_PROCESS; /** remove data node procedure */ -public class RemoveDataNodeProcedure extends AbstractNodeProcedure<RemoveDataNodeState> { - private static final Logger LOG = LoggerFactory.getLogger(RemoveDataNodeProcedure.class); +public class RemoveDataNodesProcedure extends AbstractNodeProcedure<RemoveDataNodeState> { + private static final Logger LOG = LoggerFactory.getLogger(RemoveDataNodesProcedure.class); private static final int RETRY_THRESHOLD = 5; - private TDataNodeLocation removedDataNode; + private List<TDataNodeLocation> removedDataNodes; - private List<TConsensusGroupId> migratedDataNodeRegions = new ArrayList<>(); + private List<RegionMigrationPlan> regionMigrationPlans = new ArrayList<>(); - public RemoveDataNodeProcedure() { + private Map<Integer, NodeStatus> nodeStatusMap; + + public RemoveDataNodesProcedure() { super(); } - public RemoveDataNodeProcedure(TDataNodeLocation removedDataNode) { + public RemoveDataNodesProcedure( + List<TDataNodeLocation> removedDataNodes, Map<Integer, NodeStatus> nodeStatusMap) { super(); - this.removedDataNode = removedDataNode; + this.removedDataNodes = removedDataNodes; + this.nodeStatusMap = nodeStatusMap; } @Override protected Flow executeFromState(ConfigNodeProcedureEnv env, RemoveDataNodeState state) { - if (removedDataNode == null) { + if (removedDataNodes.isEmpty()) { return Flow.NO_MORE_STATE; } - RegionMaintainHandler handler = env.getRegionMaintainHandler(); + RemoveDataNodeManager manager = env.getRemoveDataNodeManager(); try { switch (state) { case REGION_REPLICA_CHECK: - if (env.checkEnoughDataNodeAfterRemoving(removedDataNode)) { + if (manager.checkEnoughDataNodeAfterRemoving(removedDataNodes)) { setNextState(RemoveDataNodeState.REMOVE_DATA_NODE_PREPARE); } else { LOG.error( "{}, Can not remove DataNode {} " + "because the number of DataNodes is less or equal than region replica number", REMOVE_DATANODE_PROCESS, - removedDataNode); + removedDataNodes); return Flow.NO_MORE_STATE; } case REMOVE_DATA_NODE_PREPARE: - // mark the datanode as removing status and broadcast region route map - env.markDataNodeAsRemovingAndBroadcast(removedDataNode); - migratedDataNodeRegions = handler.getMigratedDataNodeRegions(removedDataNode); + removedDataNodes.parallelStream() Review Comment: refactored. -- 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-unsubscr...@iotdb.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org