move the commit before the insertion in the map

This commit is contained in:
Irevoire 2022-10-26 14:21:23 +02:00 committed by Clément Renault
parent 4e1b6b514e
commit 6c98752922
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -75,8 +75,11 @@ impl IndexMapper {
/// Get or create the index.
pub fn create_index(&self, mut wtxn: RwTxn, name: &str) -> Result<Index> {
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