Managing a transactional key-value store
A transactional layer involves implementing a concurrency control protocol, as multiple transactions can try to update the same data at the same time, which can result in a conflict. In concurrency control, there are two different ways of dealing with conflicts, as outlined here:
- Avoid conflicts altogether with pessimistic locking—for example, a read/write lock.
- Let the conflict happen but detect it with optimistic locking and resolve it—for example, multi-version concurrency control (MVCC).
CockroachDB uses MVCC. In MVCC, there can be multiple versions of the same record, but you resolve the conflicts before committing the changes.
In CockroachDB, a given transaction is executed in three phases, outlined next:
- A transaction is started with a target range that will participate in the transaction. A new transaction record is created to track the status of the transaction. It will have the initial...