Skip to main content

BlockKey

Struct BlockKey 

Source
pub struct BlockKey {
    pub sstable_id: u64,
    pub block_offset: u64,
}
Expand description

Cache lookup key: (sstable id, block byte offset within the file).

Fields§

§sstable_id: u64§block_offset: u64

Implementations§

Source§

impl BlockKey

Source

pub fn new(sstable_id: u64, block_offset: u64) -> Self

Examples found in repository?
examples/perf_features.rs (line 560)
546fn feature_block_cache(manifest: &mut SubMsFeatureManifest, base_p50: u64) {
547    use std::sync::Arc;
548    use subms_lsm_tree::{Block, BlockCache, BlockKey, LruBlockCache};
549
550    // Capacity scales with the tree and the cache is filled to it, so the
551    // occupied fraction is the same at every sweep point. A fixed 1024 slots
552    // would hold the hash map at one size while claiming to sweep the tree.
553    // One shared `Arc<[u8]>` payload keeps 64k cached blocks in memory instead
554    // of 256 MB of identical bytes; the cache stores the pointer either way.
555    fn filled(n: usize) -> (LruBlockCache, usize) {
556        let cap = (n / KEYS_PER_BLOCK).max(64);
557        let cache = LruBlockCache::new(cap);
558        let block: Block = Arc::from(representative_block().into_boxed_slice());
559        for i in 0..cap as u64 {
560            cache.put(BlockKey::new(i % 8, i * BLOCK_BYTES as u64), block.clone());
561        }
562        (cache, cap)
563    }
564
565    let sw = sweep("block-cache-integration/get_cached", |n| {
566        let (cache, cap) = filled(n);
567        let keys: Vec<BlockKey> = (0..OPS)
568            .map(|i| {
569                let k = probe(i, cap) as u64;
570                BlockKey::new(k % 8, k * BLOCK_BYTES as u64)
571            })
572            .collect();
573        keyed(|i| _ = black_box(cache.get(&keys[i])), true)
574    });
575    let (cat, reason) = classify_feature(&sw, Some(base_p50), None);
576
577    let (cache, cap) = filled(CANON_N);
578    let hits: Vec<BlockKey> = (0..OPS)
579        .map(|i| {
580            let k = probe(i, cap) as u64;
581            BlockKey::new(k % 8, k * BLOCK_BYTES as u64)
582        })
583        .collect();
584    let misses: Vec<BlockKey> = (0..OPS)
585        .map(|i| BlockKey::new(999, probe(i, cap) as u64))
586        .collect();
587    let mut p99 = BTreeMap::new();
588    p99.insert(
589        "get_cached".to_string(),
590        keyed(|i| _ = black_box(cache.get(&hits[i])), false),
591    );
592    p99.insert(
593        "get_miss".to_string(),
594        keyed(|i| _ = black_box(cache.get(&misses[i])), false),
595    );
596    manifest.set_feature("block-cache-integration", cat, &p99, &reason);
597}
More examples
Hide additional examples
examples/sample_app.rs (line 313)
309fn block_cache_read_path() {
310    use subms_lsm_tree::{Block, BlockCache, BlockKey, LruBlockCache};
311    println!("\n== block-cache-integration: read-side block cache ==");
312    let cache = LruBlockCache::new(2);
313    let hot = BlockKey::new(1, 0);
314
315    assert!(cache.get(&hot).is_none(), "cold: a miss");
316    cache.put(hot, Block::from(b"AAPL block".as_slice()));
317    let served = cache.get(&hot).expect("warm: a hit");
318    println!(
319        "  {} hit / {} miss after one warm read",
320        cache.hits(),
321        cache.misses()
322    );
323    assert_eq!(&*served, b"AAPL block", "the cached payload is served");
324
325    // A third distinct block evicts the least-recently-used entry (cap 2).
326    cache.put(BlockKey::new(2, 0), Block::from(b"MSFT block".as_slice()));
327    cache.put(BlockKey::new(3, 0), Block::from(b"GOOG block".as_slice()));
328    assert!(
329        cache.get(&hot).is_none(),
330        "coldest block evicted at capacity"
331    );
332}

Trait Implementations§

Source§

impl Clone for BlockKey

Source§

fn clone(&self) -> BlockKey

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for BlockKey

Source§

impl Debug for BlockKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for BlockKey

Source§

impl Hash for BlockKey

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for BlockKey

Source§

fn cmp(&self, other: &BlockKey) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for BlockKey

Source§

fn eq(&self, other: &BlockKey) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for BlockKey

Source§

fn partial_cmp(&self, other: &BlockKey) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for BlockKey

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.