From 6c98752922716c9124e305325c85d925262f921b Mon Sep 17 00:00:00 2001 From: Irevoire Date: Wed, 26 Oct 2022 14:21:23 +0200 Subject: [PATCH] move the commit before the insertion in the map --- index-scheduler/src/index_mapper.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/index-scheduler/src/index_mapper.rs b/index-scheduler/src/index_mapper.rs index 6fd844a93..478503a39 100644 --- a/index-scheduler/src/index_mapper.rs +++ b/index-scheduler/src/index_mapper.rs @@ -75,8 +75,11 @@ impl IndexMapper { /// Get or create the index. pub fn create_index(&self, mut wtxn: RwTxn, name: &str) -> Result { - let ret = match self.index(&mut wtxn, name) { - Ok(index) => Ok(index), + match self.index(&mut wtxn, name) { + Ok(index) => { + wtxn.commit()?; + Ok(index) + } Err(Error::IndexNotFound(_)) => { let uuid = Uuid::new_v4(); self.index_mapping.put(&mut wtxn, name, &uuid)?; @@ -85,6 +88,7 @@ impl IndexMapper { fs::create_dir_all(&index_path)?; let index = self.create_or_open_index(&index_path)?; + wtxn.commit()?; // TODO: it would be better to lazyly create the index. But we need an Index::open function for milli. if let Some(BeingDeleted) = self.index_map.write().unwrap().insert(uuid, Available(index.clone())) @@ -95,10 +99,7 @@ impl IndexMapper { Ok(index) } error => error, - }; - let index = ret?; - wtxn.commit()?; - Ok(index) + } } /// Removes the index from the mapping table and the in-memory index map