databases

Concurrency Control: Optimistic and Pessimistic

PCC (Pessimistic)

  • Uses locks, sub-sequent transactions wait until lock is released.
  • Dis-advantages:
    • Slower speeds incase of multiple transactions (might be due to bad database design ? Why is a single row being updated a million times at the same time ?)

OCC (Optimistic)

  • A transaction starts with a read and then after the write operation, the transaction checks if the original value has changed (due to another thread/process updating that value). If the original value remains the same, if not, then the transaction has to be rolled back and re-try.
    • This results in an error message to the client.
  • Does not use locks.
  • Requires READ COMMITED isolation.
  • Dis-advantage:
    • There is a chance that another write might be committed between the 2nd read and the commit. This is called time-to-check to time-to-use.
  • WiredTiger Architecture ?