JackieTien97 commented on code in PR #18909:
URL: https://github.com/apache/iotdb/pull/18909#discussion_r4321200745


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/ProcedureExecutor.java:
##########
@@ -730,12 +746,70 @@ private LockStateResult<Env> executeRootStackRollback(
       }
     }
 
+    if (!proceduresKeepingTheirStates.isEmpty()) {
+      subprocStack.removeIf(proceduresKeepingTheirStates::contains);
+      proceduresKeepingTheirStates.forEach(this::finishWithoutRollback);
+    }
+
     LOG.info(
         ProcedureMessages.ROLLED_BACK_TIME_DURATION_IS, rootProcedure, 
rootProcedure.elapsedTime());
     rootProcedureCleanup(rootProcedure);
     return new LockStateResult<>(ProcedureLockState.LOCK_ACQUIRED, 
rootProcedure);
   }
 
+  /**
+   * Finishes a procedure without undoing any of the states it has executed. 
The failure is still
+   * reported, as the operation the procedure was part of did not complete; 
what is dropped is only
+   * the bookkeeping of the rollback, so that neither this rollback nor the 
one a new leader
+   * recovers touches this procedure again.
+   */
+  private void finishWithoutRollback(final Procedure<Env> procedure) {
+    procedure.abandonRollback();
+    if (!procedure.isSuccess()) {
+      procedure.setState(ProcedureState.ROLLEDBACK);
+    }
+    // The rollback loop skipped acquireLock() for this procedure, so a lock 
restored by
+    // restoreLock() on load is still recorded in lockedWhenLoading instead of 
locked. Finish that
+    // bookkeeping and release the lock here: rootProcedureCleanup() releases 
only the locks that
+    // hasLock() reports, and a finished procedure must not keep holding its 
lock.
+    if (procedure.hasLock() || procedure.isLockedWhenLoading()) {
+      if (acquireLock(procedure) == ProcedureLockState.LOCK_ACQUIRED) {
+        releaseLock(procedure, false);

Review Comment:
   [P1] Delete child records before persisting the root's terminal state
   
   `releaseLock()` is not just an in-memory unlock: `Procedure.doReleaseLock()` 
calls `store.update()`, and this method has already marked the procedure 
`ROLLEDBACK`. For a root that skips rollback, such as 
`RemoveDataNodesProcedure`, this persists the completed parent before the later 
`store.delete(childProcIds)` call. A crash or leader change between those 
writes can therefore leave a completed root alongside its child records.
   
   I reproduced this using real `RemoveDataNodesProcedure` and 
`RegionMigrateProcedure` serialization: with one failed child and one pending 
child, take a snapshot at the first write of the completed root and initialize 
a new executor from it. The snapshot still contains a `ROLLEDBACK` child, and 
`ProcedureExecutor.recover()` throws `UnsupportedOperationException("Unexpected 
state")`, preventing executor initialization. The same snapshot-boundary tests 
pass on the base implementation.
   
   Please make the child cleanup durable before the unlock persists the root's 
terminal state, or make recovery safely handle this intermediate state.



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

Reply via email to