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
相关推荐
大卫小东(Sheldon)8 小时前
大模型智能体 (agent)简易流程介绍
ai·rust
小杍随笔10 小时前
【Rust 语言编程知识与应用:同步机制详解】
开发语言·算法·rust
Rust研习社14 小时前
Rust 错误处理:thiserror 和 anyhow 的使用
rust
RE-190114 小时前
Polars:告别 Pandas 性能瓶颈,用 Rust 驱动的 DataFrame 库处理亿级数据
开发语言·rust·pandas·polars·ai生成
好家伙VCC14 小时前
# 发散创新:用 Rust 实现高性能事件驱动架构的实践与优化 在现代软件系统中,**事件驱动编程模型**已经成为构
java·开发语言·python·架构·rust
Ivanqhz15 小时前
寄存器分配的核心函数 allocate
java·开发语言·后端·python·rust
浪客川16 小时前
godot-rust入门案例
rust·游戏引擎·godot
wenlonglanying1 天前
Windows安装Rust环境(详细教程)
开发语言·windows·rust
Rust研习社1 天前
Rust + WebAssembly 新手完全入门指南
rust
Java水解1 天前
Rust异步缓存系统的设计与实现
后端·rust