Optimistic Concurrency Control (OCC) is a concurrency control method that assumes that multiple transactions can complete without affecting each other, and that therefore transactions can proceed without locking the data resources that they affect. Before committing, each transaction verifies that no other transaction has modified its data. If the check reveals conflicting modifications, the committing transaction rolls back.
However, if conflicts happen often, the cost of repeatedly restarting transactions hurts performance significantly; other concurrency control methods have better performance under these conditions.
Optimistic Concurrency Control Phases
More specifically, OCC transactions involve these phases:
? Begin: Record a timestamp marking the transaction's beginning.
? Modify: Read and write database values.
? Validate: Check whether other transactions have modified data that this transaction has modified. Always check transactions that completed after this transaction's start time. Optionally, check transactions that are still active at validation time.
? Commit/Rollback: If there is no conflict, make all changes part of the official state of the database. If there is a conflict, resolve it, typically by aborting the transaction, although other resolution schemes are possible.
OCC is generally used in environments with low data contention. When conflicts are rare, transactions can complete without the expense of managing locks and without having transactions wait for other transactions' locks to clear, leading to higher throughput than other concurrency control methods.