Introduce customs updates

This commit is contained in:
Clément Renault 2019-10-11 15:33:35 +02:00
parent da6ab2753e
commit 02575a2ef6
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
4 changed files with 62 additions and 5 deletions

View File

@ -3,8 +3,10 @@ use std::convert::TryInto;
use meilidb_schema::Schema; use meilidb_schema::Schema;
use rkv::Value; use rkv::Value;
use serde::de;
use crate::{RankedMap, MResult}; use crate::{RankedMap, MResult};
const CUSTOMS_KEY: &str = "customs-key";
const NUMBER_OF_DOCUMENTS_KEY: &str = "number-of-documents"; const NUMBER_OF_DOCUMENTS_KEY: &str = "number-of-documents";
const RANKED_MAP_KEY: &str = "ranked-map"; const RANKED_MAP_KEY: &str = "ranked-map";
const SCHEMA_KEY: &str = "schema"; const SCHEMA_KEY: &str = "schema";
@ -63,7 +65,7 @@ impl Main {
{ {
match self.main.get(reader, SCHEMA_KEY)? { match self.main.get(reader, SCHEMA_KEY)? {
Some(Value::Blob(bytes)) => { Some(Value::Blob(bytes)) => {
let schema = bincode::deserialize_from(bytes.as_ref())?; let schema = bincode::deserialize_from(bytes)?;
Ok(Some(schema)) Ok(Some(schema))
}, },
Some(value) => panic!("invalid type {:?}", value), Some(value) => panic!("invalid type {:?}", value),
@ -151,4 +153,17 @@ impl Main {
None => Ok(0), 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<Option<&'t [u8]>> {
match self.main.get(reader, CUSTOMS_KEY)? {
Some(Value::Blob(bytes)) => Ok(Some(bytes)),
Some(value) => panic!("invalid type {:?}", value),
None => Ok(None),
}
}
} }

View File

@ -16,7 +16,7 @@ pub use self::updates_results::UpdatesResults;
use std::collections::HashSet; use std::collections::HashSet;
use meilidb_schema::{Schema, SchemaAttr}; use meilidb_schema::{Schema, SchemaAttr};
use serde::de; use serde::{ser, de};
use crate::criterion::Criteria; use crate::criterion::Criteria;
use crate::serde::Deserializer; use crate::serde::Deserializer;
use crate::{update, query_builder::QueryBuilder, DocumentId, MResult, Error}; 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<u64> {
let _ = self.updates_notifier.send(()); let _ = self.updates_notifier.send(());
update::push_schema_update(writer, self.updates, self.updates_results, schema)?; update::push_schema_update(writer, self.updates, self.updates_results, schema)
Ok(()) }
pub fn customs_update(&self, writer: &mut rkv::Writer, customs: Vec<u8>) -> MResult<u64> {
let _ = self.updates_notifier.send(());
update::push_customs_update(writer, self.updates, self.updates_results, customs)
} }
pub fn documents_addition<D>(&self) -> update::DocumentsAddition<D> { pub fn documents_addition<D>(&self) -> update::DocumentsAddition<D> {

View File

@ -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<u8>,
) -> MResult<u64>
{
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)
}

View File

@ -1,9 +1,11 @@
mod customs_update;
mod documents_addition; mod documents_addition;
mod documents_deletion; mod documents_deletion;
mod schema_update; mod schema_update;
mod synonyms_addition; mod synonyms_addition;
mod synonyms_deletion; 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_addition::{DocumentsAddition, apply_documents_addition};
pub use self::documents_deletion::{DocumentsDeletion, apply_documents_deletion}; pub use self::documents_deletion::{DocumentsDeletion, apply_documents_deletion};
pub use self::schema_update::{apply_schema_update, push_schema_update}; pub use self::schema_update::{apply_schema_update, push_schema_update};
@ -23,6 +25,7 @@ use meilidb_schema::Schema;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub enum Update { pub enum Update {
Schema(Schema), Schema(Schema),
Customs(Vec<u8>),
DocumentsAddition(Vec<rmpv::Value>), DocumentsAddition(Vec<rmpv::Value>),
DocumentsDeletion(Vec<DocumentId>), DocumentsDeletion(Vec<DocumentId>),
SynonymsAddition(BTreeMap<String, Vec<String>>), SynonymsAddition(BTreeMap<String, Vec<String>>),
@ -32,6 +35,7 @@ pub enum Update {
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub enum UpdateType { pub enum UpdateType {
Schema { schema: Schema }, Schema { schema: Schema },
Customs,
DocumentsAddition { number: usize }, DocumentsAddition { number: usize },
DocumentsDeletion { number: usize }, DocumentsDeletion { number: usize },
SynonymsAddition { number: usize }, SynonymsAddition { number: usize },
@ -112,6 +116,14 @@ pub fn update_task(writer: &mut rkv::Writer, index: store::Index) -> MResult<Opt
(update_type, result, start.elapsed()) (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) => { Update::DocumentsAddition(documents) => {
let start = Instant::now(); let start = Instant::now();