Skip to main content

cancel_flow

Function cancel_flow 

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

  1. SELECT + UPDATE ff_flow_core.public_flow_state = 'cancelled' (atomic state flip).
  2. For CancelAll/CancelPending: SELECT member execution ids from ff_exec_core filtered by flow_id and state, UPDATE each to cancelled, INSERT a ff_completion_event row per member (the trigger fires NOTIFY at COMMIT).
  3. For CancelPending under CancelRemaining semantics (Stage C), INSERT a ff_pending_cancel_groups bookkeeping 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.