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
相关推荐
遇码14 小时前
给 Rust 桌面应用做双击安装包:Windows NSIS setup.exe + macOS DMG 的完整做法
人工智能·windows·ai·rust·大模型
GitCode官方17 小时前
本期精选 Rust 开源项目推荐
开发语言·rust·开源·g-star·atomgit
nezuko3520 小时前
用 AI 把代码改写成 Rust 之后,怎么证明它没改坏?我做了个开源工具
rust
爆米花byh2 天前
在RockyLinux9环境下安装Rust1.100.0环境
linux·rust
hai3152475432 天前
阶乘分层关系模型存储文本与表格
数据结构·算法·rust·排序算法·线性回归
Pniubi2 天前
MVCC实战应用
数据库·mvcc
Shota Kishi2 天前
Solana Stream SDK 的 UDP Shred 接收:data-only 与 recover 两种模式的取舍与实测
rust·区块链·solana
tomatohug2 天前
Tauri v2 实战:做一个贴在任何输入框上的提示词优化助手
rust
Zenova EdgeOS2 天前
Rust 数据库实战:工业边缘场景下的 sqlx
数据库·oracle·rust·边缘计算·工业网关
用户46043852250863 天前
关于paimon- rust的学习 --- Table(一)
大数据·rust