Skip to content

Commit

Permalink
Add coherency debug check for object_by_id_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
mystenmark committed May 30, 2024
1 parent 52ce620 commit 3908cb0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
1 change: 0 additions & 1 deletion crates/sui-core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,6 @@ impl AuthorityStore {
objects: &[ObjectRef],
is_force_reset: bool,
) -> SuiResult {
trace!(?objects, "initialize_locks");
AuthorityStore::initialize_live_object_markers(
&self.perpetual_tables.live_owned_object_markers,
write_batch,
Expand Down
20 changes: 13 additions & 7 deletions crates/sui-core/src/execution_cache/writeback_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ impl WritebackCache {
version: SequenceNumber,
object: ObjectEntry,
) {
debug!("inserting object entry {:?}: {:?}", object_id, version);
debug!("inserting object entry {:?}", object);
fail_point_async!("write_object_entry");
self.metrics.record_cache_write("object");
self.dirty
Expand Down Expand Up @@ -575,22 +575,28 @@ impl WritebackCache {
if cfg!(debug_assertions) {
if let Some(entry) = &entry {
// check that cache is coherent
let highest = self
let highest: Option<ObjectEntry> = self
.dirty
.objects
.get(object_id)
.and_then(|entry| entry.get_highest().map(|(version, _)| *version))
.and_then(|entry| entry.get_highest().map(|(_, o)| o.clone()))
.or_else(|| {
let object = self.store.get_object(object_id).unwrap();
object.map(|o| o.version())
let obj: Option<ObjectEntry> = self
.store
.get_latest_object_or_tombstone(*object_id)
.unwrap()
.map(|(_, o)| o.into());
obj
});

assert_eq!(
highest,
match &*entry.lock() {
LatestObjectCacheEntry::Object(version, _) => Some(*version),
LatestObjectCacheEntry::Object(version, entry) => Some(entry.clone()),
LatestObjectCacheEntry::NonExistent => None,
}
},
"object_by_id cache is incoherent for {:?}",
object_id
);
}
}
Expand Down
9 changes: 9 additions & 0 deletions crates/sui-types/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,15 @@ pub enum ObjectOrTombstone {
Tombstone(ObjectRef),
}

impl ObjectOrTombstone {
pub fn as_objref(&self) -> ObjectRef {
match self {
ObjectOrTombstone::Object(obj) => obj.compute_object_reference(),
ObjectOrTombstone::Tombstone(obref) => *obref,
}
}
}

impl From<Object> for ObjectOrTombstone {
fn from(object: Object) -> Self {
ObjectOrTombstone::Object(object)
Expand Down

0 comments on commit 3908cb0

Please sign in to comment.