Merge pull request #343 from meilisearch/explicit-index-clear

Change the update loop to be more explicit on index clear
This commit is contained in:
Clément Renault 2019-11-28 14:48:37 +01:00 committed by GitHub
commit e640bc90b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -55,7 +55,23 @@ fn update_awaiter(
index: Index, index: Index,
) -> MResult<()> { ) -> MResult<()> {
let mut receiver = receiver.into_iter(); let mut receiver = receiver.into_iter();
while let Some(UpdateEvent::NewUpdate) = receiver.next() { while let Some(event) = receiver.next() {
// if we receive a *MustClear* event, clear the index and break the loop
if let UpdateEvent::MustClear = event {
let mut writer = env.typed_write_txn::<MainT>()?;
let mut update_writer = update_env.typed_write_txn::<UpdateT>()?;
store::clear(&mut writer, &mut update_writer, &index)?;
writer.commit()?;
update_writer.commit()?;
debug!("store {} cleared", index_uid);
break
}
loop { loop {
// We instantiate a *write* transaction to *block* the thread // We instantiate a *write* transaction to *block* the thread
// until the *other*, notifiying, thread commits // until the *other*, notifiying, thread commits
@ -115,14 +131,6 @@ fn update_awaiter(
debug!("update loop system stopped"); debug!("update loop system stopped");
let mut writer = env.typed_write_txn::<MainT>()?;
let mut update_writer = update_env.typed_write_txn::<UpdateT>()?;
store::clear(&mut writer, &mut update_writer, &index)?;
writer.commit()?;
update_writer.commit()?;
debug!("store {} cleared", index_uid);
Ok(()) Ok(())
} }