mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
introduce index resolver
This commit is contained in:
parent
5353be74c3
commit
42a6260b65
23 changed files with 833 additions and 193 deletions
|
@ -42,7 +42,7 @@ pub fn create_indexes_handler(
|
|||
indexer_options: &IndexerOpts,
|
||||
) -> anyhow::Result<IndexHandlerSender> {
|
||||
let (sender, receiver) = mpsc::channel(100);
|
||||
let store = MapIndexStore::new(&db_path, index_size);
|
||||
let store = MapIndexStore::new(&db_path, index_size, indexer_options);
|
||||
let actor = IndexActor::new(receiver, store, indexer_options)?;
|
||||
|
||||
tokio::task::spawn(actor.run());
|
||||
|
@ -59,7 +59,7 @@ pub struct IndexMeta {
|
|||
}
|
||||
|
||||
impl IndexMeta {
|
||||
fn new(index: &Index) -> Result<Self> {
|
||||
pub fn new(index: &Index) -> Result<Self> {
|
||||
let txn = index.read_txn()?;
|
||||
Self::new_txn(index, &txn)
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ where
|
|||
None => self.store.create(uuid, None).await?,
|
||||
};
|
||||
|
||||
Ok(spawn_blocking(move || update_handler.handle_update(index, meta)).await?)
|
||||
Ok(spawn_blocking(move || update_handler.handle_update(&index, meta)).await?)
|
||||
}
|
||||
|
||||
async fn handle_settings(&self, uuid: Uuid) -> Result<Settings<Checked>> {
|
||||
|
|
|
@ -10,6 +10,7 @@ use uuid::Uuid;
|
|||
|
||||
use super::error::{IndexActorError, Result};
|
||||
use crate::index::Index;
|
||||
use crate::index::update_handler::UpdateHandler;
|
||||
use crate::index_controller::update_file_store::UpdateFileStore;
|
||||
|
||||
type AsyncMap<K, V> = Arc<RwLock<HashMap<K, V>>>;
|
||||
|
@ -26,10 +27,11 @@ pub struct MapIndexStore {
|
|||
path: PathBuf,
|
||||
index_size: usize,
|
||||
update_file_store: Arc<UpdateFileStore>,
|
||||
update_handler: Arc<UpdateHandler>,
|
||||
}
|
||||
|
||||
impl MapIndexStore {
|
||||
pub fn new(path: impl AsRef<Path>, index_size: usize) -> Self {
|
||||
pub fn new(path: impl AsRef<Path>, index_size: usize, update_handler: Arc<UpdateHandler>) -> Self {
|
||||
let update_file_store = Arc::new(UpdateFileStore::new(path.as_ref()).unwrap());
|
||||
let path = path.as_ref().join("indexes/");
|
||||
let index_store = Arc::new(RwLock::new(HashMap::new()));
|
||||
|
@ -38,6 +40,7 @@ impl MapIndexStore {
|
|||
path,
|
||||
index_size,
|
||||
update_file_store,
|
||||
update_handler,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,8 +62,9 @@ impl IndexStore for MapIndexStore {
|
|||
|
||||
let index_size = self.index_size;
|
||||
let file_store = self.update_file_store.clone();
|
||||
let update_handler = self.update_handler.clone();
|
||||
let index = spawn_blocking(move || -> Result<Index> {
|
||||
let index = Index::open(path, index_size, file_store)?;
|
||||
let index = Index::open(path, index_size, file_store, uuid, update_handler)?;
|
||||
if let Some(primary_key) = primary_key {
|
||||
let mut txn = index.write_txn()?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue