Skip to content

Commit

Permalink
Do not store writes in the snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
gsserge committed Dec 16, 2024
1 parent 2c2994a commit 85316bc
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 169 deletions.
21 changes: 4 additions & 17 deletions src/storage/kv/snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use std::ops::RangeBounds;
use vart::{art::QueryType, art::Tree, iter::Iter, VariableSizeKey};

use crate::storage::{
kv::error::{Error, Result},
kv::indexer::IndexValue,
kv::store::Core,
kv::util::now,
};

use vart::{art::QueryType, art::Tree, iter::Iter, VariableSizeKey};

/// A versioned snapshot for snapshot isolation.
pub(crate) struct Snapshot {
snap: Tree<VariableSizeKey, IndexValue>,
Expand Down Expand Up @@ -39,17 +37,6 @@ impl Snapshot {
})
}

/// Set a key-value pair into the snapshot.
pub(crate) fn set(&mut self, key: &VariableSizeKey, value: IndexValue) {
self.snap
.insert(key, value, self.version, now())
.expect("incorrect snapshot version");
}

pub(crate) fn delete(&mut self, key: &VariableSizeKey) -> bool {
self.snap.remove(key)
}

/// Retrieves the latest value associated with the given key from the snapshot.
pub(crate) fn get(&self, key: &VariableSizeKey) -> Option<(IndexValue, u64)> {
self.snap
Expand All @@ -59,11 +46,11 @@ impl Snapshot {
}

/// Retrieves the value associated with the given key at the given timestamp from the snapshot.
pub(crate) fn get_at_ts(&self, key: &VariableSizeKey, ts: u64) -> Option<IndexValue> {
pub(crate) fn get_at_ts(&self, key: &VariableSizeKey, ts: u64) -> Option<(IndexValue, u64)> {
self.snap
.get_at_ts(key, ts)
.filter(|(val, _, _)| !val.deleted())
.map(|(val, _, _)| val)
.map(|(val, _, ts)| (val, ts))
}

/// Retrieves the version history of the value associated with the given key from the snapshot.
Expand Down Expand Up @@ -201,7 +188,7 @@ mod tests {

// Test keys_at_ts
let ts = now();
let txn = store
let mut txn = store
.begin_with_mode(Mode::ReadOnly)
.expect("Failed to begin transaction");

Expand Down
Loading

0 comments on commit 85316bc

Please sign in to comment.