feat: Introduce Hybrid Logical Clocks in protobuf, update architecture documentation, and add HLC test cases.
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "lattice-store"
|
||||
description = "Log-based KV store with snapshots and watermarks"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
lattice-core = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
tokio-test = { workspace = true }
|
||||
@@ -0,0 +1,12 @@
|
||||
//! Lattice Store
|
||||
//!
|
||||
//! Log-based Key-Value store:
|
||||
//! - State is a "view" generated by replaying entries
|
||||
//! - Watermarks for agreeing on safe compaction points
|
||||
//! - Snapshots for replacing old logs
|
||||
|
||||
pub mod store;
|
||||
pub mod snapshot;
|
||||
pub mod watermark;
|
||||
|
||||
pub use store::Store;
|
||||
@@ -0,0 +1,6 @@
|
||||
//! Snapshots for log compaction
|
||||
|
||||
/// A verified snapshot that can replace old log entries.
|
||||
pub struct Snapshot {
|
||||
// TODO: snapshot data, watermark, verification
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
//! The main KV store
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// A log-based Key-Value store.
|
||||
///
|
||||
/// The store is a dynamic "view" generated by replaying entries.
|
||||
pub struct Store {
|
||||
data: HashMap<Vec<u8>, Vec<u8>>,
|
||||
}
|
||||
|
||||
impl Store {
|
||||
/// Create a new empty store.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
data: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a value by key.
|
||||
pub fn get(&self, key: &[u8]) -> Option<&[u8]> {
|
||||
self.data.get(key).map(|v| v.as_slice())
|
||||
}
|
||||
|
||||
/// Set a value (this would normally go through the log).
|
||||
pub fn set(&mut self, key: Vec<u8>, value: Vec<u8>) {
|
||||
self.data.insert(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Store {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
//! Watermarks for agreeing on safe compaction points
|
||||
|
||||
/// A watermark representing a safe cut-off point for log compaction.
|
||||
///
|
||||
/// Nodes use watermarks to agree on which entries can be safely
|
||||
/// deleted and replaced with snapshots.
|
||||
pub struct Watermark {
|
||||
// TODO: watermark data
|
||||
}
|
||||
Reference in New Issue
Block a user