Algorithm Search⌘K

Transactions and concurrency control

Problems

  • Concurrency control problem

    Build a scheduler that interleaves the actions of concurrent transactions, by running, delaying or rejecting each one, so that the output is serializable and recoverable.

    core
  • Robustness against weak isolation

    Decide whether every execution of a given set of transactions or programs that a weak isolation level allows is serializable, so the weak level is safe for that workload.

    research

Algorithms

  • Conservative two-phase locking

    Two-phase locking in which a transaction declares its read and write sets and gets all its locks at once before its first action. A waiting transaction holds nothing, so there is no deadlock.

    O(w s k) expected per-admission-pass1 languagescore
  • Multiple granularity locking

    Lock the nodes of a hierarchy of database, tables and rows. Intention modes IS, IX and SIX on the ancestors let a coarse lock and a fine lock see each other with one test per node.

    O(d k) expected per-row-access · per-subtree-lock1 languagescore
  • Optimistic concurrency control

    Transactions run without locks on private copies, then a validation step checks their read sets against the write sets of transactions that committed meanwhile, and aborts on overlap.

    O(r + w + k w) worst1 languagescore
  • Strict two-phase locking

    Two-phase locking that keeps exclusive locks until commit or abort. Schedules are strict, so no cascading aborts; the rigorous form keeps all locks and serializes in commit order.

    O(w) per-abort1 languagescore
  • Timestamp ordering

    Give each transaction a timestamp at start and keep, per item, the largest read and write timestamps. An action that arrives too late aborts its transaction. No locks, no deadlocks.

    O(n) total1 languagescore
  • Two-phase locking

    Lock each item before use and never lock again after the first unlock. Every schedule it allows is conflict serializable, in the order of the lock points.

    O(k^2) per-deadlock-check1 languagescore
  • Wait-die and wound-wait

    Two rules that prevent deadlock in a locking scheduler by age: in wait-die only older transactions wait, in wound-wait only younger ones do. A restart keeps its timestamp.

    O(1) deadlock-search1 languagescore
  • Key-range locking

    Locking for ordered indexes where a lock on a key also covers the gap below it, so range scans see no phantom inserts. Next-key locking is the usual form.

    O(log n + k) expected per-point-operation1 languagesadvanced
  • Transaction chopping

    Split known transaction programs into pieces that commit one by one, and keep every execution serializable: a chopping is safe when its graph of sibling and conflict edges has no SC-cycle.

    O((m^2 + n^3) α(m)) worst1 languagesadvanced
  • Tree locking protocol

    A protocol for items arranged in a tree that locks a node only while holding its parent and allows early release, yet stays serializable.

    O(1) expected per-request1 languagesadvanced
  • Serializable snapshot isolation

    Snapshot isolation plus SIREAD locks and two flags per transaction, which abort any transaction that could be the pivot of two consecutive rw edges, so that every committed history is serializable.

    O(p + v + s + w) worst1 languagesresearch
  • Silo epoch-based OCC

    An optimistic commit protocol for multicore in-memory databases: lock the write set, read a global epoch, validate the read set by TIDs, then install. Reads never write shared memory.

    O(r + w log w) worst1 languagesresearch

Data structures

  • Lock table

    A hash table from each locked item to its granted group and a FIFO queue of waiting requests, with a compatibility matrix of lock modes. It is the core of a lock manager.

    O(1 + (1 + a) g) expected release1 languagesintro

Techniques

  • Multiversion concurrency control

    Keep several committed versions of each item, so that a read can be served by an older version instead of waiting or aborting. The schedule must be one-copy serializable.

    1 languagescore
  • Commitment ordering

    Commit transactions in the order of their conflicts. Each local schedule is then serializable, and with atomic commitment the global schedule across databases is too.

    advanced
  • Escrow transactional method

    Let concurrent transactions update a numeric quantity by reserving amounts in escrow, as long as all outcomes respect its bounds.

    advanced
  • Predicate locking

    Lock the condition of a query instead of the rows it found, so that a write of any row that matches the condition must wait. This is the exact cure for the phantom problem.

    1 languagesadvanced
  • Thomas write rule

    In timestamp ordering, skip a write that a younger write has already made obsolete instead of aborting. It admits some schedules that are view but not conflict serializable.

    1 languagesadvanced

Concepts

  • Conflict graph

    A directed graph on the transactions of a schedule, with an edge Ti -> Tj when an action of Ti conflicts with a later action of Tj. It is acyclic exactly when the schedule is conflict serializable.

    1 languagescore
  • Transaction anomalies

    The ways concurrent transactions go wrong under weak isolation, from dirty writes to write skew. Each is a pattern of operations or a cycle of dependencies, and levels are named by what they forbid.

    core
  • Write skew

    Two concurrent transactions each read data that the other writes, and write different items. Each is correct alone, but together they break a rule that spans the items. Snapshot isolation allows it.

    core
  • Phantom problem

    A query reads the rows that match a condition, and another transaction then inserts a matching row. Row locks cannot stop this, so two-phase locking on rows is not serializable.

    1 languagesadvanced

Definitions

  • ACID properties

    The four guarantees of a database transaction: atomicity (all or nothing), consistency (constraints kept), isolation (as if alone) and durability (commits survive crashes).

    intro
  • Schedule (transaction history)

    An interleaving of the read, write, commit and abort actions of several transactions that keeps the order within each transaction.

    intro
  • Cascadeless schedule

    A schedule in which transactions read only values written by committed transactions, so one abort never forces another.

    core
  • Conflict serializability

    A schedule is conflict serializable if it orders every pair of conflicting actions the same way as some serial schedule. This holds exactly when its conflict graph is acyclic.

    1 languagescore
  • Isolation levels

    Weaker forms of serializability, named read uncommitted, read committed, repeatable read and serializable in SQL-92, and defined by the anomalies each one forbids.

    1 languagescore
  • Recoverable schedule

    A schedule in which each transaction commits only after every transaction whose writes it read has committed.

    core
  • Serializability

    A concurrent schedule of transactions is serializable if it is equivalent to some serial schedule. Final-state, view and conflict equivalence give three nested classes.

    1 languagescore
  • Snapshot isolation

    Each transaction reads the committed state as of its start and commits only if no concurrent committed transaction wrote an item it wrote. It allows write skew, so it is not serializable.

    1 languagescore
  • Strict schedule

    A schedule in which no item is read or overwritten until the last transaction that wrote it has committed or aborted.

    core
  • Adya's generalized isolation levels

    Isolation levels defined by the cycles they forbid in a graph of dependencies between committed transactions, so that locking, optimistic and multiversion systems can all meet them.

    advanced
  • Multiversion serializability

    A multiversion schedule is serializable when its reads-from relation is that of a serial run on one copy of each item. A version order with an acyclic MVSG proves it.

    advanced
  • View serializability

    A schedule is view serializable if some serial schedule has the same reads-from relation and the same final writes. It is strictly larger than conflict serializability and NP-complete to test.

    1 languagesadvanced

Theorems

  • Serializability theorem

    A schedule is conflict serializable exactly when its conflict graph is acyclic, and a topological order gives an equivalent serial order.

    core
  • Two-phase locking theorem

    Every schedule produced by transactions that follow two-phase locking is conflict serializable, in the order of their lock points.

    core
  • Dangerous structure theorem

    Every cycle in the dependency graph of a snapshot isolation history has two rw-antidependency arcs in a row between concurrent transactions, and the last of the three commits first.

    advanced
  • NP-completeness of view serializability

    Testing whether a schedule is view serializable is NP-complete, unlike conflict serializability, which a cycle test decides.

    advanced

Models

  • Sagas

    A long-lived transaction written as a sequence of local transactions, each with a compensating transaction that undoes it on failure.

    advanced