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
相关推荐
木木木一6 小时前
Rust学习记录--C8 常用的集合
开发语言·学习·rust
TDengine (老段)6 小时前
TDengine Rust 连接器入门指南
大数据·数据库·物联网·rust·时序数据库·tdengine·涛思数据
Kapaseker8 小时前
来自 Rust 官网的王婆卖瓜
rust
萧曵 丶20 小时前
Next-Key Lock、记录锁、间隙锁浅谈
数据库·sql·mysql·mvcc·可重复读·幻读
鲁正杰21 小时前
【运维部署】现代化内网穿透与文件共享方案 (Rust)
运维·开发语言·rust
superman超哥1 天前
Rust `‘static` 生命周期:从字面意义到深层语义
开发语言·后端·rust·生命周期·编程语言·rust static·深层语义
半夏知半秋1 天前
rust学习-Option与Result
开发语言·笔记·后端·学习·rust
superman超哥1 天前
Rust 结构体中的生命周期参数:所有权设计的核心抉择
开发语言·后端·rust·rust结构体·rust生命周期·所有权设计
lusasky1 天前
在Windows上编译、安装Rust
开发语言·windows·rust