mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-27 04:25:06 +08:00
Prefix Redis keys to avoid false negative excessive writes
This commit is contained in:
parent
0e08906fcb
commit
16b4545d23
@ -11,6 +11,7 @@ use crate::CboRoaringBitmapCodec;
|
|||||||
|
|
||||||
pub struct SorterCacheDelAddCboRoaringBitmap<const N: usize, MF> {
|
pub struct SorterCacheDelAddCboRoaringBitmap<const N: usize, MF> {
|
||||||
cache: LruCache<SmallVec<[u8; N]>, DelAddRoaringBitmap>,
|
cache: LruCache<SmallVec<[u8; N]>, DelAddRoaringBitmap>,
|
||||||
|
prefix: &'static [u8; 3],
|
||||||
sorter: grenad::Sorter<MF>,
|
sorter: grenad::Sorter<MF>,
|
||||||
deladd_buffer: Vec<u8>,
|
deladd_buffer: Vec<u8>,
|
||||||
cbo_buffer: Vec<u8>,
|
cbo_buffer: Vec<u8>,
|
||||||
@ -18,9 +19,15 @@ pub struct SorterCacheDelAddCboRoaringBitmap<const N: usize, MF> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize, MF> SorterCacheDelAddCboRoaringBitmap<N, MF> {
|
impl<const N: usize, MF> SorterCacheDelAddCboRoaringBitmap<N, MF> {
|
||||||
pub fn new(cap: NonZeroUsize, sorter: grenad::Sorter<MF>, conn: redis::Connection) -> Self {
|
pub fn new(
|
||||||
|
cap: NonZeroUsize,
|
||||||
|
sorter: grenad::Sorter<MF>,
|
||||||
|
prefix: &'static [u8; 3],
|
||||||
|
conn: redis::Connection,
|
||||||
|
) -> Self {
|
||||||
SorterCacheDelAddCboRoaringBitmap {
|
SorterCacheDelAddCboRoaringBitmap {
|
||||||
cache: LruCache::new(cap),
|
cache: LruCache::new(cap),
|
||||||
|
prefix,
|
||||||
sorter,
|
sorter,
|
||||||
deladd_buffer: Vec::new(),
|
deladd_buffer: Vec::new(),
|
||||||
cbo_buffer: Vec::new(),
|
cbo_buffer: Vec::new(),
|
||||||
@ -136,7 +143,10 @@ where
|
|||||||
}
|
}
|
||||||
DelAddRoaringBitmap { del: None, add: None } => return Ok(()),
|
DelAddRoaringBitmap { del: None, add: None } => return Ok(()),
|
||||||
}
|
}
|
||||||
redis::cmd("INCR").arg(key.as_ref()).query::<usize>(&mut self.conn).unwrap();
|
self.cbo_buffer.clear();
|
||||||
|
self.cbo_buffer.extend_from_slice(self.prefix);
|
||||||
|
self.cbo_buffer.extend_from_slice(&key);
|
||||||
|
redis::cmd("INCR").arg(&self.cbo_buffer).query::<usize>(&mut self.conn).unwrap();
|
||||||
self.sorter.insert(key, value_writer.into_inner().unwrap())
|
self.sorter.insert(key, value_writer.into_inner().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ pub fn extract_facet_number_docids<R: io::Read + io::Seek>(
|
|||||||
SorterCacheDelAddCboRoaringBitmap::<20, MergeFn>::new(
|
SorterCacheDelAddCboRoaringBitmap::<20, MergeFn>::new(
|
||||||
NonZeroUsize::new(20).unwrap(),
|
NonZeroUsize::new(20).unwrap(),
|
||||||
facet_number_docids_sorter,
|
facet_number_docids_sorter,
|
||||||
|
b"fnd",
|
||||||
super::REDIS_CLIENT.get_connection().unwrap(),
|
super::REDIS_CLIENT.get_connection().unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -48,6 +48,7 @@ pub fn extract_facet_string_docids<R: io::Read + io::Seek>(
|
|||||||
SorterCacheDelAddCboRoaringBitmap::<20, MergeFn>::new(
|
SorterCacheDelAddCboRoaringBitmap::<20, MergeFn>::new(
|
||||||
NonZeroUsize::new(200).unwrap(),
|
NonZeroUsize::new(200).unwrap(),
|
||||||
facet_string_docids_sorter,
|
facet_string_docids_sorter,
|
||||||
|
b"fsd",
|
||||||
REDIS_CLIENT.get_connection().unwrap(),
|
REDIS_CLIENT.get_connection().unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ pub fn extract_fid_word_count_docids<R: io::Read + io::Seek>(
|
|||||||
SorterCacheDelAddCboRoaringBitmap::<20, MergeFn>::new(
|
SorterCacheDelAddCboRoaringBitmap::<20, MergeFn>::new(
|
||||||
NonZeroUsize::new(300).unwrap(),
|
NonZeroUsize::new(300).unwrap(),
|
||||||
fid_word_count_docids_sorter,
|
fid_word_count_docids_sorter,
|
||||||
|
b"fwc",
|
||||||
super::REDIS_CLIENT.get_connection().unwrap(),
|
super::REDIS_CLIENT.get_connection().unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ pub fn extract_word_docids<R: io::Read + io::Seek>(
|
|||||||
let mut cached_word_fid_docids_sorter = SorterCacheDelAddCboRoaringBitmap::<20, _>::new(
|
let mut cached_word_fid_docids_sorter = SorterCacheDelAddCboRoaringBitmap::<20, _>::new(
|
||||||
NonZeroUsize::new(300).unwrap(),
|
NonZeroUsize::new(300).unwrap(),
|
||||||
word_fid_docids_sorter,
|
word_fid_docids_sorter,
|
||||||
|
b"wfd",
|
||||||
REDIS_CLIENT.get_connection().unwrap(),
|
REDIS_CLIENT.get_connection().unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -112,6 +113,7 @@ pub fn extract_word_docids<R: io::Read + io::Seek>(
|
|||||||
let mut cached_word_docids_sorter = SorterCacheDelAddCboRoaringBitmap::<20, MergeFn>::new(
|
let mut cached_word_docids_sorter = SorterCacheDelAddCboRoaringBitmap::<20, MergeFn>::new(
|
||||||
NonZeroUsize::new(100).unwrap(),
|
NonZeroUsize::new(100).unwrap(),
|
||||||
word_docids_sorter,
|
word_docids_sorter,
|
||||||
|
b"wdi",
|
||||||
REDIS_CLIENT.get_connection().unwrap(),
|
REDIS_CLIENT.get_connection().unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -126,6 +128,7 @@ pub fn extract_word_docids<R: io::Read + io::Seek>(
|
|||||||
let mut cached_exact_word_docids_sorter = SorterCacheDelAddCboRoaringBitmap::<20, MergeFn>::new(
|
let mut cached_exact_word_docids_sorter = SorterCacheDelAddCboRoaringBitmap::<20, MergeFn>::new(
|
||||||
NonZeroUsize::new(100).unwrap(),
|
NonZeroUsize::new(100).unwrap(),
|
||||||
exact_word_docids_sorter,
|
exact_word_docids_sorter,
|
||||||
|
b"ewd",
|
||||||
REDIS_CLIENT.get_connection().unwrap(),
|
REDIS_CLIENT.get_connection().unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ pub fn extract_word_pair_proximity_docids<R: io::Read + io::Seek>(
|
|||||||
SorterCacheDelAddCboRoaringBitmap::<20, MergeFn>::new(
|
SorterCacheDelAddCboRoaringBitmap::<20, MergeFn>::new(
|
||||||
NonZeroUsize::new(100).unwrap(),
|
NonZeroUsize::new(100).unwrap(),
|
||||||
sorter,
|
sorter,
|
||||||
|
b"wpp",
|
||||||
super::REDIS_CLIENT.get_connection().unwrap(),
|
super::REDIS_CLIENT.get_connection().unwrap(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -41,6 +41,7 @@ pub fn extract_word_position_docids<R: io::Read + io::Seek>(
|
|||||||
SorterCacheDelAddCboRoaringBitmap::<20, MergeFn>::new(
|
SorterCacheDelAddCboRoaringBitmap::<20, MergeFn>::new(
|
||||||
NonZeroUsize::new(300).unwrap(),
|
NonZeroUsize::new(300).unwrap(),
|
||||||
word_position_docids_sorter,
|
word_position_docids_sorter,
|
||||||
|
b"wpd",
|
||||||
super::REDIS_CLIENT.get_connection().unwrap(),
|
super::REDIS_CLIENT.get_connection().unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ impl<'t, 'i> WordPrefixDocids<'t, 'i> {
|
|||||||
let mut cached_prefix_docids_sorter = SorterCacheDelAddCboRoaringBitmap::<20, MergeFn>::new(
|
let mut cached_prefix_docids_sorter = SorterCacheDelAddCboRoaringBitmap::<20, MergeFn>::new(
|
||||||
NonZeroUsize::new(200).unwrap(),
|
NonZeroUsize::new(200).unwrap(),
|
||||||
prefix_docids_sorter,
|
prefix_docids_sorter,
|
||||||
|
b"pdi",
|
||||||
REDIS_CLIENT.get_connection().unwrap(),
|
REDIS_CLIENT.get_connection().unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@ impl<'t, 'i> WordPrefixIntegerDocids<'t, 'i> {
|
|||||||
SorterCacheDelAddCboRoaringBitmap::<20, MergeFn>::new(
|
SorterCacheDelAddCboRoaringBitmap::<20, MergeFn>::new(
|
||||||
NonZeroUsize::new(200).unwrap(),
|
NonZeroUsize::new(200).unwrap(),
|
||||||
prefix_integer_docids_sorter,
|
prefix_integer_docids_sorter,
|
||||||
|
b"pid",
|
||||||
REDIS_CLIENT.get_connection().unwrap(),
|
REDIS_CLIENT.get_connection().unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user