Optimistic Concurrency Control (OCC)
In this lesson, we will describe a way through which the optimistic concurrency control method controls concurrent operations.
Optimistic concurrency control (OCC) is a concurrency control method that was first proposed in 1981 by
In this method, transactions execute in the following three phases:
- Begin
- Read & modify
- Validate & commit/rollback
Begin phase
In this phase, transactions are assigned a unique
Read & modify phase
During this phase, transactions execute their read and write operations tentatively. This means that when an item is modified, a copy of the item is written to a temporary, local storage location. A read operation first checks for a copy of the item in this location and returns this one, if it exists. Otherwise, it performs a regular read operation from the database.
Validate & commit/rollback phase
The transaction enters this phase when all operations have been executed.
During this phase, the transaction checks whether there are other transactions that have modified the data this transaction has accessed, and have started after this transaction’s start time. If there are, then the transaction is aborted and restarted from the beginning, acquiring a new timestamp. Otherwise, the transaction can be committed.
Get hands-on with 1400+ tech skills courses.