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 15, 2024
1 parent 2c2994a commit 055f966
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 169 deletions.
2 changes: 1 addition & 1 deletion src/storage/kv/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl SerializableSnapshotIsolation {
let current_snapshot = Snapshot::take(&txn.core)?;

// Check read conflicts
for entry in txn.read_set.iter() {
for entry in txn.read_set.lock().unwrap().iter() {
match current_snapshot.get(&entry.key[..].into()) {
Some((_, version)) => {
if entry.ts != version {
Expand Down
19 changes: 3 additions & 16 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
Loading

0 comments on commit 055f966

Please sign in to comment.