Optimistic Concurrency Control Techniques, Phases, Advantages

The optimistic control protocol is also called validation-based protocol which copies the transaction data locally and updates the local copy of data instead of actual data in the database.

Optimistic Concurrency Control, or OCC, is like playing a game where you assume everything will go smoothly until you reach the end. Instead of checking every move, you wait until the last moment to make sure no one has broken the rules.

Here’s how it works in databases

  1. Start: Everyone begins their tasks, thinking all will go well.
  2. Check: At the end, before finishing, everyone checks to see if they bumped into someone else’s work.
  3. Finish: If everything’s okay, they finish their task. If not, they try again.

Phases of Optimistic Concurrency Control

  1. Read phase: All transaction data are read and stored in a temporary variable which is also called the local variable of that transaction, after which a write operation is performed on the temporary variable.
  2. Validation phase: In this phase, a test is performed to determine if the changes of the local variable are also possible in the actual database. This phase ensures the violation-free change in the execution of a transaction.
  3. Write phase: After the validation phase passed successfully then the changes are made in the actual database.

Advantages of Optimistic Control Protocol

  1. Minimized Locking Overhead: OCC reduces the need for locks. This means that data items don’t need to be locked and unlocked frequently, which can save time and resources. It’s like having an honor system in a classroom where students manage themselves, reducing the need for constant teacher supervision.
  2. Increased Throughput: By avoiding locks, OCC allows more transactions to complete in a given period. It’s similar to more cars moving smoothly through intersections with fewer red lights, keeping traffic flowing.
  3. Reduced Waiting Time: Transactions under OCC don’t wait for locks to be released. This means that tasks can be carried out without being held up by others, much like people not having to queue at a buffet.
  4. Better Performance in Low Conflict Environments: In scenarios where database access conflicts are infrequent, OCC shines by allowing transactions to proceed without preemptive checks for conflicts, akin to rarely encountering traffic on a road, thus reaching your destination faster.
  5. Deadlock Avoidance: Since OCC doesn’t rely on locks, the possibility of deadlocks—situations where transactions wait on each other indefinitely—is virtually eliminated. Imagine a situation where two kids want to play with different toys without interfering with each other, ensuring smooth playtime.

Each of these advantages contributes to making OCC a preferred method for managing data concurrency in certain database environments, particularly those where the likelihood of transaction conflicts is low.