pub trait CompactionIndex<K: Key>: Send + Sync {
// Required methods
fn update_if_match(
&self,
key: &K,
old_loc: DiskLoc,
new_loc: DiskLoc,
) -> bool;
fn contains_key(&self, key: &K) -> bool;
fn is_live(&self, shard_id: u8, key: &K, loc: DiskLoc) -> bool;
// Provided method
fn invalidate_blocks(&self, _shard_id: u8, _file_id: u32, _total_bytes: u64) { ... }
}Required Methods§
Sourcefn update_if_match(&self, key: &K, old_loc: DiskLoc, new_loc: DiskLoc) -> bool
fn update_if_match(&self, key: &K, old_loc: DiskLoc, new_loc: DiskLoc) -> bool
If the current index points to old_loc, it is updated to new_loc and returns true.
Sourcefn contains_key(&self, key: &K) -> bool
fn contains_key(&self, key: &K) -> bool
Returns true if the key currently exists in the index (i.e. has a live Put).
Sourcefn is_live(&self, shard_id: u8, key: &K, loc: DiskLoc) -> bool
fn is_live(&self, shard_id: u8, key: &K, loc: DiskLoc) -> bool
Returns true iff the index currently maps key to exactly loc — i.e.
the entry at loc is the live (latest) version of key.
shard_id is the shard being compacted. Every key scanned during a shard’s
compaction routes to that shard, so sharded (map) indexes use shard_id
directly instead of recomputing shard_for(key) per entry; tree indexes
are global and ignore it.
Used by compaction to skip superseded entries before copying them into a
new file. A superseded entry can never become live again (a newer version
with a higher GSN exists), so a false result is permanently safe to act
on even while writers run concurrently. A true result may still race with
a concurrent overwrite; the post-copy update_if_match
CAS is the authoritative guard that re-marks the copy dead if it lost the race.
Provided Methods§
Sourcefn invalidate_blocks(&self, _shard_id: u8, _file_id: u32, _total_bytes: u64)
fn invalidate_blocks(&self, _shard_id: u8, _file_id: u32, _total_bytes: u64)
Invalidate cached blocks for a file after compaction replaces its contents.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".