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
相关推荐
疯不皮7 小时前
全网不唯一,但最热心带读Wasm胶水代码!被面试官问到再也不怕啦~
rust·webassembly·trae
关山月12 小时前
Rust 中的 Copy 和 Clone 比较
后端·rust
阳光808813 小时前
体验开源OpenHarmony+stratovirt模拟器
linux·ubuntu·rust·开源
今天也想MK代码13 小时前
rust编程实战:实现3d粒子渲染wasm
开发语言·rust·wasm
关山月1 天前
Rust 中的特性(Trait):从基础到高级
后端·rust
niandb1 天前
The Rust Programming Language 学习 (三)
学习·算法·rust
周万宁.FoBJ1 天前
如何在rust中解析 windows 的 lnk文件(快捷方式)
开发语言·windows·rust
受之以蒙2 天前
Rust并发编程:解锁高效与安全的编程新姿势
笔记·rust
前端付杰3 天前
Sass 模块化革命:深入解析 @use 语法,打造高效 CSS 架构
css·rust·less·sass·scss
weixin_502539853 天前
rust学习笔记12-hashmap与1. 两数之和
笔记·学习·rust