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
相关推荐
muyouking115 小时前
4.Rust+Axum Tower 中间件实战:从集成到自定义
开发语言·中间件·rust
Source.Liu6 小时前
【TeamFlow】4.2 Yew库详细介绍
rust·yew
勇敢牛牛_6 小时前
【MRAG】使用RAG技术增强AI回复的实时性和准确性
rust·知识库·rag
techdashen9 小时前
性能比拼: Rust vs Zig vs Go
开发语言·golang·rust
muyouking1112 小时前
9.Rust+Axum 测试驱动开发与性能优化全攻略
驱动开发·性能优化·rust
阿阳热爱前端14 小时前
BongoCat 桌宠全新升级!开源 × 跨平台,快来撸猫!
前端·rust·app
阿廖沙102419 小时前
前端开发工程师的Rust入门
rust
pumpkin845141 天前
学习笔记十七——Rust 支持面向对象编程吗?
笔记·学习·rust
Source.Liu1 天前
【TeamFlow】3 Rust 与 WebAssembly (Wasm) 深度应用指南
rust·wasm
CHQIUU1 天前
【Rust 精进之路之第5篇-数据基石·下】复合类型:元组 (Tuple) 与数组 (Array) 的定长世界
rust