diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2024-10-07 23:53:54 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2024-10-07 23:53:54 +0300 |
| commit | 771237f961f5148060c1d0606e4671552954176e (patch) | |
| tree | f611923245f143b5ca392aaaa310d55a4aa8cde7 /log_db/src/primary_memtable.rs | |
| parent | b6cc16f3301251f5d48f354120c2b6dde9bd3e6c (diff) | |
Only store primary keys in secondary index sets
Diffstat (limited to 'log_db/src/primary_memtable.rs')
| -rw-r--r-- | log_db/src/primary_memtable.rs | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/log_db/src/primary_memtable.rs b/log_db/src/primary_memtable.rs index 0c94ceb..141238f 100644 --- a/log_db/src/primary_memtable.rs +++ b/log_db/src/primary_memtable.rs @@ -3,15 +3,29 @@ use priority_queue::PriorityQueue; use std::collections::BTreeMap; pub struct PrimaryMemtable { + /// Maximum number of records that can be stored in the memtable + /// before evicting the oldest records. The oldest record is + /// determined by the `evict_policy`. capacity: usize, - /// Running counter of memtable operations, used as priority - /// in evict_queue. - n_operations: u64, + /// Map of records indexed by key. Used as a shared heap of records + /// for all secondary memtables also. Secondary memtables store an + /// IndexableValue as their record value, which is used to get + /// the actual record from the primary memtable `records` map. + /// + /// Note: it must be invariant that all memtables (primary and secondary) + /// contain the same keys. records: BTreeMap<IndexableValue, Record>, - /// A max heap priority queue of keys. Note: n_operations must - /// be negated upon append to evict oldest values first. + /// A max heap priority queue of keys. The record with least priority is evicted + /// from the primary memtable and any secondary memtables that reference it, when + /// the memtable reaches capacity. + /// + /// Note: n_operations must be negated upon append to evict oldest values first. evict_queue: PriorityQueue<IndexableValue, i64>, + /// Policy for prioritizing records for eviction. evict_policy: MemtableEvictPolicy, + /// Running counter of memtable operations, used as priority + /// in evict_queue. + n_operations: u64, } impl PrimaryMemtable { @@ -59,6 +73,10 @@ impl PrimaryMemtable { self.records.get(key) } + pub fn get_without_update(&self, key: &IndexableValue) -> Option<&Record> { + self.records.get(key) + } + fn set_priority(&mut self, key: &IndexableValue) { let priority = self.get_and_increment_current_priority(); match self.evict_queue.get(key) { |
