mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 02:27:40 +08:00
update reviewer change
This commit is contained in:
parent
64e55b4db9
commit
4e1b6b514e
@ -749,10 +749,8 @@ impl IndexScheduler {
|
|||||||
let index_uid = op.index_uid();
|
let index_uid = op.index_uid();
|
||||||
let index = if must_create_index {
|
let index = if must_create_index {
|
||||||
// create the index if it doesn't already exist
|
// create the index if it doesn't already exist
|
||||||
let mut wtxn = self.env.write_txn()?;
|
let wtxn = self.env.write_txn()?;
|
||||||
let index = self.index_mapper.create_index(&mut wtxn, index_uid)?;
|
self.index_mapper.create_index(wtxn, index_uid)?
|
||||||
wtxn.commit()?;
|
|
||||||
index
|
|
||||||
} else {
|
} else {
|
||||||
let rtxn = self.env.read_txn()?;
|
let rtxn = self.env.read_txn()?;
|
||||||
self.index_mapper.index(&rtxn, index_uid)?
|
self.index_mapper.index(&rtxn, index_uid)?
|
||||||
@ -765,12 +763,11 @@ impl IndexScheduler {
|
|||||||
Ok(tasks)
|
Ok(tasks)
|
||||||
}
|
}
|
||||||
Batch::IndexCreation { index_uid, primary_key, task } => {
|
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)? {
|
if self.index_mapper.exists(&wtxn, &index_uid)? {
|
||||||
return Err(Error::IndexAlreadyExists(index_uid));
|
return Err(Error::IndexAlreadyExists(index_uid));
|
||||||
}
|
}
|
||||||
self.index_mapper.create_index(&mut wtxn, &index_uid)?;
|
self.index_mapper.create_index(wtxn, &index_uid)?;
|
||||||
wtxn.commit()?;
|
|
||||||
|
|
||||||
self.process_batch(Batch::IndexUpdate { index_uid, primary_key, task })
|
self.process_batch(Batch::IndexUpdate { index_uid, primary_key, task })
|
||||||
}
|
}
|
||||||
|
@ -74,26 +74,31 @@ impl IndexMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get or create the index.
|
/// Get or create the index.
|
||||||
pub fn create_index(&self, wtxn: &mut RwTxn, name: &str) -> Result<Index> {
|
pub fn create_index(&self, mut wtxn: RwTxn, name: &str) -> Result<Index> {
|
||||||
match self.index(wtxn, name) {
|
let ret = match self.index(&mut wtxn, name) {
|
||||||
Ok(index) => Ok(index),
|
Ok(index) => Ok(index),
|
||||||
Err(Error::IndexNotFound(_)) => {
|
Err(Error::IndexNotFound(_)) => {
|
||||||
let uuid = Uuid::new_v4();
|
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());
|
let index_path = self.base_path.join(uuid.to_string());
|
||||||
fs::create_dir_all(&index_path)?;
|
fs::create_dir_all(&index_path)?;
|
||||||
let index = self.create_or_open_index(&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
|
// TODO: it would be better to lazyly create the index. But we need an Index::open function for milli.
|
||||||
// then we end up with an available index that should not exist and is actually
|
if let Some(BeingDeleted) =
|
||||||
// not available in the index_mapping database.
|
self.index_map.write().unwrap().insert(uuid, Available(index.clone()))
|
||||||
self.index_map.write().unwrap().insert(uuid, Available(index.clone()));
|
{
|
||||||
|
panic!("Uuid v4 conflict.");
|
||||||
|
}
|
||||||
|
|
||||||
Ok(index)
|
Ok(index)
|
||||||
}
|
}
|
||||||
error => error,
|
error => error,
|
||||||
}
|
};
|
||||||
|
let index = ret?;
|
||||||
|
wtxn.commit()?;
|
||||||
|
Ok(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the index from the mapping table and the in-memory index map
|
/// Removes the index from the mapping table and the in-memory index map
|
||||||
|
@ -774,9 +774,8 @@ impl IndexScheduler {
|
|||||||
|
|
||||||
/// Create a new index without any associated task.
|
/// Create a new index without any associated task.
|
||||||
pub fn create_raw_index(&self, name: &str) -> Result<Index> {
|
pub fn create_raw_index(&self, name: &str) -> Result<Index> {
|
||||||
let mut wtxn = self.env.write_txn()?;
|
let wtxn = self.env.write_txn()?;
|
||||||
let index = self.index_mapper.create_index(&mut wtxn, name)?;
|
let index = self.index_mapper.create_index(wtxn, name)?;
|
||||||
wtxn.commit()?;
|
|
||||||
|
|
||||||
Ok(index)
|
Ok(index)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user