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: u64Implementations§
Source§impl BlockKey
impl BlockKey
Sourcepub fn new(sstable_id: u64, block_offset: u64) -> Self
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
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§
impl Copy for BlockKey
impl Eq for BlockKey
Source§impl Ord for BlockKey
impl Ord for BlockKey
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for BlockKey
impl PartialOrd for BlockKey
impl StructuralPartialEq for BlockKey
Auto Trait Implementations§
impl Freeze for BlockKey
impl RefUnwindSafe for BlockKey
impl Send for BlockKey
impl Sync for BlockKey
impl Unpin for BlockKey
impl UnsafeUnpin for BlockKey
impl UnwindSafe for BlockKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more