5 个不稳定版本
0.4.1 | 2023年6月22日 |
---|---|
0.4.0 | 2023年1月5日 |
0.3.0 | 2022年12月6日 |
0.1.2 | 2022年10月1日 |
#431 在 并发 中
每月下载量60
在 7 个 Crate 中使用(直接使用6个)
64KB
1K SLoC
Datacake CRDT
Riak 的 ORSWOT CRDT 的实现,这是一个允许在观察到新事件后删除旧墓碑的 CRDT
该集合基于第二个支持的结构 HLCTimestamp
,这是一个混合逻辑时钟,它保证了时间戳始终是唯一和单调的(前提是正确使用。)
基本示例
use std::time::Duration;
use datacake_crdt::{OrSWotSet, HLCTimestamp};
fn main() {
let mut node_a = HLCTimestamp::now(0, 0);
// Simulating a node begin slightly ahead in time.
let mut node_b = HLCTimestamp::new(node_a.datacake_timestamp() + Duration::from_secs(5), 0, 1);
let mut node_a_set = OrSWotSet::default();
let mut node_b_set = OrSWotSet::default();
// Insert a new key with a new timestamp in set A.
node_a_set.insert(1, node_a.send().unwrap());
// Insert a new entry in set B.
node_b_set.insert(2, node_b.send().unwrap());
// Let some time pass for demonstration purposes.
std::thread::sleep(Duration::from_millis(500));
// Set A has key `1` removed.
node_a_set.delete(1, node_a.send().unwrap());
// Merging set B with set A and vice versa.
// Our sets are now aligned without conflicts.
node_b_set.merge(node_a_set.clone());
node_a_set.merge(node_b_set.clone());
// Set A and B should both see that key `1` has been deleted.
assert!(node_a_set.get(&1).is_none(), "Key should be correctly removed.");
assert!(node_b_set.get(&1).is_none(), "Key should be correctly removed.");
}
灵感来源
依赖项
~0.3–1MB
~23K SLoC