mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-31 05:44:25 +01:00
docs: Add a section on MVCC internals
This commit is contained in:
@@ -507,6 +507,20 @@ The code generator module takes AST as input and produces virtual machine progra
|
||||
|
||||
### Virtual Machine
|
||||
|
||||
### MVCC
|
||||
|
||||
The database implements a multi-version concurrency control (MVCC) using a hybrid architecture that combines an in-memory index with persistent storage through WAL (Write-Ahead Logging) and SQLite database files. The implementation draws from the Hekaton approach documented in Larson et al. (2011), with key modifications for durability handling.
|
||||
|
||||
The database maintains a centralized in-memory MVCC index that serves as the primary coordination point for all database connections. This index provides shared access across all active connections and stores the most recent versions of modified data. It implements version visibility rules for concurrent transactions following the Hekaton MVCC design. The architecture employs a three-tier storage hierarchy consisting of the MVCC index in memory as the primary read/write target for active transactions, a page cache in memory serving as an intermediate buffer for data retrieved from persistent storage, and persistent storage comprising WAL files and SQLite database files on disk.
|
||||
|
||||
_Read operations_ follow a lazy loading strategy with a specific precedence order. The database first queries the in-memory MVCC index to check if the requested row exists and is visible to the current transaction. If the row is not found in the MVCC index, the system performs a lazy read from the page cache. When necessary, the page cache retrieves data from both the WAL and the underlying SQLite database file.
|
||||
|
||||
_Write operations_ are handled entirely within the in-memory MVCC index during transaction execution. This design provides high-performance writes with minimal latency, immediate visibility of changes within the transaction scope, and isolation from other concurrent transactions until the transaction is committed.
|
||||
|
||||
_Commit operation_ ensures durability through a two-phase approach: first, the system writes the complete transaction write set from the MVCC index to the page cache, then the page cache contents are flushed to the WAL, ensuring durable storage of the committed transaction. This commit protocol guarantees that once a transaction commits successfully, all changes are persisted to durable storage and will survive system failures.
|
||||
|
||||
While the implementation follows Hekaton's core MVCC principles, it differs in one significant aspect regarding logical change tracking. Unlike Hekaton, this system does not maintain a record of logical changes after flushing data to the WAL. This design choice simplifies compatibility with the SQLite database file format.
|
||||
|
||||
### Pager
|
||||
|
||||
TODO
|
||||
@@ -515,4 +529,9 @@ TODO
|
||||
|
||||
TODO
|
||||
|
||||
### References
|
||||
|
||||
Per-Åke Larson et al. "High-Performance Concurrency Control Mechanisms for Main-Memory Databases." In _VLDB '11_
|
||||
|
||||
|
||||
[SQLite]: https://www.sqlite.org/
|
||||
|
||||
Reference in New Issue
Block a user