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
相关推荐
Ramble_Naylor7 小时前
只借不占:Rust 的引用与借用
开发语言·rust
k4m7v2pz11 小时前
交叉编译 Rust 到 aarch64 Linux 掌机:glibc 版本与 sysroot 重建的完整踩坑记录
rust·glibc·交叉编译·aarch64·zigbuild·sysroot
k4m7v2pz15 小时前
用 Rust 重造 Java 的 CLI 分发体验:从 java -jar 到 wasmtime run
rust·跨平台·webassembly·wasmtime·wasi·java-jar
Source.Liu16 小时前
【IT】Rust实现win下系统信息采集工具的开发
rust
MC皮蛋侠客1 天前
Tauri 2.x 系列(八):与其他语言结合——Sidecar、服务、FFI 与插件的选择
rust·tauri
MC皮蛋侠客1 天前
Tauri 2.x 系列(五):调用系统 API——官方插件、Rust crate 与原生能力
开发语言·后端·rust
磐链科技1 天前
钱包开发中的跨平台架构:Flutter与Rust构建高性能移动端钱包
flutter·架构·rust
MC皮蛋侠客2 天前
Tauri 2.x 系列(四):窗口、菜单、托盘与应用生命周期——做出真正的桌面体验
rust·tauri
MC皮蛋侠客2 天前
Tauri 2.x 系列(一):架构全景与最小闭环——从 WebView 到 EMS 后台
架构·rust·tauri