mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 18:45:06 +08:00
feat: Force RocksDB compaction
This commit is contained in:
parent
62c8f1ba04
commit
07f447c457
@ -122,6 +122,7 @@ impl<'a> DocumentsAddition<'a> {
|
|||||||
let ranked_map = self.ranked_map;
|
let ranked_map = self.ranked_map;
|
||||||
let schema = lease_inner.schema.clone();
|
let schema = lease_inner.schema.clone();
|
||||||
let raw = lease_inner.raw.clone();
|
let raw = lease_inner.raw.clone();
|
||||||
|
lease_inner.raw.compact();
|
||||||
|
|
||||||
let inner = InnerIndex { words, schema, ranked_map, raw };
|
let inner = InnerIndex { words, schema, ranked_map, raw };
|
||||||
self.inner.0.store(Arc::new(inner));
|
self.inner.0.store(Arc::new(inner));
|
||||||
|
@ -121,6 +121,7 @@ impl<'a> DocumentsDeletion<'a> {
|
|||||||
let ranked_map = lease_inner.ranked_map.clone();
|
let ranked_map = lease_inner.ranked_map.clone();
|
||||||
let schema = lease_inner.schema.clone();
|
let schema = lease_inner.schema.clone();
|
||||||
let raw = lease_inner.raw.clone();
|
let raw = lease_inner.raw.clone();
|
||||||
|
lease_inner.raw.compact();
|
||||||
|
|
||||||
let inner = InnerIndex { words, schema, ranked_map, raw };
|
let inner = InnerIndex { words, schema, ranked_map, raw };
|
||||||
self.inner.0.store(Arc::new(inner));
|
self.inner.0.store(Arc::new(inner));
|
||||||
|
@ -10,6 +10,16 @@ pub struct RawIndex {
|
|||||||
pub custom: CustomSettings,
|
pub custom: CustomSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl RawIndex {
|
||||||
|
pub(crate) fn compact(&self) {
|
||||||
|
self.main.0.compact_range(None::<&[u8]>, None::<&[u8]>);
|
||||||
|
self.words.0.compact_range(None::<&[u8]>, None::<&[u8]>);
|
||||||
|
self.docs_words.0.compact_range(None::<&[u8]>, None::<&[u8]>);
|
||||||
|
self.documents.0.compact_range(None::<&[u8]>, None::<&[u8]>);
|
||||||
|
self.custom.0.compact_range(None::<&[u8]>, None::<&[u8]>);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct InnerRawIndex {
|
pub struct InnerRawIndex {
|
||||||
database: Arc<rocksdb::DB>,
|
database: Arc<rocksdb::DB>,
|
||||||
@ -65,4 +75,12 @@ impl InnerRawIndex {
|
|||||||
|
|
||||||
self.database.write(batch)
|
self.database.write(batch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn compact_range<S, E>(&self, start: Option<S>, end: Option<E>)
|
||||||
|
where S: AsRef<[u8]>,
|
||||||
|
E: AsRef<[u8]>,
|
||||||
|
{
|
||||||
|
let cf = self.database.cf_handle(&self.name).expect("cf not found");
|
||||||
|
self.database.compact_range_cf(cf, start, end)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,24 @@ impl WordsIndex {
|
|||||||
// we must force an allocation to make the memory aligned
|
// we must force an allocation to make the memory aligned
|
||||||
match self.0.get(word)? {
|
match self.0.get(word)? {
|
||||||
Some(bytes) => {
|
Some(bytes) => {
|
||||||
let layout = LayoutVerified::new_slice(bytes.as_ref()).expect("invalid layout");
|
let vec = match LayoutVerified::new_slice(bytes.as_ref()) {
|
||||||
let slice = layout.into_slice();
|
Some(layout) => layout.into_slice().to_vec(),
|
||||||
let setbuf = SetBuf::new_unchecked(slice.to_vec());
|
None => {
|
||||||
|
let len = bytes.as_ref().len();
|
||||||
|
let count = len / std::mem::size_of::<DocIndex>();
|
||||||
|
let mut buf: Vec<DocIndex> = Vec::with_capacity(count);
|
||||||
|
unsafe {
|
||||||
|
let src = bytes.as_ref().as_ptr();
|
||||||
|
let dst = buf.as_mut_ptr() as *mut u8;
|
||||||
|
std::ptr::copy_nonoverlapping(src, dst, len);
|
||||||
|
buf.set_len(count);
|
||||||
|
}
|
||||||
|
buf
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let setbuf = SetBuf::new_unchecked(vec);
|
||||||
|
|
||||||
Ok(Some(setbuf))
|
Ok(Some(setbuf))
|
||||||
},
|
},
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
|
Loading…
Reference in New Issue
Block a user