mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
Move to zerocopy-lmdb
This commit is contained in:
parent
c332c7bc70
commit
1667e1b32f
25 changed files with 450 additions and 684 deletions
|
@ -1,21 +1,22 @@
|
|||
use zlmdb::Result as ZResult;
|
||||
use crate::update::{Update, next_update_id};
|
||||
use crate::{store, MResult};
|
||||
use crate::store;
|
||||
|
||||
pub fn apply_customs_update(
|
||||
writer: &mut rkv::Writer,
|
||||
writer: &mut zlmdb::RwTxn,
|
||||
main_store: store::Main,
|
||||
customs: &[u8],
|
||||
) -> MResult<()>
|
||||
) -> ZResult<()>
|
||||
{
|
||||
main_store.put_customs(writer, customs)
|
||||
}
|
||||
|
||||
pub fn push_customs_update(
|
||||
writer: &mut rkv::Writer,
|
||||
writer: &mut zlmdb::RwTxn,
|
||||
updates_store: store::Updates,
|
||||
updates_results_store: store::UpdatesResults,
|
||||
customs: Vec<u8>,
|
||||
) -> MResult<u64>
|
||||
) -> ZResult<u64>
|
||||
{
|
||||
let last_update_id = next_update_id(writer, updates_store, updates_results_store)?;
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ impl<D> DocumentsAddition<D> {
|
|||
self.documents.push(document);
|
||||
}
|
||||
|
||||
pub fn finalize(self, writer: &mut rkv::Writer) -> MResult<u64>
|
||||
pub fn finalize(self, writer: &mut zlmdb::RwTxn) -> MResult<u64>
|
||||
where D: serde::Serialize
|
||||
{
|
||||
let _ = self.updates_notifier.send(());
|
||||
|
@ -57,7 +57,7 @@ impl<D> Extend<D> for DocumentsAddition<D> {
|
|||
}
|
||||
|
||||
pub fn push_documents_addition<D: serde::Serialize>(
|
||||
writer: &mut rkv::Writer,
|
||||
writer: &mut zlmdb::RwTxn,
|
||||
updates_store: store::Updates,
|
||||
updates_results_store: store::UpdatesResults,
|
||||
addition: Vec<D>,
|
||||
|
@ -79,7 +79,7 @@ pub fn push_documents_addition<D: serde::Serialize>(
|
|||
}
|
||||
|
||||
pub fn apply_documents_addition(
|
||||
writer: &mut rkv::Writer,
|
||||
writer: &mut zlmdb::RwTxn,
|
||||
main_store: store::Main,
|
||||
documents_fields_store: store::DocumentsFields,
|
||||
documents_fields_counts_store: store::DocumentsFieldsCounts,
|
||||
|
|
|
@ -49,7 +49,7 @@ impl DocumentsDeletion {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn finalize(self, writer: &mut rkv::Writer) -> MResult<u64> {
|
||||
pub fn finalize(self, writer: &mut zlmdb::RwTxn) -> MResult<u64> {
|
||||
let _ = self.updates_notifier.send(());
|
||||
let update_id = push_documents_deletion(
|
||||
writer,
|
||||
|
@ -68,7 +68,7 @@ impl Extend<DocumentId> for DocumentsDeletion {
|
|||
}
|
||||
|
||||
pub fn push_documents_deletion(
|
||||
writer: &mut rkv::Writer,
|
||||
writer: &mut zlmdb::RwTxn,
|
||||
updates_store: store::Updates,
|
||||
updates_results_store: store::UpdatesResults,
|
||||
deletion: Vec<DocumentId>,
|
||||
|
@ -83,7 +83,7 @@ pub fn push_documents_deletion(
|
|||
}
|
||||
|
||||
pub fn apply_documents_deletion(
|
||||
writer: &mut rkv::Writer,
|
||||
writer: &mut zlmdb::RwTxn,
|
||||
main_store: store::Main,
|
||||
documents_fields_store: store::DocumentsFields,
|
||||
documents_fields_counts_store: store::DocumentsFieldsCounts,
|
||||
|
|
|
@ -18,11 +18,12 @@ use std::cmp;
|
|||
|
||||
use log::debug;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use zlmdb::Result as ZResult;
|
||||
|
||||
use crate::{store, MResult, DocumentId, RankedMap};
|
||||
use meilidb_schema::Schema;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum Update {
|
||||
Schema(Schema),
|
||||
Customs(Vec<u8>),
|
||||
|
@ -62,8 +63,8 @@ pub enum UpdateStatus {
|
|||
Unknown,
|
||||
}
|
||||
|
||||
pub fn update_status<T: rkv::Readable>(
|
||||
reader: &T,
|
||||
pub fn update_status(
|
||||
reader: &zlmdb::RoTxn,
|
||||
updates_store: store::Updates,
|
||||
updates_results_store: store::UpdatesResults,
|
||||
update_id: u64,
|
||||
|
@ -82,10 +83,10 @@ pub fn update_status<T: rkv::Readable>(
|
|||
}
|
||||
|
||||
pub fn next_update_id(
|
||||
writer: &mut rkv::Writer,
|
||||
writer: &mut zlmdb::RwTxn,
|
||||
updates_store: store::Updates,
|
||||
updates_results_store: store::UpdatesResults,
|
||||
) -> MResult<u64>
|
||||
) -> ZResult<u64>
|
||||
{
|
||||
let last_update_id = updates_store.last_update_id(writer)?;
|
||||
let last_update_id = last_update_id.map(|(n, _)| n);
|
||||
|
@ -99,7 +100,7 @@ pub fn next_update_id(
|
|||
Ok(new_update_id)
|
||||
}
|
||||
|
||||
pub fn update_task(writer: &mut rkv::Writer, index: store::Index) -> MResult<Option<UpdateResult>> {
|
||||
pub fn update_task(writer: &mut zlmdb::RwTxn, index: store::Index) -> MResult<Option<UpdateResult>> {
|
||||
let (update_id, update) = match index.updates.pop_front(writer)? {
|
||||
Some(value) => value,
|
||||
None => return Ok(None),
|
||||
|
@ -120,7 +121,7 @@ pub fn update_task(writer: &mut rkv::Writer, index: store::Index) -> MResult<Opt
|
|||
let start = Instant::now();
|
||||
|
||||
let update_type = UpdateType::Customs;
|
||||
let result = apply_customs_update(writer, index.main, &customs);
|
||||
let result = apply_customs_update(writer, index.main, &customs).map_err(Into::into);
|
||||
|
||||
(update_type, result, start.elapsed())
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::{store, error::UnsupportedOperation, MResult};
|
|||
use crate::update::{Update, next_update_id};
|
||||
|
||||
pub fn apply_schema_update(
|
||||
writer: &mut rkv::Writer,
|
||||
writer: &mut zlmdb::RwTxn,
|
||||
main_store: store::Main,
|
||||
new_schema: &Schema,
|
||||
) -> MResult<()>
|
||||
|
@ -12,11 +12,11 @@ pub fn apply_schema_update(
|
|||
return Err(UnsupportedOperation::SchemaAlreadyExists.into())
|
||||
}
|
||||
|
||||
main_store.put_schema(writer, new_schema)
|
||||
main_store.put_schema(writer, new_schema).map_err(Into::into)
|
||||
}
|
||||
|
||||
pub fn push_schema_update(
|
||||
writer: &mut rkv::Writer,
|
||||
writer: &mut zlmdb::RwTxn,
|
||||
updates_store: store::Updates,
|
||||
updates_results_store: store::UpdatesResults,
|
||||
schema: Schema,
|
||||
|
|
|
@ -39,7 +39,7 @@ impl SynonymsAddition {
|
|||
self.synonyms.entry(synonym).or_insert_with(Vec::new).extend(alternatives);
|
||||
}
|
||||
|
||||
pub fn finalize(self, writer: &mut rkv::Writer) -> MResult<u64> {
|
||||
pub fn finalize(self, writer: &mut zlmdb::RwTxn) -> MResult<u64> {
|
||||
let _ = self.updates_notifier.send(());
|
||||
let update_id = push_synonyms_addition(
|
||||
writer,
|
||||
|
@ -52,7 +52,7 @@ impl SynonymsAddition {
|
|||
}
|
||||
|
||||
pub fn push_synonyms_addition(
|
||||
writer: &mut rkv::Writer,
|
||||
writer: &mut zlmdb::RwTxn,
|
||||
updates_store: store::Updates,
|
||||
updates_results_store: store::UpdatesResults,
|
||||
addition: BTreeMap<String, Vec<String>>,
|
||||
|
@ -67,7 +67,7 @@ pub fn push_synonyms_addition(
|
|||
}
|
||||
|
||||
pub fn apply_synonyms_addition(
|
||||
writer: &mut rkv::Writer,
|
||||
writer: &mut zlmdb::RwTxn,
|
||||
main_store: store::Main,
|
||||
synonyms_store: store::Synonyms,
|
||||
addition: BTreeMap<String, Vec<String>>,
|
||||
|
|
|
@ -49,7 +49,7 @@ impl SynonymsDeletion {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn finalize(self, writer: &mut rkv::Writer) -> MResult<u64> {
|
||||
pub fn finalize(self, writer: &mut zlmdb::RwTxn) -> MResult<u64> {
|
||||
let _ = self.updates_notifier.send(());
|
||||
let update_id = push_synonyms_deletion(
|
||||
writer,
|
||||
|
@ -62,7 +62,7 @@ impl SynonymsDeletion {
|
|||
}
|
||||
|
||||
pub fn push_synonyms_deletion(
|
||||
writer: &mut rkv::Writer,
|
||||
writer: &mut zlmdb::RwTxn,
|
||||
updates_store: store::Updates,
|
||||
updates_results_store: store::UpdatesResults,
|
||||
deletion: BTreeMap<String, Option<Vec<String>>>,
|
||||
|
@ -77,7 +77,7 @@ pub fn push_synonyms_deletion(
|
|||
}
|
||||
|
||||
pub fn apply_synonyms_deletion(
|
||||
writer: &mut rkv::Writer,
|
||||
writer: &mut zlmdb::RwTxn,
|
||||
main_store: store::Main,
|
||||
synonyms_store: store::Synonyms,
|
||||
deletion: BTreeMap<String, Option<Vec<String>>>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue