Transactions executed with optimistic concurrency control are divided into three phases:
- a read phase during which a transaction reads and writes values to a local cache,
- a validation phase during which a transaction checks to see if its execution is consistent with a serialization of concurrently executing transactions, and
- a write phase during which a transaction copies its cached writes into the database (provided it passed validation).
A transaction is assigned a timestamp when it enters its validation phase. The
logic to validate transaction j
is as follows:
- for all transactions
i
<j
:- if the write set of
i
overlaps the read set ofj
:- transaction
i
must finish its write phase before transactionj
starts its read phase
- transaction
- elif the write set of
i
overlaps the write set ofj
:- transaction
i
must finish its write phase before transactionj
starts its write phase
- transaction
- else:
- the two transactions can overlap arbitrarily
- if the write set of
This repo includes a toy implementation of the OCC algorithms presented in [1].
- [1]: Kung, Hsiang-Tsung, and John T. Robinson. "On optimistic methods for concurrency control." ACM Transactions on Database Systems (TODS) 6.2 (1981): 213-226.