mirror of https://github.com/spacejam/sled
Improve verification subsystem
This commit is contained in:
parent
2647942831
commit
947131e11b
|
@ -63,12 +63,18 @@ impl EventVerifier {
|
|||
let history = flush_model.entry(object_id).or_default();
|
||||
|
||||
if let Some((last_state, _epoch, _at)) = history.last() {
|
||||
assert!(
|
||||
last_state.can_transition_to(state),
|
||||
"object_id {object_id:?} performed \
|
||||
illegal state transition from {last_state:?} to {state:?} at {at} in epoch {epoch:?}.\nhistory: {:#?}",
|
||||
*history
|
||||
);
|
||||
if !last_state.can_transition_to(state) {
|
||||
println!(
|
||||
"object_id {object_id:?} performed \
|
||||
illegal state transition from {last_state:?} \
|
||||
to {state:?} at {at} in epoch {epoch:?}."
|
||||
);
|
||||
|
||||
println!("history:");
|
||||
for (last_state, epoch, at) in history.iter() {
|
||||
println!("{last_state:?} {epoch:?} {at}");
|
||||
}
|
||||
}
|
||||
}
|
||||
history.push((state, epoch, at));
|
||||
}
|
||||
|
@ -76,6 +82,9 @@ impl EventVerifier {
|
|||
pub(crate) fn print_debug_history_for_object(&self, object_id: ObjectId) {
|
||||
let flush_model = self.flush_model.lock().unwrap();
|
||||
let history = flush_model.get(&object_id).unwrap();
|
||||
println!("history for object {:?}: {:#?}", object_id, history);
|
||||
println!("history for object {:?}:", object_id);
|
||||
for (last_state, epoch, at) in history.iter() {
|
||||
println!("{last_state:?} {epoch:?} {at}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -287,10 +287,10 @@ impl<const LEAF_FANOUT: usize> ObjectCache<LEAF_FANOUT> {
|
|||
#[cfg(feature = "for-internal-testing-only")]
|
||||
{
|
||||
self.event_verifier.mark(
|
||||
object_id,
|
||||
node.object_id,
|
||||
None,
|
||||
event_verifier::State::PagedOut,
|
||||
concat!(file!(), ':', line!(), ":paging-out"),
|
||||
concat!(file!(), ':', line!(), ":page-out"),
|
||||
);
|
||||
}
|
||||
*write = None;
|
||||
|
@ -361,19 +361,18 @@ impl<const LEAF_FANOUT: usize> ObjectCache<LEAF_FANOUT> {
|
|||
|
||||
match dirty_value {
|
||||
Dirty::MergedAndDeleted { object_id, collection_id } => {
|
||||
assert_eq!(object_id, dirty_object_id);
|
||||
|
||||
log::trace!(
|
||||
"MergedAndDeleted for {:?}, adding None to write_batch",
|
||||
object_id
|
||||
);
|
||||
write_batch.push(Update::Free {
|
||||
object_id: dirty_object_id,
|
||||
collection_id,
|
||||
});
|
||||
write_batch.push(Update::Free { object_id, collection_id });
|
||||
|
||||
#[cfg(feature = "for-internal-testing-only")]
|
||||
{
|
||||
self.event_verifier.mark(
|
||||
dirty_object_id,
|
||||
object_id,
|
||||
Some(dirty_epoch),
|
||||
event_verifier::State::CleanPagedIn,
|
||||
concat!(
|
||||
|
@ -607,7 +606,12 @@ impl<const LEAF_FANOUT: usize> ObjectCache<LEAF_FANOUT> {
|
|||
node_to_evict.object_id,
|
||||
Some(flush_through_epoch),
|
||||
event_verifier::State::PagedOut,
|
||||
concat!(file!(), ':', line!()),
|
||||
concat!(
|
||||
file!(),
|
||||
':',
|
||||
line!(),
|
||||
":page-out-after-flush"
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
41
src/tree.rs
41
src/tree.rs
|
@ -306,14 +306,14 @@ impl<const LEAF_FANOUT: usize> Tree<LEAF_FANOUT> {
|
|||
{
|
||||
self.cache.event_verifier.mark(
|
||||
predecessor_guard.node.object_id,
|
||||
None,
|
||||
Some(merge_epoch),
|
||||
event_verifier::State::Dirty,
|
||||
concat!(file!(), ':', line!(), ":merged-into"),
|
||||
);
|
||||
|
||||
self.cache.event_verifier.mark(
|
||||
leaf_guard.node.object_id,
|
||||
None,
|
||||
Some(merge_epoch),
|
||||
event_verifier::State::Unallocated,
|
||||
concat!(file!(), ':', line!(), ":merged"),
|
||||
);
|
||||
|
@ -340,16 +340,6 @@ impl<const LEAF_FANOUT: usize> Tree<LEAF_FANOUT> {
|
|||
},
|
||||
);
|
||||
|
||||
#[cfg(feature = "for-internal-testing-only")]
|
||||
{
|
||||
self.cache.event_verifier.mark(
|
||||
leaf_guard.node.object_id,
|
||||
None,
|
||||
event_verifier::State::Dirty,
|
||||
concat!(file!(), ':', line!(), ":merged-into-sibling"),
|
||||
);
|
||||
}
|
||||
|
||||
self.cache.install_dirty(
|
||||
merge_epoch,
|
||||
predecessor_guard.node.object_id,
|
||||
|
@ -360,16 +350,6 @@ impl<const LEAF_FANOUT: usize> Tree<LEAF_FANOUT> {
|
|||
},
|
||||
);
|
||||
|
||||
#[cfg(feature = "for-internal-testing-only")]
|
||||
{
|
||||
self.cache.event_verifier.mark(
|
||||
predecessor_guard.node.object_id,
|
||||
None,
|
||||
event_verifier::State::Dirty,
|
||||
concat!(file!(), ':', line!(), ":received-merge-from-sibling"),
|
||||
);
|
||||
}
|
||||
|
||||
let (p_object_id, p_sz) =
|
||||
predecessor_guard.handle_cache_access_and_eviction_externally();
|
||||
let (s_object_id, s_sz) =
|
||||
|
@ -506,7 +486,7 @@ impl<const LEAF_FANOUT: usize> Tree<LEAF_FANOUT> {
|
|||
{
|
||||
self.cache.event_verifier.mark(
|
||||
node.object_id,
|
||||
None,
|
||||
Some(old_flush_epoch),
|
||||
event_verifier::State::CleanPagedIn,
|
||||
concat!(
|
||||
file!(),
|
||||
|
@ -545,21 +525,6 @@ impl<const LEAF_FANOUT: usize> Tree<LEAF_FANOUT> {
|
|||
},
|
||||
);
|
||||
|
||||
#[cfg(feature = "for-internal-testing-only")]
|
||||
{
|
||||
self.cache.event_verifier.mark(
|
||||
node.object_id,
|
||||
None,
|
||||
event_verifier::State::Dirty,
|
||||
concat!(
|
||||
file!(),
|
||||
':',
|
||||
line!(),
|
||||
":cooperative-serialize"
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
old_flush_epoch.increment(),
|
||||
flush_epoch_guard.epoch(),
|
||||
|
|
Loading…
Reference in New Issue