From 2603d8d0d04b9711f0229b91781aeb3a122c6363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Sat, 20 Jul 2024 10:44:35 +0200 Subject: [PATCH] Add a way to disable the cache --- milli/src/update/index_documents/cache.rs | 28 ++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/milli/src/update/index_documents/cache.rs b/milli/src/update/index_documents/cache.rs index 338c564e6..0c8799d52 100644 --- a/milli/src/update/index_documents/cache.rs +++ b/milli/src/update/index_documents/cache.rs @@ -11,6 +11,8 @@ use smallvec::SmallVec; use crate::update::del_add::{DelAdd, KvWriterDelAdd}; use crate::CboRoaringBitmapCodec; +const DISABLED: bool = true; + pub struct SorterCacheDelAddCboRoaringBitmap { cache: ArcCache, DelAddRoaringBitmap>, prefix: &'static [u8; 3], @@ -43,6 +45,10 @@ where MF: for<'a> Fn(&[u8], &[Cow<'a, [u8]>]) -> Result, U>, { pub fn insert_del_u32(&mut self, key: &[u8], n: u32) -> Result<(), grenad::Error> { + if DISABLED { + return self.write_entry_to_sorter(key, DelAddRoaringBitmap::new_del_u32(n)); + } + let (cache, evicted) = self.cache.get_mut(key); match cache { Some(DelAddRoaringBitmap { del, add: _ }) => { @@ -67,6 +73,10 @@ where key: &[u8], bitmap: RoaringBitmap, ) -> Result<(), grenad::Error> { + if DISABLED { + return self.write_entry_to_sorter(key, DelAddRoaringBitmap::new_del(bitmap)); + } + let (cache, evicted) = self.cache.get_mut(key); match cache { Some(DelAddRoaringBitmap { del, add: _ }) => { @@ -87,6 +97,10 @@ where } pub fn insert_add_u32(&mut self, key: &[u8], n: u32) -> Result<(), grenad::Error> { + if DISABLED { + return self.write_entry_to_sorter(key, DelAddRoaringBitmap::new_add_u32(n)); + } + let (cache, evicted) = self.cache.get_mut(key); match cache { Some(DelAddRoaringBitmap { del: _, add }) => { @@ -111,6 +125,10 @@ where key: &[u8], bitmap: RoaringBitmap, ) -> Result<(), grenad::Error> { + if DISABLED { + return self.write_entry_to_sorter(key, DelAddRoaringBitmap::new_add(bitmap)); + } + let (cache, evicted) = self.cache.get_mut(key); match cache { Some(DelAddRoaringBitmap { del: _, add }) => { @@ -131,6 +149,10 @@ where } pub fn insert_del_add_u32(&mut self, key: &[u8], n: u32) -> Result<(), grenad::Error> { + if DISABLED { + return self.write_entry_to_sorter(key, DelAddRoaringBitmap::new_del_add_u32(n)); + } + let (cache, evicted) = self.cache.get_mut(key); match cache { Some(DelAddRoaringBitmap { del, add }) => { @@ -151,9 +173,9 @@ where } } - fn write_entry_to_sorter( + fn write_entry_to_sorter>( &mut self, - key: SmallVec<[u8; N]>, + key: A, deladd: DelAddRoaringBitmap, ) -> Result<(), grenad::Error> { self.deladd_buffer.clear(); @@ -182,7 +204,7 @@ where } self.cbo_buffer.clear(); self.cbo_buffer.extend_from_slice(self.prefix); - self.cbo_buffer.extend_from_slice(&key); + self.cbo_buffer.extend_from_slice(key.as_ref()); redis::cmd("INCR").arg(&self.cbo_buffer).query::(&mut self.conn).unwrap(); self.sorter.insert(key, value_writer.into_inner().unwrap()) }