diff --git a/meilisearch-http/src/index_controller/index_actor/actor.rs b/meilisearch-http/src/index_controller/index_actor/actor.rs index 6d0c1e8cd..d56c53fcd 100644 --- a/meilisearch-http/src/index_controller/index_actor/actor.rs +++ b/meilisearch-http/src/index_controller/index_actor/actor.rs @@ -348,7 +348,7 @@ impl IndexActor { Ok(IndexStats { size: index.size()?, number_of_documents: index.number_of_documents(&rtxn)?, - is_indexing: false, // TODO check actual is_indexing + is_indexing: false, // We set this field in src/index_controller/mod.rs get_stats fields_distribution: index.fields_distribution(&rtxn)?, }) }) diff --git a/meilisearch-http/src/index_controller/mod.rs b/meilisearch-http/src/index_controller/mod.rs index e459af10c..967506a55 100644 --- a/meilisearch-http/src/index_controller/mod.rs +++ b/meilisearch-http/src/index_controller/mod.rs @@ -354,7 +354,13 @@ impl IndexController { pub async fn get_stats(&self, uid: String) -> anyhow::Result { let uuid = self.uuid_resolver.get(uid.clone()).await?; - Ok(self.index_handle.get_index_stats(uuid).await?) + let stats = self.index_handle.get_index_stats(uuid); + let is_indexing = self.update_handle.is_locked(uuid); + + Ok(IndexStats { + is_indexing: is_indexing.await?, + ..stats.await? + }) } } diff --git a/meilisearch-http/src/index_controller/update_actor/actor.rs b/meilisearch-http/src/index_controller/update_actor/actor.rs index d87b910d6..c99c0059f 100644 --- a/meilisearch-http/src/index_controller/update_actor/actor.rs +++ b/meilisearch-http/src/index_controller/update_actor/actor.rs @@ -72,6 +72,9 @@ where Some(Snapshot { uuid, path, ret }) => { let _ = ret.send(self.handle_snapshot(uuid, path).await); } + Some(IsLocked { uuid, ret }) => { + let _ = ret.send(self.handle_is_locked(uuid).await); + } None => break, } } @@ -223,4 +226,14 @@ where Ok(()) } + + async fn handle_is_locked(&self, uuid: Uuid) -> Result { + let store = self + .store + .get(uuid) + .await? + .ok_or(UpdateError::UnexistingIndex(uuid))?; + + Ok(store.update_lock.is_locked()) + } } diff --git a/meilisearch-http/src/index_controller/update_actor/handle_impl.rs b/meilisearch-http/src/index_controller/update_actor/handle_impl.rs index 59f67fbe0..621675955 100644 --- a/meilisearch-http/src/index_controller/update_actor/handle_impl.rs +++ b/meilisearch-http/src/index_controller/update_actor/handle_impl.rs @@ -3,11 +3,12 @@ use std::path::{Path, PathBuf}; use tokio::sync::{mpsc, oneshot}; use uuid::Uuid; +use crate::index_controller::IndexActorHandle; + use super::{ MapUpdateStoreStore, PayloadData, Result, UpdateActor, UpdateActorHandle, UpdateMeta, UpdateMsg, UpdateStatus, }; -use crate::index_controller::IndexActorHandle; #[derive(Clone)] pub struct UpdateActorHandleImpl { @@ -36,6 +37,7 @@ where Ok(Self { sender }) } } + #[async_trait::async_trait] impl UpdateActorHandle for UpdateActorHandleImpl where @@ -43,29 +45,12 @@ where { type Data = D; - async fn update( - &self, - meta: UpdateMeta, - data: mpsc::Receiver>, - uuid: Uuid, - ) -> Result { - let (ret, receiver) = oneshot::channel(); - let msg = UpdateMsg::Update { - uuid, - data, - meta, - ret, - }; - let _ = self.sender.send(msg).await; - receiver.await.expect("update actor killed.") - } async fn get_all_updates_status(&self, uuid: Uuid) -> Result> { let (ret, receiver) = oneshot::channel(); let msg = UpdateMsg::ListUpdates { uuid, ret }; let _ = self.sender.send(msg).await; receiver.await.expect("update actor killed.") } - async fn update_status(&self, uuid: Uuid, id: u64) -> Result { let (ret, receiver) = oneshot::channel(); let msg = UpdateMsg::GetUpdate { uuid, id, ret }; @@ -93,4 +78,28 @@ where let _ = self.sender.send(msg).await; receiver.await.expect("update actor killed.") } + + async fn update( + &self, + meta: UpdateMeta, + data: mpsc::Receiver>, + uuid: Uuid, + ) -> Result { + let (ret, receiver) = oneshot::channel(); + let msg = UpdateMsg::Update { + uuid, + data, + meta, + ret, + }; + let _ = self.sender.send(msg).await; + receiver.await.expect("update actor killed.") + } + + async fn is_locked(&self, uuid: Uuid) -> Result { + let (ret, receiver) = oneshot::channel(); + let msg = UpdateMsg::IsLocked { uuid, ret }; + let _ = self.sender.send(msg).await; + receiver.await.expect("update actor killed.") + } } diff --git a/meilisearch-http/src/index_controller/update_actor/message.rs b/meilisearch-http/src/index_controller/update_actor/message.rs index 8e6e3c212..409fbcebc 100644 --- a/meilisearch-http/src/index_controller/update_actor/message.rs +++ b/meilisearch-http/src/index_controller/update_actor/message.rs @@ -34,4 +34,8 @@ pub enum UpdateMsg { path: PathBuf, ret: oneshot::Sender>, }, + IsLocked { + uuid: Uuid, + ret: oneshot::Sender>, + }, } diff --git a/meilisearch-http/src/index_controller/update_actor/mod.rs b/meilisearch-http/src/index_controller/update_actor/mod.rs index f3c3caf04..095e068e8 100644 --- a/meilisearch-http/src/index_controller/update_actor/mod.rs +++ b/meilisearch-http/src/index_controller/update_actor/mod.rs @@ -52,4 +52,5 @@ pub trait UpdateActorHandle { data: mpsc::Receiver>, uuid: Uuid, ) -> Result; + async fn is_locked(&self, uuid: Uuid) -> Result; } diff --git a/meilisearch-http/src/index_controller/update_handler.rs b/meilisearch-http/src/index_controller/update_handler.rs index 17f7107a2..1eb622cbf 100644 --- a/meilisearch-http/src/index_controller/update_handler.rs +++ b/meilisearch-http/src/index_controller/update_handler.rs @@ -39,7 +39,7 @@ impl UpdateHandler { }) } - fn update_buidler(&self, update_id: u64) -> UpdateBuilder { + fn update_builder(&self, update_id: u64) -> UpdateBuilder { // We prepare the update by using the update builder. let mut update_builder = UpdateBuilder::new(update_id); if let Some(max_nb_chunks) = self.max_nb_chunks { @@ -67,7 +67,7 @@ impl UpdateHandler { let update_id = meta.id(); - let update_builder = self.update_buidler(update_id); + let update_builder = self.update_builder(update_id); let result = match meta.meta() { DocumentsAddition { diff --git a/meilisearch-http/tests/index/stats.rs b/meilisearch-http/tests/index/stats.rs index d32c06d2b..e1d8bd211 100644 --- a/meilisearch-http/tests/index/stats.rs +++ b/meilisearch-http/tests/index/stats.rs @@ -35,6 +35,11 @@ async fn stats() { assert_eq!(code, 202); assert_eq!(response["updateId"], 0); + let (response, code) = index.stats().await; + + assert_eq!(code, 200); + assert_eq!(response["isIndexing"], true); + index.wait_update_id(0).await; let (response, code) = index.stats().await; diff --git a/meilisearch-http/tests/stats/mod.rs b/meilisearch-http/tests/stats/mod.rs index e5027c71f..ee10f9708 100644 --- a/meilisearch-http/tests/stats/mod.rs +++ b/meilisearch-http/tests/stats/mod.rs @@ -56,6 +56,11 @@ async fn stats() { assert_eq!(code, 202); assert_eq!(response["updateId"], 0); + let (response, code) = server.stats().await; + + assert_eq!(code, 200); + assert_eq!(response["indexes"]["test"]["isIndexing"], true); + index.wait_update_id(0).await; let (response, code) = server.stats().await;