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


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/ProcedureExecutor.java:
##########
@@ -708,6 +720,10 @@ private LockStateResult<Env> executeRootStackRollback(
         cleanupAfterRollback(procedure);
         continue;
       }
+      if (proceduresKeepingTheirStates.contains(procedure)) {
+        // Finished below, once the rest of the stack has been rolled back.
+        continue;

Review Comment:
   fixed it



##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/ProcedureExecutor.java:
##########
@@ -730,12 +746,60 @@ 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);
+    }
+    if (procedure.hasParent()) {
+      try {
+        store.delete(procedure.getProcId());
+        // do not remove this procedure when exception occurred
+        procedures.remove(procedure.getProcId());
+      } catch (final Exception e) {
+        LOG.warn(ProcedureMessages.FAILED_TO_DELETE_PROCEDURE_ON_ROLLBACK, e);
+      }
+    } else {
+      // A child which never executed has no rollback step and is not visited 
above, so its record
+      // goes with the ones of the children which were.
+      final long[] childProcIds = 
rollbackStack.get(procedure.getProcId()).getSubprocedureIds();
+      if (childProcIds.length > 0) {
+        try {
+          store.delete(childProcIds);
+        } catch (final Exception e) {
+          LOG.warn(ProcedureMessages.FAILED_TO_DELETE_PROCEDURE_ON_ROLLBACK, 
e);
+        }
+      }
+      // The stack indexes and the states just dropped are persisted here, so 
that the rollback
+      // recovered by a new leader leaves this procedure out. Endless retry 
since this step is not
+      // idempotent.
+      RetryUtils.executeWithEndlessBackoffRetry(
+          () -> store.update(procedure), "finish procedure without rollback");

Review Comment:
   fixed it



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