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
相关推荐
栈与堆1 天前
LeetCode 21 - 合并两个有序链表
java·数据结构·python·算法·leetcode·链表·rust
盛者无名1 天前
Rust的所有权(Owenership)
开发语言·rust
BlockChain8881 天前
MPC 钱包实战(三):Rust MPC Node + Java 调度层 + ETH 实际转账(可运行)
java·开发语言·rust
短剑重铸之日1 天前
7天读懂MySQL|特别篇:MVCC详解
数据库·后端·mysql·mvcc
分布式存储与RustFS2 天前
RustFS在AI场景下的实测:从GPU到存储的完整加速方案
开发语言·人工智能·rust·对象存储·企业存储·rustfs·minio国产化替代
柠檬丶抒情2 天前
Rust no_std 裸机移植:9 条避坑与实战手册
开发语言·mongodb·rust
FAFU_kyp2 天前
Rust 流程控制学习教程
学习·算法·rust
FAFU_kyp2 天前
Rust 模式匹配:match 与 if let 详解
开发语言·后端·rust
Mr -老鬼3 天前
Java VS Rust
java·开发语言·rust
张心独酌3 天前
Rust开发案例库-静态服务器
服务器·开发语言·rust