mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-24 21:50:07 +01:00
Merge #2055
2055: fix(dump): Fix the loading of dump with empty indexes r=irevoire a=irevoire Co-authored-by: Tamo <tamo@meilisearch.com>
This commit is contained in:
commit
c636988935
@ -8,7 +8,7 @@ use indexmap::IndexMap;
|
|||||||
use milli::documents::DocumentBatchReader;
|
use milli::documents::DocumentBatchReader;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::document_formats::read_ndjson;
|
use crate::document_formats::{read_ndjson, DocumentFormatError};
|
||||||
use crate::index::update_handler::UpdateHandler;
|
use crate::index::update_handler::UpdateHandler;
|
||||||
use crate::index::updates::apply_settings_to_builder;
|
use crate::index::updates::apply_settings_to_builder;
|
||||||
|
|
||||||
@ -128,8 +128,14 @@ impl Index {
|
|||||||
|
|
||||||
let mut tmp_doc_file = tempfile::tempfile()?;
|
let mut tmp_doc_file = tempfile::tempfile()?;
|
||||||
|
|
||||||
read_ndjson(reader, &mut tmp_doc_file)?;
|
let empty = match read_ndjson(reader, &mut tmp_doc_file) {
|
||||||
|
// if there was no document in the file it's because the index was empty
|
||||||
|
Ok(_) => false,
|
||||||
|
Err(DocumentFormatError::EmptyPayload(_)) => true,
|
||||||
|
Err(e) => return Err(e.into()),
|
||||||
|
};
|
||||||
|
|
||||||
|
if !empty {
|
||||||
tmp_doc_file.seek(SeekFrom::Start(0))?;
|
tmp_doc_file.seek(SeekFrom::Start(0))?;
|
||||||
|
|
||||||
let documents_reader = DocumentBatchReader::from_reader(tmp_doc_file)?;
|
let documents_reader = DocumentBatchReader::from_reader(tmp_doc_file)?;
|
||||||
@ -142,9 +148,9 @@ impl Index {
|
|||||||
.index_documents(&mut txn, &index);
|
.index_documents(&mut txn, &index);
|
||||||
builder.execute(documents_reader, |_| ())?;
|
builder.execute(documents_reader, |_| ())?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
txn.commit()?;
|
txn.commit()?;
|
||||||
|
|
||||||
index.prepare_for_closing().wait();
|
index.prepare_for_closing().wait();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user