mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 05:14:27 +01:00
Fix the dead lock on index deletion once again
This commit is contained in:
parent
98f76aa952
commit
c8832409ad
@ -18,7 +18,7 @@ pub struct Database {
|
|||||||
pub env: heed::Env,
|
pub env: heed::Env,
|
||||||
common_store: heed::PolyDatabase,
|
common_store: heed::PolyDatabase,
|
||||||
indexes_store: heed::Database<Str, Unit>,
|
indexes_store: heed::Database<Str, Unit>,
|
||||||
indexes: RwLock<HashMap<String, (Index, thread::JoinHandle<()>)>>,
|
indexes: RwLock<HashMap<String, (Index, thread::JoinHandle<MResult<()>>)>>,
|
||||||
update_fn: Arc<ArcSwapFn>,
|
update_fn: Arc<ArcSwapFn>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ macro_rules! r#break_try {
|
|||||||
|
|
||||||
pub enum UpdateEvent {
|
pub enum UpdateEvent {
|
||||||
NewUpdate,
|
NewUpdate,
|
||||||
MustStop,
|
MustClear,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type UpdateEvents = Receiver<UpdateEvent>;
|
pub type UpdateEvents = Receiver<UpdateEvent>;
|
||||||
@ -48,7 +48,7 @@ fn update_awaiter(
|
|||||||
index_uid: &str,
|
index_uid: &str,
|
||||||
update_fn: Arc<ArcSwapFn>,
|
update_fn: Arc<ArcSwapFn>,
|
||||||
index: Index,
|
index: Index,
|
||||||
) {
|
) -> MResult<()> {
|
||||||
let mut receiver = receiver.into_iter();
|
let mut receiver = receiver.into_iter();
|
||||||
while let Some(UpdateEvent::NewUpdate) = receiver.next() {
|
while let Some(UpdateEvent::NewUpdate) = receiver.next() {
|
||||||
loop {
|
loop {
|
||||||
@ -97,6 +97,14 @@ fn update_awaiter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
debug!("update loop system stopped");
|
debug!("update loop system stopped");
|
||||||
|
|
||||||
|
let mut writer = env.write_txn()?;
|
||||||
|
store::clear(&mut writer, &index)?;
|
||||||
|
writer.commit()?;
|
||||||
|
|
||||||
|
debug!("store {} cleared", index_uid);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Database {
|
impl Database {
|
||||||
@ -226,14 +234,15 @@ impl Database {
|
|||||||
// and clear all the LMDB dbi
|
// and clear all the LMDB dbi
|
||||||
let mut writer = self.env.write_txn()?;
|
let mut writer = self.env.write_txn()?;
|
||||||
self.indexes_store.delete(&mut writer, &name)?;
|
self.indexes_store.delete(&mut writer, &name)?;
|
||||||
|
|
||||||
store::clear(&mut writer, &index)?;
|
|
||||||
writer.commit()?;
|
writer.commit()?;
|
||||||
|
|
||||||
|
// send a stop event to the update loop of the index
|
||||||
|
index.updates_notifier.send(UpdateEvent::MustClear).unwrap();
|
||||||
|
|
||||||
drop(indexes_lock);
|
drop(indexes_lock);
|
||||||
|
|
||||||
// join the update loop thread to ensure it is stopped
|
// join the update loop thread to ensure it is stopped
|
||||||
handle.join().unwrap();
|
handle.join().unwrap()?;
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ pub struct Index {
|
|||||||
|
|
||||||
pub updates: Updates,
|
pub updates: Updates,
|
||||||
pub updates_results: UpdatesResults,
|
pub updates_results: UpdatesResults,
|
||||||
updates_notifier: UpdateEventsEmitter,
|
pub(crate) updates_notifier: UpdateEventsEmitter,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Index {
|
impl Index {
|
||||||
@ -381,9 +381,6 @@ pub fn open(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear(writer: &mut heed::RwTxn, index: &Index) -> MResult<()> {
|
pub fn clear(writer: &mut heed::RwTxn, index: &Index) -> MResult<()> {
|
||||||
// send a stop event to the update loop of the index
|
|
||||||
index.updates_notifier.send(UpdateEvent::MustStop).unwrap();
|
|
||||||
|
|
||||||
// clear all the stores
|
// clear all the stores
|
||||||
index.main.clear(writer)?;
|
index.main.clear(writer)?;
|
||||||
index.postings_lists.clear(writer)?;
|
index.postings_lists.clear(writer)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user