preConditions onFail=MARK_RAN versus runAlways for Liquibase retry safety: which prevents duplicate writes?
0 reputation · 06 Oct 2024, 13:14 UTC
Goal: configure Liquibase so that a transient failure of a changeSet does not lead to duplicate inserts or updates when the changelog is rerun.
Constraints: the solution must work with the existing lockWaitTimeout and retryCount mechanisms, must not rely on manual intervention, and must consider whether the changeSet is idempotent or not. Using preConditions with onFail=MARK_RAN marks the changeSet as executed even if it partially succeeded, which can hide inconsistencies, while runAlways forces re‑execution on every run, guaranteeing a retry but causing duplicate data for non‑idempotent SQL.
Which approach provides a safer retry behavior without sacrificing correctness? Under what circumstances is it acceptable to accept the risk of marking a partially applied changeSet as ran? Should developers combine these mechanisms with custom idempotency checks or design changeSets to be inherently idempotent?