mvcc_cell code review

mvcc_cell code review

(Jin Qing's Column, Aug., 2024)

mvcc_cell: Software-transactional memory for Rust

Downloads: 1,475

Transactions are fully isolated and serialized:

  • Each transaction sees a fixed snapshot
  • Any concurrent commits will be prevented

Example:

rust 复制代码
let mvcc = Mvcc::new();

// Create a transactional slot
let slot = MvccCell::new(&mvcc, Box::new(0));

// Start concurrent transactions
let mut t1 = mvcc.begin();
let mut t2 = mvcc.begin();

// Uncommitted values are not visible outside the transaction
t1[&slot] = 42;
assert_eq!(t2[&slot], 0);

// First committer wins, regardless of actual modification order
t2[&slot] = 7;
assert!(t2.try_commit().is_ok());
assert!(t1.try_commit().is_err());

// Transactions always read the values that were current when
// begin() was called.
assert_eq!(mvcc.begin()[&slot], 7);

Features

  • The minimal implementation of MVCC
  • Uses 2 transaction IDs: begin ID and commit ID
    • 2 transactions can have the same begin ID
    • Commit will increase the global transaction ID
      • TxnId only increased on commit
    • Any overlap of 2 transactions is regarded as confliction
  • MvccCell stores a value with its history and pending writings
  • Snapshot isolation: reading and writing are within the snapshot
  • Non-blocking: no lock on reading and writing
  • Transaction
    • The ID of a transaction is private
    • Transaction is not Send nor Sync
  • Not two-phase commit: try_commit() will commit
  • Writing implies reading
    • Low Performance: any concurrent read or write to the same slot will fail
  • Consistency: Serializable
  • Vacuum can cleanup the history
相关推荐
星释20 小时前
Rust 练习册 111:构建锦标赛积分榜系统
开发语言·后端·rust
蜂蜜黄油呀土豆1 天前
MySQL Undo Log 深度解析:表空间、MVCC、回滚机制与版本演进全解
数据库·mysql·innodb·redo log·mvcc·undo log·事务日志
星释1 天前
Rust 练习册 116:杂志剪贴侦探游戏
开发语言·后端·rust
星释1 天前
Rust 练习册 113:构建你自己的 CSV 处理器
开发语言·windows·rust
wadesir1 天前
高效存储与访问:Rust语言三角矩阵压缩(从零开始掌握Rust稀疏矩阵存储技巧)
算法·矩阵·rust
Eighteenzi1 天前
REVM 解析 3 --- 新版本v97 的解析
rust·revm
poemyang1 天前
像Git一样管理数据:深入解析数据库并发控制MVCC的实现
mysql·事务·mvcc
小灰灰搞电子2 天前
Rust 动态分发(dyn Trait)详解
开发语言·后端·rust
爱学习的小可爱卢2 天前
编程语言30年:从Java到Rust的进化史
java·开发语言·rust
archko2 天前
用rust写了一个桌面app,就不再想用kmp了
开发语言·后端·rust