2022-10-22 22:35:42 +08:00
|
|
|
use std::fmt::Write;
|
|
|
|
|
2022-10-21 00:00:07 +08:00
|
|
|
use meilisearch_types::heed::types::{OwnedType, SerdeBincode, SerdeJson, Str};
|
|
|
|
use meilisearch_types::heed::{Database, RoTxn};
|
2022-10-19 18:59:12 +08:00
|
|
|
use meilisearch_types::milli::{CboRoaringBitmapCodec, RoaringBitmapCodec, BEU32};
|
2022-10-21 00:00:07 +08:00
|
|
|
use meilisearch_types::tasks::{Details, Task};
|
2022-10-10 18:57:17 +08:00
|
|
|
use roaring::RoaringBitmap;
|
|
|
|
|
2022-10-21 00:00:07 +08:00
|
|
|
use crate::index_mapper::IndexMapper;
|
|
|
|
use crate::{IndexScheduler, Kind, Status, BEI128};
|
2022-10-10 18:57:17 +08:00
|
|
|
|
2022-10-10 21:51:28 +08:00
|
|
|
pub fn snapshot_index_scheduler(scheduler: &IndexScheduler) -> String {
|
2022-10-10 18:57:17 +08:00
|
|
|
let IndexScheduler {
|
2022-10-11 17:58:33 +08:00
|
|
|
autobatching_enabled,
|
2022-10-19 18:59:12 +08:00
|
|
|
must_stop_processing: _,
|
2022-10-10 18:57:17 +08:00
|
|
|
processing_tasks,
|
2022-10-18 21:04:14 +08:00
|
|
|
file_store,
|
2022-10-10 18:57:17 +08:00
|
|
|
env,
|
|
|
|
all_tasks,
|
|
|
|
status,
|
|
|
|
kind,
|
|
|
|
index_tasks,
|
2022-10-19 18:59:12 +08:00
|
|
|
enqueued_at,
|
|
|
|
started_at,
|
|
|
|
finished_at,
|
2022-10-10 18:57:17 +08:00
|
|
|
index_mapper,
|
|
|
|
wake_up: _,
|
2022-10-18 01:24:06 +08:00
|
|
|
dumps_path: _,
|
2022-10-25 16:53:25 +08:00
|
|
|
snapshots_path: _,
|
2022-10-10 18:57:17 +08:00
|
|
|
test_breakpoint_sdr: _,
|
2022-10-20 23:11:44 +08:00
|
|
|
planned_failures: _,
|
|
|
|
run_loop_iteration: _,
|
2022-10-10 18:57:17 +08:00
|
|
|
} = scheduler;
|
|
|
|
|
|
|
|
let rtxn = env.read_txn().unwrap();
|
|
|
|
|
|
|
|
let mut snap = String::new();
|
|
|
|
|
2022-10-17 23:19:17 +08:00
|
|
|
let processing_tasks = processing_tasks.read().unwrap().processing.clone();
|
2022-10-21 00:00:07 +08:00
|
|
|
snap.push_str(&format!("### Autobatching Enabled = {autobatching_enabled}\n"));
|
2022-10-10 18:57:17 +08: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-10-19 18:59:12 +08: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 21:04:14 +08:00
|
|
|
snap.push_str("### File Store:\n");
|
|
|
|
snap.push_str(&snapshot_file_store(file_store));
|
|
|
|
snap.push_str("\n----------------------------------------------------------------------\n");
|
|
|
|
|
2022-10-10 18:57:17 +08:00
|
|
|
snap
|
|
|
|
}
|
|
|
|
|
2022-10-20 23:11:44 +08:00
|
|
|
pub fn snapshot_file_store(file_store: &file_store::FileStore) -> String {
|
2022-10-18 21:04:14 +08:00
|
|
|
let mut snap = String::new();
|
|
|
|
for uuid in file_store.__all_uuids() {
|
|
|
|
snap.push_str(&format!("{uuid}\n"));
|
|
|
|
}
|
|
|
|
snap
|
|
|
|
}
|
|
|
|
|
2022-10-20 23:11:44 +08:00
|
|
|
pub fn snapshot_bitmap(r: &RoaringBitmap) -> String {
|
2022-10-10 18:57:17 +08:00
|
|
|
let mut snap = String::new();
|
|
|
|
snap.push('[');
|
|
|
|
for x in r {
|
|
|
|
snap.push_str(&format!("{x},"));
|
|
|
|
}
|
|
|
|
snap.push(']');
|
|
|
|
snap
|
|
|
|
}
|
|
|
|
|
2022-10-20 23:11:44 +08:00
|
|
|
pub fn snapshot_all_tasks(rtxn: &RoTxn, db: Database<OwnedType<BEU32>, SerdeJson<Task>>) -> String {
|
2022-10-10 18:57:17 +08:00
|
|
|
let mut snap = String::new();
|
2022-10-22 22:35:42 +08:00
|
|
|
let iter = db.iter(rtxn).unwrap();
|
|
|
|
for next in iter {
|
2022-10-10 18:57:17 +08:00
|
|
|
let (task_id, task) = next.unwrap();
|
|
|
|
snap.push_str(&format!("{task_id} {}\n", snapshot_task(&task)));
|
|
|
|
}
|
|
|
|
snap
|
|
|
|
}
|
|
|
|
|
2022-10-20 23:11:44 +08:00
|
|
|
pub fn snapshot_date_db(
|
2022-10-19 18:59:12 +08:00
|
|
|
rtxn: &RoTxn,
|
|
|
|
db: Database<OwnedType<BEI128>, CboRoaringBitmapCodec>,
|
|
|
|
) -> String {
|
|
|
|
let mut snap = String::new();
|
2022-10-22 22:35:42 +08:00
|
|
|
let iter = db.iter(rtxn).unwrap();
|
|
|
|
for next in iter {
|
2022-10-19 18:59:12 +08:00
|
|
|
let (_timestamp, task_ids) = next.unwrap();
|
|
|
|
snap.push_str(&format!("[timestamp] {}\n", snapshot_bitmap(&task_ids)));
|
|
|
|
}
|
|
|
|
snap
|
|
|
|
}
|
|
|
|
|
2022-10-20 23:11:44 +08:00
|
|
|
pub fn snapshot_task(task: &Task) -> String {
|
2022-10-10 18:57:17 +08:00
|
|
|
let mut snap = String::new();
|
|
|
|
let Task {
|
|
|
|
uid,
|
|
|
|
enqueued_at: _,
|
|
|
|
started_at: _,
|
|
|
|
finished_at: _,
|
|
|
|
error,
|
2022-10-25 17:42:14 +08:00
|
|
|
canceled_by,
|
2022-10-10 18:57:17 +08:00
|
|
|
details,
|
|
|
|
status,
|
|
|
|
kind,
|
|
|
|
} = task;
|
|
|
|
snap.push('{');
|
|
|
|
snap.push_str(&format!("uid: {uid}, "));
|
|
|
|
snap.push_str(&format!("status: {status}, "));
|
2022-10-25 17:42:14 +08:00
|
|
|
if let Some(canceled_by) = canceled_by {
|
|
|
|
snap.push_str(&format!("canceled_by: {canceled_by}, "));
|
|
|
|
}
|
2022-10-10 18:57:17 +08:00
|
|
|
if let Some(error) = error {
|
|
|
|
snap.push_str(&format!("error: {error:?}, "));
|
|
|
|
}
|
|
|
|
if let Some(details) = details {
|
2022-10-25 16:18:18 +08:00
|
|
|
snap.push_str(&format!("details: {}, ", &snapshot_details(details)));
|
2022-10-10 18:57:17 +08:00
|
|
|
}
|
|
|
|
snap.push_str(&format!("kind: {kind:?}"));
|
|
|
|
|
|
|
|
snap.push('}');
|
|
|
|
snap
|
|
|
|
}
|
2022-10-21 00:00:07 +08:00
|
|
|
|
2022-10-25 16:18:18 +08:00
|
|
|
fn snapshot_details(d: &Details) -> String {
|
2022-10-10 18:57:17 +08:00
|
|
|
match d {
|
2022-10-22 00:03:10 +08:00
|
|
|
Details::DocumentAdditionOrUpdate {
|
2022-10-10 18:57:17 +08:00
|
|
|
received_documents,
|
|
|
|
indexed_documents,
|
|
|
|
} => {
|
2022-10-18 01:24:06 +08:00
|
|
|
format!("{{ received_documents: {received_documents}, indexed_documents: {indexed_documents:?} }}")
|
2022-10-10 18:57:17 +08:00
|
|
|
}
|
2022-10-22 00:03:10 +08:00
|
|
|
Details::SettingsUpdate { settings } => {
|
2022-10-10 18:57:17 +08:00
|
|
|
format!("{{ settings: {settings:?} }}")
|
|
|
|
}
|
|
|
|
Details::IndexInfo { primary_key } => {
|
|
|
|
format!("{{ primary_key: {primary_key:?} }}")
|
|
|
|
}
|
|
|
|
Details::DocumentDeletion {
|
2022-10-25 17:02:26 +08:00
|
|
|
matched_documents: received_document_ids,
|
2022-10-10 18:57:17 +08:00
|
|
|
deleted_documents,
|
|
|
|
} => format!("{{ received_document_ids: {received_document_ids}, deleted_documents: {deleted_documents:?} }}"),
|
|
|
|
Details::ClearAll { deleted_documents } => {
|
|
|
|
format!("{{ deleted_documents: {deleted_documents:?} }}")
|
|
|
|
},
|
2022-10-17 23:19:17 +08:00
|
|
|
Details::TaskCancelation {
|
|
|
|
matched_tasks,
|
|
|
|
canceled_tasks,
|
|
|
|
original_query,
|
|
|
|
} => {
|
|
|
|
format!("{{ matched_tasks: {matched_tasks:?}, canceled_tasks: {canceled_tasks:?}, original_query: {original_query:?} }}")
|
|
|
|
}
|
2022-10-13 17:09:00 +08:00
|
|
|
Details::TaskDeletion {
|
2022-10-10 18:57:17 +08:00
|
|
|
matched_tasks,
|
|
|
|
deleted_tasks,
|
|
|
|
original_query,
|
|
|
|
} => {
|
|
|
|
format!("{{ matched_tasks: {matched_tasks:?}, deleted_tasks: {deleted_tasks:?}, original_query: {original_query:?} }}")
|
|
|
|
},
|
|
|
|
Details::Dump { dump_uid } => {
|
|
|
|
format!("{{ dump_uid: {dump_uid:?} }}")
|
|
|
|
},
|
2022-10-17 22:30:18 +08:00
|
|
|
Details::IndexSwap { swaps } => {
|
|
|
|
format!("{{ indexes: {swaps:?} }}")
|
2022-10-21 00:00:07 +08:00
|
|
|
}
|
2022-10-10 18:57:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-20 23:11:44 +08:00
|
|
|
pub fn snapshot_status(
|
|
|
|
rtxn: &RoTxn,
|
|
|
|
db: Database<SerdeBincode<Status>, RoaringBitmapCodec>,
|
|
|
|
) -> String {
|
2022-10-10 18:57:17 +08:00
|
|
|
let mut snap = String::new();
|
2022-10-22 22:35:42 +08:00
|
|
|
let iter = db.iter(rtxn).unwrap();
|
|
|
|
for next in iter {
|
2022-10-10 18:57:17 +08:00
|
|
|
let (status, task_ids) = next.unwrap();
|
2022-10-22 23:17:09 +08:00
|
|
|
writeln!(snap, "{status} {}", snapshot_bitmap(&task_ids)).unwrap();
|
2022-10-10 18:57:17 +08:00
|
|
|
}
|
|
|
|
snap
|
|
|
|
}
|
2022-10-20 23:11:44 +08:00
|
|
|
pub fn snapshot_kind(rtxn: &RoTxn, db: Database<SerdeBincode<Kind>, RoaringBitmapCodec>) -> String {
|
2022-10-10 18:57:17 +08:00
|
|
|
let mut snap = String::new();
|
2022-10-22 22:35:42 +08:00
|
|
|
let iter = db.iter(rtxn).unwrap();
|
|
|
|
for next in iter {
|
2022-10-10 18:57:17 +08:00
|
|
|
let (kind, task_ids) = next.unwrap();
|
|
|
|
let kind = serde_json::to_string(&kind).unwrap();
|
2022-10-22 23:17:09 +08:00
|
|
|
writeln!(snap, "{kind} {}", snapshot_bitmap(&task_ids)).unwrap();
|
2022-10-10 18:57:17 +08:00
|
|
|
}
|
|
|
|
snap
|
|
|
|
}
|
|
|
|
|
2022-10-20 23:11:44 +08:00
|
|
|
pub fn snapshot_index_tasks(rtxn: &RoTxn, db: Database<Str, RoaringBitmapCodec>) -> String {
|
2022-10-10 18:57:17 +08:00
|
|
|
let mut snap = String::new();
|
2022-10-22 22:35:42 +08:00
|
|
|
let iter = db.iter(rtxn).unwrap();
|
|
|
|
for next in iter {
|
2022-10-10 18:57:17 +08:00
|
|
|
let (index, task_ids) = next.unwrap();
|
2022-10-22 23:17:09 +08:00
|
|
|
writeln!(snap, "{index} {}", snapshot_bitmap(&task_ids)).unwrap();
|
2022-10-10 18:57:17 +08:00
|
|
|
}
|
|
|
|
snap
|
|
|
|
}
|
|
|
|
|
2022-10-20 23:11:44 +08:00
|
|
|
pub fn snapshot_index_mapper(rtxn: &RoTxn, mapper: &IndexMapper) -> String {
|
2022-10-25 16:59:06 +08:00
|
|
|
let names = mapper.indexes(rtxn).unwrap().into_iter().map(|(n, _)| n).collect::<Vec<_>>();
|
2022-10-10 18:57:17 +08:00
|
|
|
format!("{names:?}")
|
|
|
|
}
|