From 0df5f1c926e67c7d626d34a1e17f528d8e7e5164 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 25 Nov 2021 22:03:37 +0800 Subject: [PATCH] fix key de-allocation bug forgot to reduce key count for the dictionary record when a key is removed. --- services/pddb/src/backend/basis.rs | 2 +- services/pddb/src/backend/dictionary.rs | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/services/pddb/src/backend/basis.rs b/services/pddb/src/backend/basis.rs index bc720a577..8cf557481 100644 --- a/services/pddb/src/backend/basis.rs +++ b/services/pddb/src/backend/basis.rs @@ -1010,7 +1010,7 @@ impl BasisCacheEntry { free_key_index: dict.last_disk_key_index, name: dict_name, }; - log::trace!("syncing dict {}", name); + log::info!("syncing dict {} with {} keys", name, dict.key_count); // log::info!("raw: {:x?}", dict_disk.deref()); // observation: all keys to be flushed to disk will be in the KeyCacheEntry. Some may be clean, // but definitely all the dirty ones are in there (if they aren't, where else would they be??) diff --git a/services/pddb/src/backend/dictionary.rs b/services/pddb/src/backend/dictionary.rs index 07b8c1c1f..b9f6a3623 100644 --- a/services/pddb/src/backend/dictionary.rs +++ b/services/pddb/src/backend/dictionary.rs @@ -621,18 +621,12 @@ impl DictCacheEntry { let mut need_free_key: Option = None; if let Some(kcache) = self.keys.get_mut(&name) { self.clean = false; + self.key_count -= 1; if let Some(small_index) = small_storage_index_from_key(kcache, self.index) { // handle the small pool case let ksp = &mut self.small_pool[small_index]; - log::info!("victim: {}", name); - for s in &ksp.contents { - log::info!("before: {}", s); - } ksp.contents.swap_remove(ksp.contents.iter().position(|s| *s == name) .expect("Small pool did not contain the element we expected")); - for s in &ksp.contents { - log::info!("after: {}", s); - } assert!(kcache.reserved <= SMALL_CAPACITY as u64, "error in small key entry size"); ksp.avail += kcache.reserved as u16; assert!(ksp.avail <= SMALL_CAPACITY as u16, "bookkeeping error in small pool capacity");