MariaDB Xpand Multi-Version Concurrency Control (MVCC)
MariaDB Xpand implements a distributed Multi-Version Concurrency Control (MVCC) scheme.
This documentation applies to both Xpand topologies.
MariaDB Xpand's Multi-Version Concurrency Control (MVCC) provides many benefits:
It supports lockless reads.
It supports 2-phase locking for writes.
It supports online schema changes.
It maintains version history of row changes in the undo log.
It builds a transaction's snapshot by retrieving the relevant row version from the undo log.
It performs garbage collection of old row versions from the undo log when they are no longer needed for old transactions.
Transaction, Invocation, and Commit IDs
MariaDB Xpand generates several identifiers associated with each transaction, invocation, and commit:
Transaction start identifier. Marks the logical beginning of the transaction.
Invocation identifier. Marks the beginning of each statement within the transaction.
Commit identifier. Marks the id at which transaction changes are visible to other transactions.
The following diagram shows several IDs generated throughout a transaction:
These identifiers affect row visibility. The visibility rules depend on the isolation level. See Using Transaction Isolation Levels with MariaDB Xpand for the specific details.
MariaDB Xpand generates the
iid identifiers using a combination of system wide clock and a unique instance
id to create a globally unique ordered identifier.
Version History in the Undo Log
MariaDB Xpand maintains row version history:
When a row changes, the old version of the row is added to the version history.
Row version history is stored in the undo log.
Each row contains a Log Sequence Number (LSN), which points at the previous version of the row.
If the pointer refers to the trim LSN, then that is the end of the history chain.
The row versions are used to access previous row versions to build a transaction's snapshot.
The row versions are also used to rollback transactions.
The following diagram shows how the system keeps multiple versions of the row in the undo log:
MariaDB Xpand automatically performs garbage collection:
It deletes old row versions from the undo log when they are no longer needed by old transactions.
A row version is no longer needed when its
cidvalue is lower than the lowest
xidvalue of any currently running transactions.
Xpand also performs checkpoints.