pub async fn cancel_flow(
pool: &PgPool,
partition_config: &PartitionConfig,
id: &FlowId,
policy: CancelFlowPolicy,
) -> Result<CancelFlowResult, EngineError>Expand description
cancel_flow — SERIALIZABLE cascade with a 3-attempt retry loop.
Transaction steps:
- SELECT + UPDATE
ff_flow_core.public_flow_state = 'cancelled'(atomic state flip). - For
CancelAll/CancelPending: SELECT member execution ids fromff_exec_corefiltered by flow_id and state, UPDATE each tocancelled, INSERT aff_completion_eventrow per member (the trigger fires NOTIFY at COMMIT). - For
CancelPendingunderCancelRemainingsemantics (Stage C), INSERT aff_pending_cancel_groupsbookkeeping row for every running sibling group that the Wave-5 dispatcher needs to follow up on. Wave 4c only writes the bookkeeping row — the actual dispatch is Wave 5.
On SQLSTATE 40001 / 40P01 (serialization / deadlock) the
transaction ROLLBACKs, we sleep a tiny backoff, and retry. After
[CANCEL_FLOW_MAX_ATTEMPTS] failed attempts we return
ContentionKind::RetryExhausted.