Merge pull request #234 from meilisearch/clear-all-update-variant

Introduce a clear all documents update
This commit is contained in:
Clément Renault 2019-10-23 16:45:37 +02:00 committed by GitHub
commit 1446a6a2d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 72 additions and 0 deletions

View File

@ -26,6 +26,10 @@ impl DocsWords {
self.docs_words.delete(writer, &document_id) self.docs_words.delete(writer, &document_id)
} }
pub fn clear(self, writer: &mut heed::RwTxn) -> ZResult<()> {
self.docs_words.clear(writer)
}
pub fn doc_words( pub fn doc_words(
self, self,
reader: &heed::RoTxn, reader: &heed::RoTxn,

View File

@ -32,6 +32,10 @@ impl DocumentsFields {
self.documents_fields.delete_range(writer, start..=end) self.documents_fields.delete_range(writer, start..=end)
} }
pub fn clear(self, writer: &mut heed::RwTxn) -> ZResult<()> {
self.documents_fields.clear(writer)
}
pub fn document_attribute<'txn>( pub fn document_attribute<'txn>(
self, self,
reader: &'txn heed::RoTxn, reader: &'txn heed::RoTxn,

View File

@ -32,6 +32,10 @@ impl DocumentsFieldsCounts {
.delete_range(writer, start..=end) .delete_range(writer, start..=end)
} }
pub fn clear(self, writer: &mut heed::RwTxn) -> ZResult<()> {
self.documents_fields_counts.clear(writer)
}
pub fn document_field_count( pub fn document_field_count(
self, self,
reader: &heed::RoTxn, reader: &heed::RoTxn,

View File

@ -166,6 +166,10 @@ impl Index {
) )
} }
pub fn clear_all(&self, writer: &mut heed::RwTxn) -> MResult<u64> {
update::push_clear_all(writer, self.updates, self.updates_results)
}
pub fn synonyms_addition(&self) -> update::SynonymsAddition { pub fn synonyms_addition(&self) -> update::SynonymsAddition {
update::SynonymsAddition::new( update::SynonymsAddition::new(
self.updates, self.updates,

View File

@ -0,0 +1,36 @@
use meilidb_schema::{Diff, Schema};
use crate::update::documents_addition::reindex_all_documents;
use crate::update::{next_update_id, Update};
use crate::{error::UnsupportedOperation, store, MResult, RankedMap};
pub fn apply_clear_all(
writer: &mut heed::RwTxn,
main_store: store::Main,
documents_fields_store: store::DocumentsFields,
documents_fields_counts_store: store::DocumentsFieldsCounts,
postings_lists_store: store::PostingsLists,
docs_words_store: store::DocsWords,
) -> MResult<()> {
main_store.put_words_fst(writer, &fst::Set::default())?;
main_store.put_ranked_map(writer, &RankedMap::default())?;
main_store.put_number_of_documents(writer, |_| 0)?;
documents_fields_store.clear(writer)?;
documents_fields_counts_store.clear(writer)?;
postings_lists_store.clear(writer)?;
docs_words_store.clear(writer)?;
Ok(())
}
pub fn push_clear_all(
writer: &mut heed::RwTxn,
updates_store: store::Updates,
updates_results_store: store::UpdatesResults,
) -> MResult<u64> {
let last_update_id = next_update_id(writer, updates_store, updates_results_store)?;
let update = Update::ClearAll;
updates_store.put_update(writer, last_update_id, &update)?;
Ok(last_update_id)
}

View File

@ -184,6 +184,7 @@ pub fn reindex_all_documents(
main_store.put_ranked_map(writer, &ranked_map)?; main_store.put_ranked_map(writer, &ranked_map)?;
main_store.put_number_of_documents(writer, |_| 0)?; main_store.put_number_of_documents(writer, |_| 0)?;
postings_lists_store.clear(writer)?; postings_lists_store.clear(writer)?;
docs_words_store.clear(writer)?;
// 3. re-index one document by one document (otherwise we make the borrow checker unhappy) // 3. re-index one document by one document (otherwise we make the borrow checker unhappy)
let mut indexer = RawIndexer::new(); let mut indexer = RawIndexer::new();

View File

@ -1,3 +1,4 @@
mod clear_all;
mod customs_update; mod customs_update;
mod documents_addition; mod documents_addition;
mod documents_deletion; mod documents_deletion;
@ -5,6 +6,7 @@ mod schema_update;
mod synonyms_addition; mod synonyms_addition;
mod synonyms_deletion; mod synonyms_deletion;
pub use self::clear_all::{apply_clear_all, push_clear_all};
pub use self::customs_update::{apply_customs_update, push_customs_update}; pub use self::customs_update::{apply_customs_update, push_customs_update};
pub use self::documents_addition::{apply_documents_addition, DocumentsAddition}; pub use self::documents_addition::{apply_documents_addition, DocumentsAddition};
pub use self::documents_deletion::{apply_documents_deletion, DocumentsDeletion}; pub use self::documents_deletion::{apply_documents_deletion, DocumentsDeletion};
@ -25,6 +27,7 @@ use meilidb_schema::Schema;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Update { pub enum Update {
ClearAll,
Schema(Schema), Schema(Schema),
Customs(Vec<u8>), Customs(Vec<u8>),
DocumentsAddition(Vec<serde_json::Value>), DocumentsAddition(Vec<serde_json::Value>),
@ -35,6 +38,7 @@ pub enum Update {
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub enum UpdateType { pub enum UpdateType {
ClearAll,
Schema { schema: Schema }, Schema { schema: Schema },
Customs, Customs,
DocumentsAddition { number: usize }, DocumentsAddition { number: usize },
@ -107,6 +111,21 @@ pub fn update_task(writer: &mut heed::RwTxn, index: store::Index) -> MResult<Opt
debug!("Processing update number {}", update_id); debug!("Processing update number {}", update_id);
let (update_type, result, duration) = match update { let (update_type, result, duration) = match update {
Update::ClearAll => {
let start = Instant::now();
let update_type = UpdateType::ClearAll;
let result = apply_clear_all(
writer,
index.main,
index.documents_fields,
index.documents_fields_counts,
index.postings_lists,
index.docs_words,
);
(update_type, result, start.elapsed())
}
Update::Schema(schema) => { Update::Schema(schema) => {
let start = Instant::now(); let start = Instant::now();