update reviewer change

This commit is contained in:
Irevoire 2022-10-26 14:19:56 +02:00 committed by Clément Renault
parent 64e55b4db9
commit 4e1b6b514e
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
3 changed files with 19 additions and 18 deletions

View File

@ -749,10 +749,8 @@ impl IndexScheduler {
let index_uid = op.index_uid();
let index = if must_create_index {
// create the index if it doesn't already exist
let mut wtxn = self.env.write_txn()?;
let index = self.index_mapper.create_index(&mut wtxn, index_uid)?;
wtxn.commit()?;
index
let wtxn = self.env.write_txn()?;
self.index_mapper.create_index(wtxn, index_uid)?
} else {
let rtxn = self.env.read_txn()?;
self.index_mapper.index(&rtxn, index_uid)?
@ -765,12 +763,11 @@ impl IndexScheduler {
Ok(tasks)
}
Batch::IndexCreation { index_uid, primary_key, task } => {
let mut wtxn = self.env.write_txn()?;
let wtxn = self.env.write_txn()?;
if self.index_mapper.exists(&wtxn, &index_uid)? {
return Err(Error::IndexAlreadyExists(index_uid));
}
self.index_mapper.create_index(&mut wtxn, &index_uid)?;
wtxn.commit()?;
self.index_mapper.create_index(wtxn, &index_uid)?;
self.process_batch(Batch::IndexUpdate { index_uid, primary_key, task })
}

View File

@ -74,26 +74,31 @@ impl IndexMapper {
}
/// Get or create the index.
pub fn create_index(&self, wtxn: &mut RwTxn, name: &str) -> Result<Index> {
match self.index(wtxn, name) {
pub fn create_index(&self, mut wtxn: RwTxn, name: &str) -> Result<Index> {
let ret = match self.index(&mut wtxn, name) {
Ok(index) => Ok(index),
Err(Error::IndexNotFound(_)) => {
let uuid = Uuid::new_v4();
self.index_mapping.put(wtxn, name, &uuid)?;
self.index_mapping.put(&mut wtxn, name, &uuid)?;
let index_path = self.base_path.join(uuid.to_string());
fs::create_dir_all(&index_path)?;
let index = self.create_or_open_index(&index_path)?;
// TODO: this is far from perfect. If the caller don't commit or fail his commit
// then we end up with an available index that should not exist and is actually
// not available in the index_mapping database.
self.index_map.write().unwrap().insert(uuid, Available(index.clone()));
// 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()))
{
panic!("Uuid v4 conflict.");
}
Ok(index)
}
error => error,
}
};
let index = ret?;
wtxn.commit()?;
Ok(index)
}
/// Removes the index from the mapping table and the in-memory index map

View File

@ -774,9 +774,8 @@ impl IndexScheduler {
/// Create a new index without any associated task.
pub fn create_raw_index(&self, name: &str) -> Result<Index> {
let mut wtxn = self.env.write_txn()?;
let index = self.index_mapper.create_index(&mut wtxn, name)?;
wtxn.commit()?;
let wtxn = self.env.write_txn()?;
let index = self.index_mapper.create_index(wtxn, name)?;
Ok(index)
}