Copilot commented on code in PR #18892:
URL: https://github.com/apache/iotdb/pull/18892#discussion_r4300673385
##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/region/RemoveRegionPeerProcedure.java:
##########
@@ -193,30 +196,80 @@ protected Flow executeFromState(ConfigNodeProcedureEnv
env, RemoveRegionPeerStat
setNextState(REMOVE_REGION_LOCATION_CACHE);
break;
case REMOVE_REGION_LOCATION_CACHE:
- handler.removeRegionLocation(regionId, targetDataNode);
+ tsStatus = handler.removeRegionLocation(regionId, targetDataNode);
+ if (tsStatus == null || tsStatus.getCode() !=
SUCCESS_STATUS.getStatusCode()) {
+ return retryStep(state);
+ }
+ if (!handler.isIoTConsensusV1DataRegion(regionId)) {
+ return finishRemoval(state);
+ }
setKillPoint(state);
- LOGGER.info(ProcedureMessages.REMOVEREGIONPEER_STATE_SUCCESS, state);
- LOGGER.info(
- ProcedureMessages
-
.PID_REMOVEREGION_SUCCESS_REGION_HAS_BEEN_REMOVED_FROM_DATANODE_PROCEDURE,
- getProcId(),
- regionId.getId(),
- targetDataNode.getDataNodeId(),
- CommonDateTimeUtils.convertMillisecondToDurationStr(
- System.currentTimeMillis() - getSubmittedTime()),
- DateTimeUtils.convertLongToDate(getSubmittedTime(), "ms"));
- return Flow.NO_MORE_STATE;
+ setNextState(RESET_IOT_CONSENSUS_V1_PEER_LIST);
+ break;
+ case RESET_IOT_CONSENSUS_V1_PEER_LIST:
+ if (!handler.resetPeerListAfterRemoveForIoTConsensusV1(regionId,
targetDataNode)) {
+ return retryStep(state);
+ }
+ return finishRemoval(state);
default:
throw new ProcedureException(ProcedureMessages.UNSUPPORTED_STATE +
state.name());
}
} catch (Exception e) {
LOGGER.error(ProcedureMessages.REMOVEREGIONPEER_STATE_FAILED, state, e);
+ if (state == REMOVE_REGION_LOCATION_CACHE || state ==
RESET_IOT_CONSENSUS_V1_PEER_LIST) {
+ return retryStep(state);
+ }
return Flow.NO_MORE_STATE;
}
LOGGER.info(ProcedureMessages.PID_REMOVEREGION_STATE_SUCCESS, getProcId(),
state);
return Flow.HAS_MORE_STATE;
}
+ private Flow retryStep(RemoveRegionPeerState state) {
+ if (getCycles() >= MAX_FINALIZATION_RETRY) {
+ ProcedureException failure =
+ new ProcedureException(
+ String.format(
+ ProcedureMessages
+
.EXCEPTION_FAILED_TO_FINALIZE_REGION_PEER_REMOVAL_FOR_ARG_AT_STATE_ARG_AFTER_ARG_ATTEMPTS_382EA168,
+ regionId,
+ state,
+ getCycles() + 1));
+ LOGGER.error(ProcedureMessages.REMOVEREGIONPEER_STATE_FAILED, state,
failure);
+ setFailure(failure);
Review Comment:
When this procedure runs under `RemoveDataNodesProcedure` (through
`RegionMigrateProcedure`), exhausting either finalization retry limit calls
`setFailure`, and `RootProcedureStack.addRollbackStep` marks the entire root
stack failed. The removal targets have already been changed to `Removing`, but
the parent's `STOP_DATA_NODE` step is skipped and its `rollbackState` is empty.
Consequently, the targets remain registered in `Removing` instead of being
stopped or having their previous statuses restored; some may still host
unmigrated regions. Add failure cleanup in the enclosing node-removal flow
while preserving the reconciliation failure, and cover child retry exhaustion
with a `ProcedureExecutor` regression test.
--
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]