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
相关推荐
yezipi耶不耶8 小时前
Rust入门之并发编程基础(三)
rust
SoniaChen3319 小时前
Rust基础[part4]_基本类型,所有权
开发语言·后端·rust
will_csdn_go19 小时前
祺洛后台管理 Rust Cross 交叉编译环境配置指南
开发语言·后端·rust
Source.Liu20 小时前
【unitrix】 6.5 基础整数类型特征(base_int.rs)
rust
PaytonD21 小时前
基于 iced 实现一个简易时钟
rust
Humbunklung1 天前
Rust 模块系统:控制作用域与私有性
开发语言·后端·rust
毒鸡蛋2 天前
Rust 基础大纲
rust
songroom2 天前
【转】Rust: PhantomData,#may_dangle和Drop Check 真真假假
开发语言·后端·rust
红尘散仙2 天前
Rust 终端 UI 开发新玩法:用 Ratatui Kit 轻松打造高颜值 CLI
前端·后端·rust
我是前端小学生3 天前
solana_business_card合约解析
rust