diff --git a/meilidb-core/src/store/main.rs b/meilidb-core/src/store/main.rs index 2712a0efa..cb5266187 100644 --- a/meilidb-core/src/store/main.rs +++ b/meilidb-core/src/store/main.rs @@ -3,8 +3,10 @@ use std::convert::TryInto; use meilidb_schema::Schema; use rkv::Value; +use serde::de; use crate::{RankedMap, MResult}; +const CUSTOMS_KEY: &str = "customs-key"; const NUMBER_OF_DOCUMENTS_KEY: &str = "number-of-documents"; const RANKED_MAP_KEY: &str = "ranked-map"; const SCHEMA_KEY: &str = "schema"; @@ -63,7 +65,7 @@ impl Main { { match self.main.get(reader, SCHEMA_KEY)? { Some(Value::Blob(bytes)) => { - let schema = bincode::deserialize_from(bytes.as_ref())?; + let schema = bincode::deserialize_from(bytes)?; Ok(Some(schema)) }, Some(value) => panic!("invalid type {:?}", value), @@ -151,4 +153,17 @@ impl Main { None => Ok(0), } } + + pub fn put_customs(&self, writer: &mut rkv::Writer, customs: &[u8]) -> MResult<()> { + self.main.put(writer, CUSTOMS_KEY, &Value::Blob(customs))?; + Ok(()) + } + + pub fn customs<'t>(&self, reader: &'t impl rkv::Readable) -> MResult> { + match self.main.get(reader, CUSTOMS_KEY)? { + Some(Value::Blob(bytes)) => Ok(Some(bytes)), + Some(value) => panic!("invalid type {:?}", value), + None => Ok(None), + } + } } diff --git a/meilidb-core/src/store/mod.rs b/meilidb-core/src/store/mod.rs index 228aa74bd..957ee8520 100644 --- a/meilidb-core/src/store/mod.rs +++ b/meilidb-core/src/store/mod.rs @@ -16,7 +16,7 @@ pub use self::updates_results::UpdatesResults; use std::collections::HashSet; use meilidb_schema::{Schema, SchemaAttr}; -use serde::de; +use serde::{ser, de}; use crate::criterion::Criteria; use crate::serde::Deserializer; use crate::{update, query_builder::QueryBuilder, DocumentId, MResult, Error}; @@ -109,10 +109,14 @@ impl Index { } } - pub fn schema_update(&self, writer: &mut rkv::Writer, schema: Schema) -> MResult<()> { + pub fn schema_update(&self, writer: &mut rkv::Writer, schema: Schema) -> MResult { let _ = self.updates_notifier.send(()); - update::push_schema_update(writer, self.updates, self.updates_results, schema)?; - Ok(()) + update::push_schema_update(writer, self.updates, self.updates_results, schema) + } + + pub fn customs_update(&self, writer: &mut rkv::Writer, customs: Vec) -> MResult { + let _ = self.updates_notifier.send(()); + update::push_customs_update(writer, self.updates, self.updates_results, customs) } pub fn documents_addition(&self) -> update::DocumentsAddition { diff --git a/meilidb-core/src/update/customs_update.rs b/meilidb-core/src/update/customs_update.rs new file mode 100644 index 000000000..fa65d7c67 --- /dev/null +++ b/meilidb-core/src/update/customs_update.rs @@ -0,0 +1,26 @@ +use crate::{store, error::UnsupportedOperation, MResult}; +use crate::update::{Update, next_update_id}; + +pub fn apply_customs_update( + writer: &mut rkv::Writer, + main_store: store::Main, + customs: &[u8], +) -> MResult<()> +{ + main_store.put_customs(writer, customs) +} + +pub fn push_customs_update( + writer: &mut rkv::Writer, + updates_store: store::Updates, + updates_results_store: store::UpdatesResults, + customs: Vec, +) -> MResult +{ + let last_update_id = next_update_id(writer, updates_store, updates_results_store)?; + + let update = Update::Customs(customs); + updates_store.put_update(writer, last_update_id, &update)?; + + Ok(last_update_id) +} diff --git a/meilidb-core/src/update/mod.rs b/meilidb-core/src/update/mod.rs index 0025e2e28..794c2f8ec 100644 --- a/meilidb-core/src/update/mod.rs +++ b/meilidb-core/src/update/mod.rs @@ -1,9 +1,11 @@ +mod customs_update; mod documents_addition; mod documents_deletion; mod schema_update; mod synonyms_addition; mod synonyms_deletion; +pub use self::customs_update::{apply_customs_update, push_customs_update}; pub use self::documents_addition::{DocumentsAddition, apply_documents_addition}; pub use self::documents_deletion::{DocumentsDeletion, apply_documents_deletion}; pub use self::schema_update::{apply_schema_update, push_schema_update}; @@ -22,7 +24,8 @@ use meilidb_schema::Schema; #[derive(Debug, Serialize, Deserialize)] pub enum Update { - SchemaUpdate(Schema), + Schema(Schema), + Customs(Vec), DocumentsAddition(Vec), DocumentsDeletion(Vec), SynonymsAddition(BTreeMap>), @@ -31,7 +34,8 @@ pub enum Update { #[derive(Debug, Clone, Serialize, Deserialize)] pub enum UpdateType { - SchemaUpdate { schema: Schema }, + Schema { schema: Schema }, + Customs, DocumentsAddition { number: usize }, DocumentsDeletion { number: usize }, SynonymsAddition { number: usize }, @@ -104,14 +108,22 @@ pub fn update_task(writer: &mut rkv::Writer, index: store::Index) -> MResult { + Update::Schema(schema) => { let start = Instant::now(); - let update_type = UpdateType::SchemaUpdate { schema: schema.clone() }; + let update_type = UpdateType::Schema { schema: schema.clone() }; let result = apply_schema_update(writer, index.main, &schema); (update_type, result, start.elapsed()) }, + Update::Customs(customs) => { + let start = Instant::now(); + + let update_type = UpdateType::Customs; + let result = apply_customs_update(writer, index.main, &customs); + + (update_type, result, start.elapsed()) + } Update::DocumentsAddition(documents) => { let start = Instant::now(); diff --git a/meilidb-core/src/update/schema_update.rs b/meilidb-core/src/update/schema_update.rs index 6c258c388..6e11c997d 100644 --- a/meilidb-core/src/update/schema_update.rs +++ b/meilidb-core/src/update/schema_update.rs @@ -24,7 +24,7 @@ pub fn push_schema_update( { let last_update_id = next_update_id(writer, updates_store, updates_results_store)?; - let update = Update::SchemaUpdate(schema); + let update = Update::Schema(schema); updates_store.put_update(writer, last_update_id, &update)?; Ok(last_update_id)