Retrying a Transaction from Its Beginning

Some concurrency failures mean the whole transaction must be retried. A retry should repeat the reads and decisions belonging to that transaction.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace changed input
  2. Constrain additional effects
  3. Recompute decisions from the new snapshot
  4. Bound retries and handle effects outside the database

Trace changed input

An application calculates an allocation using a quantity it read earlier. A concurrent commit may change that quantity before another attempt. Reusing the old observation can repeat the same incorrect decision. Version-checked updates make that conflict visible.

Constrain additional effects

Remote calls or notifications outside the transaction may require separate coordination. Use retry-safe contracts and a bounded attempt policy.[1]

Recompute decisions from the new snapshot

A transaction selects a free slot and attempts to reserve it. If the database requires a retry after a serialization failure, repeating only the final write can reuse a slot decision made against old data. Start again from the initial read. See function retry contracts.

Attempt 1 reads slot A → commit rejected
Retry starts fresh → sees A occupied
Select B if available → try to commit new decision

Bound retries and handle effects outside the database

Not every failure is retryable. Define a maximum budget, and avoid repeating irreversible external effects during retries. Test a transaction whose earliest read needs to change on the next attempt.

References

  1. PostgreSQL Global Development Group, Transaction Isolation ↩