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 01cf6cd commit dc0ab9d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 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
35 changes: 33 additions & 2 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 @@ -570,7 +570,38 @@ impl WritebackCache {
) -> CacheResult<(SequenceNumber, ObjectEntry)> {
self.metrics
.record_cache_request(request_type, "object_by_id");
if let Some(entry) = self.cached.object_by_id_cache.get(object_id) {
let entry = self.cached.object_by_id_cache.get(object_id);

if cfg!(debug_assertions) {
if let Some(entry) = &entry {
// check that cache is coherent
let highest: Option<ObjectEntry> = self
.dirty
.objects
.get(object_id)
.and_then(|entry| entry.get_highest().map(|(_, o)| o.clone()))
.or_else(|| {
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, entry) => Some(entry.clone()),
LatestObjectCacheEntry::NonExistent => None,
},
"object_by_id cache is incoherent for {:?}",
object_id
);
}
}

if let Some(entry) = entry {
let entry = entry.lock();
match &*entry {
LatestObjectCacheEntry::Object(latest_version, latest_object) => {
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 dc0ab9d

Please sign in to comment.