2023-01-24 16:17:23 +01:00
|
|
|
use std::collections::BTreeSet;
|
2022-10-22 16:35:42 +02:00
|
|
|
use std::fmt::Write;
|
|
|
|
|
2023-11-23 12:07:35 +01:00
|
|
|
use meilisearch_types::heed::types::{SerdeBincode, SerdeJson, Str};
|
2022-10-20 18:00:07 +02:00
|
|
|
use meilisearch_types::heed::{Database, RoTxn};
|
2022-10-19 12:59:12 +02:00
|
|
|
use meilisearch_types::milli::{CboRoaringBitmapCodec, RoaringBitmapCodec, BEU32};
|
2022-10-20 18:00:07 +02:00
|
|
|
use meilisearch_types::tasks::{Details, Task};
|
2022-10-10 12:57:17 +02:00
|
|
|
use roaring::RoaringBitmap;
|
|
|
|
|
2022-10-20 18:00:07 +02:00
|
|
|
use crate::index_mapper::IndexMapper;
|
|
|
|
use crate::{IndexScheduler, Kind, Status, BEI128};
|
2022-10-10 12:57:17 +02:00
|
|
|
|
2022-10-10 15:51:28 +02:00
|
|
|
pub fn snapshot_index_scheduler(scheduler: &IndexScheduler) -> String {
|
2022-11-28 16:27:41 +01:00
|
|
|
scheduler.assert_internally_consistent();
|
|
|
|
|
2022-10-10 12:57:17 +02:00
|
|
|
let IndexScheduler {
|
2022-10-11 11:58:33 +02:00
|
|
|
autobatching_enabled,
|
2024-02-20 12:16:50 +01:00
|
|
|
cleanup_enabled: _,
|
2022-10-19 12:59:12 +02:00
|
|
|
must_stop_processing: _,
|
2022-10-10 12:57:17 +02:00
|
|
|
processing_tasks,
|
2022-10-18 15:04:14 +02:00
|
|
|
file_store,
|
2022-10-10 12:57:17 +02:00
|
|
|
env,
|
|
|
|
all_tasks,
|
|
|
|
status,
|
|
|
|
kind,
|
|
|
|
index_tasks,
|
2022-11-28 16:27:41 +01:00
|
|
|
canceled_by,
|
2022-10-19 12:59:12 +02:00
|
|
|
enqueued_at,
|
|
|
|
started_at,
|
|
|
|
finished_at,
|
2022-10-10 12:57:17 +02:00
|
|
|
index_mapper,
|
2023-06-22 22:56:44 +02:00
|
|
|
features: _,
|
2023-04-25 17:26:34 +02:00
|
|
|
max_number_of_tasks: _,
|
2023-12-11 16:08:39 +01:00
|
|
|
max_number_of_batched_tasks: _,
|
2022-10-10 12:57:17 +02:00
|
|
|
wake_up: _,
|
2022-10-17 19:24:06 +02:00
|
|
|
dumps_path: _,
|
2022-10-25 10:53:25 +02:00
|
|
|
snapshots_path: _,
|
2022-10-25 14:35:10 +02:00
|
|
|
auth_path: _,
|
2022-10-25 15:06:28 +02:00
|
|
|
version_file_path: _,
|
2023-11-27 15:11:22 +01:00
|
|
|
webhook_url: _,
|
2023-12-19 12:18:45 +01:00
|
|
|
webhook_authorization_header: _,
|
2022-10-10 12:57:17 +02:00
|
|
|
test_breakpoint_sdr: _,
|
2022-10-20 17:11:44 +02:00
|
|
|
planned_failures: _,
|
|
|
|
run_loop_iteration: _,
|
2023-11-15 15:46:37 +01:00
|
|
|
embedders: _,
|
2022-10-10 12:57:17 +02:00
|
|
|
} = scheduler;
|
|
|
|
|
|
|
|
let rtxn = env.read_txn().unwrap();
|
|
|
|
|
|
|
|
let mut snap = String::new();
|
|
|
|
|
2022-10-17 17:19:17 +02:00
|
|
|
let processing_tasks = processing_tasks.read().unwrap().processing.clone();
|
2022-10-20 18:00:07 +02:00
|
|
|
snap.push_str(&format!("### Autobatching Enabled = {autobatching_enabled}\n"));
|
2022-10-10 12:57:17 +02:00
|
|
|
snap.push_str("### Processing Tasks:\n");
|
|
|
|
snap.push_str(&snapshot_bitmap(&processing_tasks));
|
|
|
|
snap.push_str("\n----------------------------------------------------------------------\n");
|
|
|
|
|
|
|
|
snap.push_str("### All Tasks:\n");
|
|
|
|
snap.push_str(&snapshot_all_tasks(&rtxn, *all_tasks));
|
|
|
|
snap.push_str("----------------------------------------------------------------------\n");
|
|
|
|
|
|
|
|
snap.push_str("### Status:\n");
|
|
|
|
snap.push_str(&snapshot_status(&rtxn, *status));
|
|
|
|
snap.push_str("----------------------------------------------------------------------\n");
|
|
|
|
|
|
|
|
snap.push_str("### Kind:\n");
|
|
|
|
snap.push_str(&snapshot_kind(&rtxn, *kind));
|
|
|
|
snap.push_str("----------------------------------------------------------------------\n");
|
|
|
|
|
|
|
|
snap.push_str("### Index Tasks:\n");
|
|
|
|
snap.push_str(&snapshot_index_tasks(&rtxn, *index_tasks));
|
|
|
|
snap.push_str("----------------------------------------------------------------------\n");
|
|
|
|
|
|
|
|
snap.push_str("### Index Mapper:\n");
|
|
|
|
snap.push_str(&snapshot_index_mapper(&rtxn, index_mapper));
|
|
|
|
snap.push_str("\n----------------------------------------------------------------------\n");
|
|
|
|
|
2022-11-28 16:27:41 +01:00
|
|
|
snap.push_str("### Canceled By:\n");
|
|
|
|
snap.push_str(&snapshot_canceled_by(&rtxn, *canceled_by));
|
|
|
|
snap.push_str("\n----------------------------------------------------------------------\n");
|
|
|
|
|
2022-10-19 12:59:12 +02:00
|
|
|
snap.push_str("### Enqueued At:\n");
|
|
|
|
snap.push_str(&snapshot_date_db(&rtxn, *enqueued_at));
|
|
|
|
snap.push_str("----------------------------------------------------------------------\n");
|
|
|
|
|
|
|
|
snap.push_str("### Started At:\n");
|
|
|
|
snap.push_str(&snapshot_date_db(&rtxn, *started_at));
|
|
|
|
snap.push_str("----------------------------------------------------------------------\n");
|
|
|
|
|
|
|
|
snap.push_str("### Finished At:\n");
|
|
|
|
snap.push_str(&snapshot_date_db(&rtxn, *finished_at));
|
|
|
|
snap.push_str("----------------------------------------------------------------------\n");
|
|
|
|
|
2022-10-18 15:04:14 +02:00
|
|
|
snap.push_str("### File Store:\n");
|
|
|
|
snap.push_str(&snapshot_file_store(file_store));
|
|
|
|
snap.push_str("\n----------------------------------------------------------------------\n");
|
|
|
|
|
2022-10-10 12:57:17 +02:00
|
|
|
snap
|
|
|
|
}
|
|
|
|
|
2022-10-20 17:11:44 +02:00
|
|
|
pub fn snapshot_file_store(file_store: &file_store::FileStore) -> String {
|
2022-10-18 15:04:14 +02:00
|
|
|
let mut snap = String::new();
|
2023-01-24 16:17:23 +01:00
|
|
|
// we store the uuid in a `BTreeSet` to keep them ordered.
|
|
|
|
let all_uuids = file_store.all_uuids().unwrap().collect::<Result<BTreeSet<_>, _>>().unwrap();
|
|
|
|
for uuid in all_uuids {
|
2022-10-18 15:04:14 +02:00
|
|
|
snap.push_str(&format!("{uuid}\n"));
|
|
|
|
}
|
|
|
|
snap
|
|
|
|
}
|
|
|
|
|
2022-10-20 17:11:44 +02:00
|
|
|
pub fn snapshot_bitmap(r: &RoaringBitmap) -> String {
|
2022-10-10 12:57:17 +02:00
|
|
|
let mut snap = String::new();
|
|
|
|
snap.push('[');
|
|
|
|
for x in r {
|
|
|
|
snap.push_str(&format!("{x},"));
|
|
|
|
}
|
|
|
|
snap.push(']');
|
|
|
|
snap
|
|
|
|
}
|
|
|
|
|
2023-11-23 12:07:35 +01:00
|
|
|
pub fn snapshot_all_tasks(rtxn: &RoTxn, db: Database<BEU32, SerdeJson<Task>>) -> String {
|
2022-10-10 12:57:17 +02:00
|
|
|
let mut snap = String::new();
|
2022-10-22 16:35:42 +02:00
|
|
|
let iter = db.iter(rtxn).unwrap();
|
|
|
|
for next in iter {
|
2022-10-10 12:57:17 +02:00
|
|
|
let (task_id, task) = next.unwrap();
|
|
|
|
snap.push_str(&format!("{task_id} {}\n", snapshot_task(&task)));
|
|
|
|
}
|
|
|
|
snap
|
|
|
|
}
|
|
|
|
|
2023-11-23 12:07:35 +01:00
|
|
|
pub fn snapshot_date_db(rtxn: &RoTxn, db: Database<BEI128, CboRoaringBitmapCodec>) -> String {
|
2022-10-19 12:59:12 +02:00
|
|
|
let mut snap = String::new();
|
2022-10-22 16:35:42 +02:00
|
|
|
let iter = db.iter(rtxn).unwrap();
|
|
|
|
for next in iter {
|
2022-10-19 12:59:12 +02:00
|
|
|
let (_timestamp, task_ids) = next.unwrap();
|
|
|
|
snap.push_str(&format!("[timestamp] {}\n", snapshot_bitmap(&task_ids)));
|
|
|
|
}
|
|
|
|
snap
|
|
|
|
}
|
|
|
|
|
2022-10-20 17:11:44 +02:00
|
|
|
pub fn snapshot_task(task: &Task) -> String {
|
2022-10-10 12:57:17 +02:00
|
|
|
let mut snap = String::new();
|
|
|
|
let Task {
|
|
|
|
uid,
|
|
|
|
enqueued_at: _,
|
|
|
|
started_at: _,
|
|
|
|
finished_at: _,
|
|
|
|
error,
|
2022-10-25 11:42:14 +02:00
|
|
|
canceled_by,
|
2022-10-10 12:57:17 +02:00
|
|
|
details,
|
|
|
|
status,
|
|
|
|
kind,
|
|
|
|
} = task;
|
|
|
|
snap.push('{');
|
|
|
|
snap.push_str(&format!("uid: {uid}, "));
|
|
|
|
snap.push_str(&format!("status: {status}, "));
|
2022-10-25 11:42:14 +02:00
|
|
|
if let Some(canceled_by) = canceled_by {
|
|
|
|
snap.push_str(&format!("canceled_by: {canceled_by}, "));
|
|
|
|
}
|
2022-10-10 12:57:17 +02:00
|
|
|
if let Some(error) = error {
|
|
|
|
snap.push_str(&format!("error: {error:?}, "));
|
|
|
|
}
|
|
|
|
if let Some(details) = details {
|
2022-10-25 10:18:18 +02:00
|
|
|
snap.push_str(&format!("details: {}, ", &snapshot_details(details)));
|
2022-10-10 12:57:17 +02:00
|
|
|
}
|
|
|
|
snap.push_str(&format!("kind: {kind:?}"));
|
|
|
|
|
|
|
|
snap.push('}');
|
|
|
|
snap
|
|
|
|
}
|
2022-10-20 18:00:07 +02:00
|
|
|
|
2022-10-25 10:18:18 +02:00
|
|
|
fn snapshot_details(d: &Details) -> String {
|
2022-10-10 12:57:17 +02:00
|
|
|
match d {
|
2022-10-21 18:03:10 +02:00
|
|
|
Details::DocumentAdditionOrUpdate {
|
2022-10-10 12:57:17 +02:00
|
|
|
received_documents,
|
|
|
|
indexed_documents,
|
|
|
|
} => {
|
2022-10-17 19:24:06 +02:00
|
|
|
format!("{{ received_documents: {received_documents}, indexed_documents: {indexed_documents:?} }}")
|
2022-10-10 12:57:17 +02:00
|
|
|
}
|
2024-05-08 15:26:21 +02:00
|
|
|
Details::DocumentEdition {
|
|
|
|
edited_documents,
|
|
|
|
edition_code,
|
2024-05-08 15:53:40 +02:00
|
|
|
original_filter,
|
2024-05-08 15:26:21 +02:00
|
|
|
} => {
|
2024-05-08 15:53:40 +02:00
|
|
|
format!("{{ edited_documents: {edited_documents:?}, edition_code: {edition_code:?}, original_filter: {original_filter:?} }}")
|
2024-05-08 15:26:21 +02:00
|
|
|
}
|
2022-10-21 18:03:10 +02:00
|
|
|
Details::SettingsUpdate { settings } => {
|
2022-10-10 12:57:17 +02:00
|
|
|
format!("{{ settings: {settings:?} }}")
|
|
|
|
}
|
|
|
|
Details::IndexInfo { primary_key } => {
|
|
|
|
format!("{{ primary_key: {primary_key:?} }}")
|
|
|
|
}
|
|
|
|
Details::DocumentDeletion {
|
2022-11-28 16:27:41 +01:00
|
|
|
provided_ids: received_document_ids,
|
2022-10-10 12:57:17 +02:00
|
|
|
deleted_documents,
|
|
|
|
} => format!("{{ received_document_ids: {received_document_ids}, deleted_documents: {deleted_documents:?} }}"),
|
2023-03-07 10:02:04 +01:00
|
|
|
Details::DocumentDeletionByFilter { original_filter, deleted_documents } => format!(
|
|
|
|
"{{ original_filter: {original_filter}, deleted_documents: {deleted_documents:?} }}"
|
|
|
|
),
|
2022-10-10 12:57:17 +02:00
|
|
|
Details::ClearAll { deleted_documents } => {
|
|
|
|
format!("{{ deleted_documents: {deleted_documents:?} }}")
|
|
|
|
},
|
2022-10-17 17:19:17 +02:00
|
|
|
Details::TaskCancelation {
|
|
|
|
matched_tasks,
|
|
|
|
canceled_tasks,
|
2022-11-28 16:27:41 +01:00
|
|
|
original_filter,
|
2022-10-17 17:19:17 +02:00
|
|
|
} => {
|
2022-11-28 16:27:41 +01:00
|
|
|
format!("{{ matched_tasks: {matched_tasks:?}, canceled_tasks: {canceled_tasks:?}, original_filter: {original_filter:?} }}")
|
2022-10-17 17:19:17 +02:00
|
|
|
}
|
2022-10-13 11:09:00 +02:00
|
|
|
Details::TaskDeletion {
|
2022-10-10 12:57:17 +02:00
|
|
|
matched_tasks,
|
|
|
|
deleted_tasks,
|
2022-11-28 16:27:41 +01:00
|
|
|
original_filter,
|
2022-10-10 12:57:17 +02:00
|
|
|
} => {
|
2022-11-28 16:27:41 +01:00
|
|
|
format!("{{ matched_tasks: {matched_tasks:?}, deleted_tasks: {deleted_tasks:?}, original_filter: {original_filter:?} }}")
|
2022-10-10 12:57:17 +02:00
|
|
|
},
|
|
|
|
Details::Dump { dump_uid } => {
|
|
|
|
format!("{{ dump_uid: {dump_uid:?} }}")
|
|
|
|
},
|
2022-10-17 16:30:18 +02:00
|
|
|
Details::IndexSwap { swaps } => {
|
2022-10-26 12:57:29 +02:00
|
|
|
format!("{{ swaps: {swaps:?} }}")
|
2022-10-20 18:00:07 +02:00
|
|
|
}
|
2022-10-10 12:57:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-20 17:11:44 +02:00
|
|
|
pub fn snapshot_status(
|
|
|
|
rtxn: &RoTxn,
|
|
|
|
db: Database<SerdeBincode<Status>, RoaringBitmapCodec>,
|
|
|
|
) -> String {
|
2022-10-10 12:57:17 +02:00
|
|
|
let mut snap = String::new();
|
2022-10-22 16:35:42 +02:00
|
|
|
let iter = db.iter(rtxn).unwrap();
|
|
|
|
for next in iter {
|
2022-10-10 12:57:17 +02:00
|
|
|
let (status, task_ids) = next.unwrap();
|
2022-10-22 17:17:09 +02:00
|
|
|
writeln!(snap, "{status} {}", snapshot_bitmap(&task_ids)).unwrap();
|
2022-10-10 12:57:17 +02:00
|
|
|
}
|
|
|
|
snap
|
|
|
|
}
|
2022-10-20 17:11:44 +02:00
|
|
|
pub fn snapshot_kind(rtxn: &RoTxn, db: Database<SerdeBincode<Kind>, RoaringBitmapCodec>) -> String {
|
2022-10-10 12:57:17 +02:00
|
|
|
let mut snap = String::new();
|
2022-10-22 16:35:42 +02:00
|
|
|
let iter = db.iter(rtxn).unwrap();
|
|
|
|
for next in iter {
|
2022-10-10 12:57:17 +02:00
|
|
|
let (kind, task_ids) = next.unwrap();
|
|
|
|
let kind = serde_json::to_string(&kind).unwrap();
|
2022-10-22 17:17:09 +02:00
|
|
|
writeln!(snap, "{kind} {}", snapshot_bitmap(&task_ids)).unwrap();
|
2022-10-10 12:57:17 +02:00
|
|
|
}
|
|
|
|
snap
|
|
|
|
}
|
|
|
|
|
2022-10-20 17:11:44 +02:00
|
|
|
pub fn snapshot_index_tasks(rtxn: &RoTxn, db: Database<Str, RoaringBitmapCodec>) -> String {
|
2022-10-10 12:57:17 +02:00
|
|
|
let mut snap = String::new();
|
2022-10-22 16:35:42 +02:00
|
|
|
let iter = db.iter(rtxn).unwrap();
|
|
|
|
for next in iter {
|
2022-10-10 12:57:17 +02:00
|
|
|
let (index, task_ids) = next.unwrap();
|
2022-10-22 17:17:09 +02:00
|
|
|
writeln!(snap, "{index} {}", snapshot_bitmap(&task_ids)).unwrap();
|
2022-10-10 12:57:17 +02:00
|
|
|
}
|
|
|
|
snap
|
|
|
|
}
|
2023-11-23 12:07:35 +01:00
|
|
|
pub fn snapshot_canceled_by(rtxn: &RoTxn, db: Database<BEU32, RoaringBitmapCodec>) -> String {
|
2022-11-28 16:27:41 +01:00
|
|
|
let mut snap = String::new();
|
|
|
|
let iter = db.iter(rtxn).unwrap();
|
|
|
|
for next in iter {
|
|
|
|
let (kind, task_ids) = next.unwrap();
|
|
|
|
writeln!(snap, "{kind} {}", snapshot_bitmap(&task_ids)).unwrap();
|
|
|
|
}
|
|
|
|
snap
|
|
|
|
}
|
2022-10-20 17:11:44 +02:00
|
|
|
pub fn snapshot_index_mapper(rtxn: &RoTxn, mapper: &IndexMapper) -> String {
|
2023-02-23 19:53:58 +01:00
|
|
|
let mut s = String::new();
|
2023-02-20 16:42:54 +01:00
|
|
|
let names = mapper.index_names(rtxn).unwrap();
|
2023-02-23 19:53:58 +01:00
|
|
|
|
|
|
|
for name in names {
|
|
|
|
let stats = mapper.stats_of(rtxn, &name).unwrap();
|
|
|
|
s.push_str(&format!(
|
|
|
|
"{name}: {{ number_of_documents: {}, field_distribution: {:?} }}\n",
|
|
|
|
stats.number_of_documents, stats.field_distribution
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
s
|
2022-10-10 12:57:17 +02:00
|
|
|
}
|