Skip to main content

Module compensation

Module compensation 

Source
Expand description

Saga / compensation pattern operations.

Implement the saga pattern for distributed transaction rollback:

  1. DurableContext::step_with_compensation — execute a forward step and, on success, register a type-erased compensation closure that can reverse it.
  2. DurableContext::run_compensations — execute all registered compensations in reverse registration order (LIFO — last registered, first executed), checkpointing each one with Context/START + Context/SUCCEED|FAIL using sub_type = "Compensation". All compensations are attempted regardless of earlier failures (continue-on-error semantics).

§Checkpoint Protocol

Each compensation checkpoint mirrors the child_context pattern:

  • OperationType::Context + OperationAction::Start + sub_type = "Compensation"
  • OperationType::Context + OperationAction::Succeed + sub_type = "Compensation"
  • or OperationType::Context + OperationAction::Fail on error

§Replay / Partial Rollback Resume

During replay, completed compensations (Succeeded or Failed in history) are skipped — their outcome is read from history. This enables partial rollback resume: if a Lambda times out mid-compensation, the next invocation replays the completed ones and continues from the first incomplete one.