mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 11:57:07 +02:00
Merge pull request #5488 from meilisearch/try-batch-end-reason
add "batcher stopped because" field to batch objects
This commit is contained in:
commit
e9b4794f2b
145 changed files with 1143 additions and 889 deletions
|
@ -21,6 +21,8 @@ pub struct BatchView {
|
|||
pub started_at: OffsetDateTime,
|
||||
#[serde(with = "time::serde::rfc3339::option", default)]
|
||||
pub finished_at: Option<OffsetDateTime>,
|
||||
#[serde(default = "meilisearch_types::batches::default_stop_reason")]
|
||||
pub batcher_stopped_because: String,
|
||||
}
|
||||
|
||||
impl BatchView {
|
||||
|
@ -33,6 +35,7 @@ impl BatchView {
|
|||
duration: batch.finished_at.map(|finished_at| finished_at - batch.started_at),
|
||||
started_at: batch.started_at,
|
||||
finished_at: batch.finished_at,
|
||||
batcher_stopped_because: batch.stop_reason.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use time::OffsetDateTime;
|
|||
use utoipa::ToSchema;
|
||||
|
||||
use crate::task_view::DetailsView;
|
||||
use crate::tasks::{Kind, Status};
|
||||
use crate::tasks::{BatchStopReason, Kind, Status};
|
||||
|
||||
pub type BatchId = u32;
|
||||
|
||||
|
@ -28,11 +28,26 @@ pub struct Batch {
|
|||
// Enqueued at is never displayed and is only required when removing a batch.
|
||||
// It's always some except when upgrading from a database pre v1.12
|
||||
pub enqueued_at: Option<BatchEnqueuedAt>,
|
||||
#[serde(default = "default_stop_reason")]
|
||||
pub stop_reason: String,
|
||||
}
|
||||
|
||||
pub fn default_stop_reason() -> String {
|
||||
BatchStopReason::default().to_string()
|
||||
}
|
||||
|
||||
impl PartialEq for Batch {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
let Self { uid, progress, details, stats, started_at, finished_at, enqueued_at } = self;
|
||||
let Self {
|
||||
uid,
|
||||
progress,
|
||||
details,
|
||||
stats,
|
||||
started_at,
|
||||
finished_at,
|
||||
enqueued_at,
|
||||
stop_reason,
|
||||
} = self;
|
||||
|
||||
*uid == other.uid
|
||||
&& progress.is_none() == other.progress.is_none()
|
||||
|
@ -41,6 +56,7 @@ impl PartialEq for Batch {
|
|||
&& started_at == &other.started_at
|
||||
&& finished_at == &other.finished_at
|
||||
&& enqueued_at == &other.enqueued_at
|
||||
&& stop_reason == &other.stop_reason
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -675,6 +675,147 @@ impl Details {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub enum BatchStopReason {
|
||||
#[default]
|
||||
Unspecified,
|
||||
TaskCannotBeBatched {
|
||||
kind: Kind,
|
||||
id: TaskId,
|
||||
},
|
||||
TaskKindCannotBeBatched {
|
||||
kind: Kind,
|
||||
},
|
||||
ExhaustedEnqueuedTasks,
|
||||
ExhaustedEnqueuedTasksForIndex {
|
||||
index: String,
|
||||
},
|
||||
ReachedTaskLimit {
|
||||
task_limit: usize,
|
||||
},
|
||||
ReachedSizeLimit {
|
||||
size_limit: u64,
|
||||
size: u64,
|
||||
},
|
||||
PrimaryKeyIndexMismatch {
|
||||
id: TaskId,
|
||||
in_index: String,
|
||||
in_task: String,
|
||||
},
|
||||
IndexCreationMismatch {
|
||||
id: TaskId,
|
||||
},
|
||||
PrimaryKeyMismatch {
|
||||
id: TaskId,
|
||||
reason: PrimaryKeyMismatchReason,
|
||||
},
|
||||
IndexDeletion {
|
||||
id: TaskId,
|
||||
},
|
||||
DocumentOperationWithSettings {
|
||||
id: TaskId,
|
||||
},
|
||||
DocumentOperationWithDeletionByFilter {
|
||||
id: TaskId,
|
||||
},
|
||||
DeletionByFilterWithDocumentOperation {
|
||||
id: TaskId,
|
||||
},
|
||||
SettingsWithDocumentOperation {
|
||||
id: TaskId,
|
||||
},
|
||||
}
|
||||
|
||||
impl BatchStopReason {
|
||||
pub fn replace_unspecified(&mut self, new: BatchStopReason) {
|
||||
if let BatchStopReason::Unspecified = self {
|
||||
*self = new;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum PrimaryKeyMismatchReason {
|
||||
TaskPrimaryKeyDifferFromIndexPrimaryKey { task_pk: String, index_pk: String },
|
||||
TaskPrimaryKeyDifferFromCurrentBatchPrimaryKey { task_pk: String, batch_pk: String },
|
||||
CannotInterfereWithPrimaryKeyGuessing { task_pk: String },
|
||||
}
|
||||
|
||||
impl Display for BatchStopReason {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
BatchStopReason::Unspecified => f.write_str("unspecified"),
|
||||
BatchStopReason::TaskKindCannotBeBatched { kind } => {
|
||||
write!(f, "a batch of tasks of type `{kind}` cannot be batched with any other type of task")
|
||||
}
|
||||
BatchStopReason::TaskCannotBeBatched { kind, id } => {
|
||||
write!(f, "task with id {id} of type `{kind}` cannot be batched")
|
||||
}
|
||||
BatchStopReason::ExhaustedEnqueuedTasks => f.write_str("batched all enqueued tasks"),
|
||||
BatchStopReason::ExhaustedEnqueuedTasksForIndex { index } => {
|
||||
write!(f, "batched all enqueued tasks for index `{index}`")
|
||||
}
|
||||
BatchStopReason::ReachedTaskLimit { task_limit } => {
|
||||
write!(f, "reached configured batch limit of {task_limit} tasks")
|
||||
}
|
||||
BatchStopReason::ReachedSizeLimit { size_limit, size } => write!(
|
||||
f,
|
||||
"reached configured batch size limit of {size_limit}B with a total of {size}B"
|
||||
),
|
||||
BatchStopReason::PrimaryKeyIndexMismatch { id, in_index, in_task } => {
|
||||
write!(f, "primary key `{in_task}` in task with id {id} is different from the primary key of the index `{in_index}`")
|
||||
}
|
||||
BatchStopReason::IndexCreationMismatch { id } => {
|
||||
write!(f, "task with id {id} has different index creation rules as in the batch")
|
||||
}
|
||||
BatchStopReason::PrimaryKeyMismatch { reason, id } => match reason {
|
||||
PrimaryKeyMismatchReason::TaskPrimaryKeyDifferFromIndexPrimaryKey {
|
||||
task_pk,
|
||||
index_pk,
|
||||
} => {
|
||||
write!(f, "primary key `{task_pk}` in task with id {id} is different from the primary key of the index `{index_pk}`")
|
||||
}
|
||||
PrimaryKeyMismatchReason::TaskPrimaryKeyDifferFromCurrentBatchPrimaryKey {
|
||||
task_pk,
|
||||
batch_pk,
|
||||
} => {
|
||||
write!(f, "primary key `{task_pk}` in task with id {id} is different from the primary key of the batch `{batch_pk}`")
|
||||
}
|
||||
PrimaryKeyMismatchReason::CannotInterfereWithPrimaryKeyGuessing { task_pk } => {
|
||||
write!(f, "task with id {id} is setting the `{task_pk}` primary key but cannot interfere with primary key guessing of the batch")
|
||||
}
|
||||
},
|
||||
BatchStopReason::IndexDeletion { id } => {
|
||||
write!(f, "task with id {id} deletes the index")
|
||||
}
|
||||
BatchStopReason::DocumentOperationWithSettings { id } => {
|
||||
write!(
|
||||
f,
|
||||
"task with id {id} is a settings change in a batch of document operations"
|
||||
)
|
||||
}
|
||||
BatchStopReason::DocumentOperationWithDeletionByFilter { id } => {
|
||||
write!(
|
||||
f,
|
||||
"task with id {id} is a deletion by filter in a batch of document operations"
|
||||
)
|
||||
}
|
||||
BatchStopReason::DeletionByFilterWithDocumentOperation { id } => {
|
||||
write!(
|
||||
f,
|
||||
"task with id {id} is a document operation in a batch of deletions by filter"
|
||||
)
|
||||
}
|
||||
BatchStopReason::SettingsWithDocumentOperation { id } => {
|
||||
write!(
|
||||
f,
|
||||
"task with id {id} is a document operation in a batch of settings changes"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Serialize a `time::Duration` as a best effort ISO 8601 while waiting for
|
||||
/// https://github.com/time-rs/time/issues/378.
|
||||
/// This code is a port of the old code of time that was removed in 0.2.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue