Mercurial > lbo > hg > sstable
changeset 108:84e886a16dca
Document the minimal cache size and a test
author | Thomas Krause <krauseto@hu-berlin.de> |
---|---|
date | Mon, 15 Nov 2021 17:07:47 +0100 |
parents | ee818e157e3c |
children | 71a541e117da |
files | src/options.rs src/table_reader.rs |
diffstat | 2 files changed, 24 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/options.rs Mon Nov 15 16:57:48 2021 +0100 +++ b/src/options.rs Mon Nov 15 17:07:47 2021 +0100 @@ -44,7 +44,8 @@ impl Options { /// Returns Options with a custom block cache capacity. - /// The capacity is given as number of items in the cache. + /// The capacity is given as number of items in the cache + /// and the minimal allowed capacity is 1. pub fn with_cache_capacity(mut self, capacity: usize) -> Options { self.block_cache = share(Cache::new(capacity)); self @@ -65,3 +66,4 @@ } } } +
--- a/src/table_reader.rs Mon Nov 15 16:57:48 2021 +0100 +++ b/src/table_reader.rs Mon Nov 15 17:07:47 2021 +0100 @@ -442,6 +442,27 @@ } #[test] + fn test_table_block_tiny_cache() { + let (src, size) = build_table(build_data()); + // Create a table with no block cache + let mut opt = Options::default().with_cache_capacity(1); + opt.block_size = 32; + + let table = Table::new(opt.clone(), wrap_buffer(src), size).unwrap(); + let mut iter = table.iter(); + + // index/metaindex blocks are not cached. That'd be a waste of memory. + assert_eq!(opt.block_cache.read().expect(LOCK_POISONED).count(), 0); + + // We should have at most one item in the cache + iter.next(); + assert_eq!(opt.block_cache.read().expect(LOCK_POISONED).count(), 1); + iter.next(); + assert_eq!(opt.block_cache.read().expect(LOCK_POISONED).count(), 1); + + } + + #[test] fn test_table_iterator_fwd_bwd() { let (src, size) = build_table(build_data()); let data = build_data();