The difference between the OCC and MVCC

I. Introduction

      In the database, concurrency control refers to simultaneously operate the database, how to ensure consistency and isolation of transactions across multiple user / process / thread, while maximizing concurrency.

      When multiple users / processes / threads simultaneously operate the database, there will be three kinds of conflict situations:

  • Read - read, there is no problem
  • Read - write, there are isolated problems, you may encounter a dirty read (will read uncommitted data), Mirage reading and so on.
  • Write - write, update may be lost

      To resolve the conflict, approach is the lock that lock-based concurrency control, such as 2PL, in this way the cost is relatively high, and can not avoid deadlock.

Two, MVCC

      Multi-version concurrency control (MVCC) is a method used to solve the read - write conflict lock-free concurrency control, which is a one-way distribution growth for the transaction timestamp, save a copy of each modified version that is associated with the transaction timestamp, read read-only snapshot before the start of the transaction (see) database. At the same time so that the read operation without disabling the write operation, the write operation without blocking read operation, avoid dirty reads and non-repeatable read

Three, OCC

      Optimistic concurrency control (OCC) is a method used to solve the write - write conflict lock-free concurrency control that contention between transactions not so much, so first make changes before committing the transaction, the transaction began after the check, there is no new submit changes, if not submission, if you give up and try again. Optimistic concurrency control similar optional lock. Optimistic concurrency control is suitable for low data contention, write less conflict environment.

      Multi-version concurrency control based concurrency control locks can be combined to solve write - write conflicts that MVCC + 2PL, optimistic concurrency control can also be combined to solve the write - write conflicts.

Guess you like

Origin www.cnblogs.com/qiumingcheng/p/11246386.html
Recommended