mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-23 18:04:27 +01:00
Move clock code to clock.rs
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::clock::LogicalClock;
|
||||
use crate::errors::DatabaseError;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
@@ -86,31 +87,6 @@ pub struct Database<Clock: LogicalClock> {
|
||||
|
||||
type TxID = u64;
|
||||
|
||||
/// Logical clock.
|
||||
pub trait LogicalClock {
|
||||
fn get_timestamp(&self) -> u64;
|
||||
}
|
||||
|
||||
/// A node-local clock backed by an atomic counter.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct LocalClock {
|
||||
ts_sequence: AtomicU64,
|
||||
}
|
||||
|
||||
impl LocalClock {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
ts_sequence: AtomicU64::new(0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LogicalClock for LocalClock {
|
||||
fn get_timestamp(&self) -> u64 {
|
||||
self.ts_sequence.fetch_add(1, Ordering::SeqCst)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DatabaseInner<Clock: LogicalClock> {
|
||||
rows: RefCell<HashMap<u64, Vec<RowVersion>>>,
|
||||
@@ -441,6 +417,7 @@ fn is_end_visible(txs: &HashMap<TxID, Transaction>, tx: &Transaction, rv: &RowVe
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::clock::LocalClock;
|
||||
|
||||
#[test]
|
||||
fn test_insert_read() {
|
||||
|
||||
@@ -31,5 +31,6 @@
|
||||
//! * Optimistic reads and writes
|
||||
//! * Garbage collection
|
||||
|
||||
pub mod clock;
|
||||
pub mod database;
|
||||
pub mod errors;
|
||||
|
||||
Reference in New Issue
Block a user