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
相关推荐
美味小鱼40 分钟前
实践Rust:编写一个猜数字游戏
开发语言·游戏·rust
SomeB1oody5 小时前
【Rust自学】15.6. RefCell与内部可变性:“摆脱”安全性限制
开发语言·后端·rust
扎量丙不要犟6 小时前
跨平台的客户端gui到底是选“原生”还是web
前端·javascript·c++·qt·rust·electron·tauri
许野平11 小时前
在Rust应用中访问.ini格式的配置文件
rust·配置文件·ini
扎量丙不要犟12 小时前
rust如何操作sqlserver
数据库·sqlserver·rust·tiberius
扎量丙不要犟1 天前
rust如何操作oracle
数据库·oracle·rust
SomeB1oody1 天前
【Rust】18.2. 可辩驳性:模式是否会无法匹配
开发语言·后端·rust
Source.Liu1 天前
5 长度和距离计算模块(length.rs)
rust·euclid
Source.Liu1 天前
6 齐次坐标模块(homogen.rs)
rust·euclid
扎量丙不要犟1 天前
rust跨平台调用动态库
开发语言·后端·rust