d-wang-commit commented on code in PR #18892:
URL: https://github.com/apache/iotdb/pull/18892#discussion_r4310975186
##########
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:
The existing empty rollback implementation can leave DataNodes in _Removing_
when a child procedure fails. To mitigate this, reuse the normal cleanup logic
when rolling back the _STOP_DATA_NODE_ state: unregister and stop nodes with no
remaining Regions, and restore the previous status of nodes that still host
Regions. The original failure is preserved.
--
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]