mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-12 07:36:29 +00:00
fix stats
This commit is contained in:
@ -10,7 +10,7 @@ use tokio::sync::mpsc;
|
||||
use uuid::Uuid;
|
||||
use futures::StreamExt;
|
||||
|
||||
use super::{PayloadData, Result, UpdateError, UpdateMsg, UpdateStore};
|
||||
use super::{PayloadData, Result, UpdateError, UpdateMsg, UpdateStore, UpdateStoreInfo};
|
||||
use crate::index_controller::index_actor::{IndexActorHandle, CONCURRENT_INDEX_MSG};
|
||||
use crate::index_controller::{UpdateMeta, UpdateStatus};
|
||||
|
||||
@ -81,8 +81,8 @@ where
|
||||
Some(Snapshot { uuids, path, ret }) => {
|
||||
let _ = ret.send(self.handle_snapshot(uuids, path).await);
|
||||
}
|
||||
Some(GetSize { ret }) => {
|
||||
let _ = ret.send(self.handle_get_size().await);
|
||||
Some(GetInfo { ret }) => {
|
||||
let _ = ret.send(self.handle_get_info().await);
|
||||
}
|
||||
None => break,
|
||||
}
|
||||
@ -232,17 +232,27 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_get_size(&self) -> Result<u64> {
|
||||
async fn handle_get_info(&self) -> Result<UpdateStoreInfo> {
|
||||
let update_store = self.store.clone();
|
||||
let size = tokio::task::spawn_blocking(move || -> anyhow::Result<u64> {
|
||||
let processing = self.store.processing.clone();
|
||||
let info = tokio::task::spawn_blocking(move || -> anyhow::Result<UpdateStoreInfo> {
|
||||
let txn = update_store.env.read_txn()?;
|
||||
|
||||
update_store.get_size(&txn)
|
||||
let size = update_store.get_size(&txn)?;
|
||||
let processing = processing
|
||||
.read()
|
||||
.as_ref()
|
||||
.map(|(uuid, _)| uuid)
|
||||
.cloned();
|
||||
let info = UpdateStoreInfo {
|
||||
size, processing
|
||||
};
|
||||
Ok(info)
|
||||
})
|
||||
.await
|
||||
.map_err(|e| UpdateError::Error(e.into()))?
|
||||
.map_err(|e| UpdateError::Error(e.into()))?;
|
||||
|
||||
Ok(size)
|
||||
|
||||
Ok(info)
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use uuid::Uuid;
|
||||
use crate::index_controller::IndexActorHandle;
|
||||
|
||||
use super::{
|
||||
PayloadData, Result, UpdateActor, UpdateActorHandle, UpdateMeta, UpdateMsg, UpdateStatus,
|
||||
PayloadData, Result, UpdateActor, UpdateActorHandle, UpdateMeta, UpdateMsg, UpdateStatus, UpdateStoreInfo
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -70,9 +70,9 @@ where
|
||||
receiver.await.expect("update actor killed.")
|
||||
}
|
||||
|
||||
async fn get_size(&self) -> Result<u64> {
|
||||
async fn get_info(&self) -> Result<UpdateStoreInfo> {
|
||||
let (ret, receiver) = oneshot::channel();
|
||||
let msg = UpdateMsg::GetSize { ret };
|
||||
let msg = UpdateMsg::GetInfo { ret };
|
||||
let _ = self.sender.send(msg).await;
|
||||
receiver.await.expect("update actor killed.")
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use std::path::PathBuf;
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::{PayloadData, Result, UpdateMeta, UpdateStatus};
|
||||
use super::{PayloadData, Result, UpdateMeta, UpdateStatus, UpdateStoreInfo};
|
||||
|
||||
pub enum UpdateMsg<D> {
|
||||
Update {
|
||||
@ -30,7 +30,7 @@ pub enum UpdateMsg<D> {
|
||||
path: PathBuf,
|
||||
ret: oneshot::Sender<Result<()>>,
|
||||
},
|
||||
GetSize {
|
||||
ret: oneshot::Sender<Result<u64>>,
|
||||
GetInfo {
|
||||
ret: oneshot::Sender<Result<UpdateStoreInfo>>,
|
||||
},
|
||||
}
|
||||
|
@ -32,6 +32,14 @@ pub enum UpdateError {
|
||||
UnexistingUpdate(u64),
|
||||
}
|
||||
|
||||
pub struct UpdateStoreInfo {
|
||||
/// Size of the update store in bytes.
|
||||
pub size: u64,
|
||||
/// Uuid of the currently processing update if it exists
|
||||
pub processing: Option<Uuid>,
|
||||
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
#[cfg_attr(test, automock(type Data=Vec<u8>;))]
|
||||
pub trait UpdateActorHandle {
|
||||
@ -41,7 +49,7 @@ pub trait UpdateActorHandle {
|
||||
async fn update_status(&self, uuid: Uuid, id: u64) -> Result<UpdateStatus>;
|
||||
async fn delete(&self, uuid: Uuid) -> Result<()>;
|
||||
async fn snapshot(&self, uuids: Vec<Uuid>, path: PathBuf) -> Result<()>;
|
||||
async fn get_size(&self) -> Result<u64>;
|
||||
async fn get_info(&self) -> Result<UpdateStoreInfo>;
|
||||
async fn update(
|
||||
&self,
|
||||
meta: UpdateMeta,
|
||||
|
@ -67,7 +67,7 @@ pub struct UpdateStore<M, N, E> {
|
||||
processed_meta: Database<ByteSlice, SerdeJson<Processed<M, N>>>,
|
||||
failed_meta: Database<ByteSlice, SerdeJson<Failed<M, E>>>,
|
||||
aborted_meta: Database<ByteSlice, SerdeJson<Aborted<M>>>,
|
||||
processing: Arc<RwLock<Option<(Uuid, Processing<M>)>>>,
|
||||
pub processing: Arc<RwLock<Option<(Uuid, Processing<M>)>>>,
|
||||
notification_sender: mpsc::Sender<()>,
|
||||
/// A lock on the update loop. This is meant to prevent a snapshot to occur while an update is
|
||||
/// processing, while not preventing writes all together during an update
|
||||
|
Reference in New Issue
Block a user