mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-29 16:24:26 +01:00
reintroduce the uuid mapping for the indexes
This commit is contained in:
parent
c97d51a624
commit
1804416afa
@ -11,6 +11,7 @@ use index::Index;
|
|||||||
pub use task::Task;
|
pub use task::Task;
|
||||||
use task::{Kind, KindWithContent, Status};
|
use task::{Kind, KindWithContent, Status};
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
@ -50,7 +51,7 @@ pub struct Query {
|
|||||||
pub struct IndexScheduler {
|
pub struct IndexScheduler {
|
||||||
// Keep track of the opened indexes and is used
|
// Keep track of the opened indexes and is used
|
||||||
// mainly by the index resolver.
|
// mainly by the index resolver.
|
||||||
index_map: Arc<RwLock<HashMap<String, Index>>>,
|
index_map: Arc<RwLock<HashMap<Uuid, Index>>>,
|
||||||
|
|
||||||
/// The list of tasks currently processing.
|
/// The list of tasks currently processing.
|
||||||
processing_tasks: Arc<RwLock<RoaringBitmap>>,
|
processing_tasks: Arc<RwLock<RoaringBitmap>>,
|
||||||
@ -68,8 +69,8 @@ pub struct IndexScheduler {
|
|||||||
// All the tasks ids grouped by their kind.
|
// All the tasks ids grouped by their kind.
|
||||||
kind: Database<SerdeBincode<Kind>, RoaringBitmapCodec>,
|
kind: Database<SerdeBincode<Kind>, RoaringBitmapCodec>,
|
||||||
|
|
||||||
// Tell you if an index is currently available.
|
// Map an index name with an index uuid currentl available on disk.
|
||||||
available_index: Database<Str, SerdeBincode<bool>>,
|
index_mapping: Database<Str, SerdeBincode<Uuid>>,
|
||||||
// Store the tasks associated to an index.
|
// Store the tasks associated to an index.
|
||||||
index_tasks: Database<Str, RoaringBitmapCodec>,
|
index_tasks: Database<Str, RoaringBitmapCodec>,
|
||||||
|
|
||||||
@ -88,16 +89,16 @@ impl IndexScheduler {
|
|||||||
pub fn index(&self, name: &str) -> Result<Index> {
|
pub fn index(&self, name: &str) -> Result<Index> {
|
||||||
let rtxn = self.env.read_txn()?;
|
let rtxn = self.env.read_txn()?;
|
||||||
|
|
||||||
self.available_index
|
let uuid = self
|
||||||
|
.index_mapping
|
||||||
.get(&rtxn, name)?
|
.get(&rtxn, name)?
|
||||||
.ok_or(Error::IndexNotFound(name.to_string()))?;
|
.ok_or(Error::IndexNotFound(name.to_string()))?;
|
||||||
|
|
||||||
// we clone here to drop the lock before entering the match
|
// we clone here to drop the lock before entering the match
|
||||||
let index = self.index_map.read().unwrap().get(name).cloned();
|
let index = self.index_map.read().unwrap().get(&uuid).cloned();
|
||||||
let index = match index {
|
let index = match index {
|
||||||
Some(index) => index,
|
Some(index) => index,
|
||||||
// since we're lazy, it's possible that the index doesn't exist yet.
|
// since we're lazy, it's possible that the index has not been opened yet.
|
||||||
// We need to open it ourselves.
|
|
||||||
None => {
|
None => {
|
||||||
let mut index_map = self.index_map.write().unwrap();
|
let mut index_map = self.index_map.write().unwrap();
|
||||||
// between the read lock and the write lock it's not impossible
|
// between the read lock and the write lock it's not impossible
|
||||||
@ -106,7 +107,7 @@ impl IndexScheduler {
|
|||||||
// if it's not already there.
|
// if it's not already there.
|
||||||
// Since there is a good chance it's not already there we can use
|
// Since there is a good chance it's not already there we can use
|
||||||
// the entry method.
|
// the entry method.
|
||||||
match index_map.entry(name.to_string()) {
|
match index_map.entry(uuid) {
|
||||||
Entry::Vacant(entry) => {
|
Entry::Vacant(entry) => {
|
||||||
// TODO: TAMO: get the args from somewhere.
|
// TODO: TAMO: get the args from somewhere.
|
||||||
let index = Index::open(
|
let index = Index::open(
|
||||||
|
Loading…
Reference in New Issue
Block a user