AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
docs(engine): say what a part-way failed data-stream DELETE actually does
xerj-org6b04dfbca315
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 49c0f281d..1964a96f4 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -496,17 +496,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0the removal is recorded only once every backing index is gone, and abacking index that cannot be deleted now aborts the DELETE with a 500(it was previously swallowed and answered `acknowledged`) so the operator- can retry.+ can retry. Read that 500 as "did not finish", not as "nothing happened":+ a multi-generation stream still loses every backing index that *could* be+ destroyed, the stream itself stays addressable, and the retry after the+ cause is fixed completes the delete.**Known gaps, deliberately not closed here.** `.ds-*` indices that no datastream claims — left by a data dir written before this change, or by aDELETE interrupted by an older build — are **not** cleaned up or adoptedautomatically; boot now names them in a warning and the recovery is`DELETE /<backing-index>` per index, because an orphan may hold the only copy- of real data. And `aliases.json` still has the read-error shape that was+ of real data. And `aliases.json` still has both swallow shapes that werefixed here for `cluster_state.json`: an unreadable aliases file is swallowed- at boot and overwritten by the next alias write. That is pre-existing- behaviour, not introduced here, and is tracked separately.+ at boot and overwritten by the next alias write, and a *failed* alias write+ is only logged, so an alias can survive on disk after the stream it named was+ deleted with a 200. Both are pre-existing behaviour, not introduced here or+ made worse here, and are tracked separately.- **`autoindex` no longer leaves immortal catalog entries for skipped files**([#238](https://github.com/xerj-org/xerj/issues/238)). A file added after thediff --git a/engine/crates/xerj-api/tests/cluster_metadata_survives_restart.rs b/engine/crates/xerj-api/tests/cluster_metadata_survives_restart.rsindex b95d28899..8172a9dbb 100644--- a/engine/crates/xerj-api/tests/cluster_metadata_survives_restart.rs+++ b/engine/crates/xerj-api/tests/cluster_metadata_survives_restart.rs@@ -738,3 +738,83 @@ async fn a_backing_index_that_cannot_be_deleted_aborts_the_delete() {"the retry did not record the removal: {state}");}++/// A DELETE that fails part-way still destroys every backing index it can —+/// and the release note says so, so pin it.+///+/// The loop deliberately does not stop at the first error: the caller asked+/// for the whole stream to go, so a generation that *can* be destroyed is+/// destroyed and only the ones that could not are left. The 500 therefore+/// means "did not finish", never "nothing happened", and this test exists so+/// that sentence cannot quietly stop being true — a `break` added to that+/// loop would leave `-000002` and `-000003` on disk and fail here.+///+/// Unix-only, and skipped when the process can write through a `chmod 555`+/// (i.e. running as root), where the failure cannot be injected this way.+#[cfg(unix)]+#[tokio::test(flavor = "multi_thread", worker_threads = 2)]+async fn a_partly_failed_delete_still_removes_what_it_could() {+ use std::os::unix::fs::PermissionsExt;++ let dir = tempfile::tempdir().expect("tempdir");+ let app = app_over(dir.path());+ let (st, body) = put_json(&app, "/_data_stream/audit", json!({})).await;+ assert_eq!(st, StatusCode::OK, "PUT _data_stream: {body}");+ for _ in 0..2 {+ let (st, body) = post(&app, "/audit/_rollover", json!({})).await;+ assert_eq!(st, StatusCode::OK, "rollover: {body}");+ }++ let first = dir.path().join(".ds-audit-000001");+ let second = dir.path().join(".ds-audit-000002");+ let third = dir.path().join(".ds-audit-000003");+ for p in [&first, &second, &third] {+ assert!(p.is_dir(), "fixture is wrong: {} missing", p.display());+ }++ // Only the FIRST generation is un-unlinkable. It is also the first one+ // the loop reaches, so a loop that stopped on error would leave the other+ // two behind.+ std::fs::set_permissions(&first, std::fs::Permissions::from_mode(0o555)).expect("chmod 555");+ if std::fs::File::create(first.join("root-probe")).is_ok() {+ let _ = std::fs::remove_file(first.join("root-probe"));+ std::fs::set_permissions(&first, std::fs::Permissions::from_mode(0o755)).expect("chmod");+ eprintln!("skipped: permissions do not deny this process (running as root?)");+ return;+ }++ let (st, body) = delete(&app, "/_data_stream/audit").await;+ std::fs::set_permissions(&first, std::fs::Permissions::from_mode(0o755)).expect("chmod 755");+ assert_eq!(+ st,+ StatusCode::INTERNAL_SERVER_ERROR,+ "a delete that could not destroy every backing index must report it: {body}"+ );++ assert!(+ first.exists(),+ "the generation that could not be deleted must still be there"+ );+ assert!(+ !second.exists() && !third.exists(),+ "the delete stopped at the first failure — the generations it could \+ have destroyed are still on disk, which contradicts the release note"+ );++ // The stream is still addressable and still recorded, so the retry has+ // something to finish.+ let (st, body) = get(&app, "/_data_stream/audit").await;+ assert_eq!(st, StatusCode::OK, "stream must stay addressable: {body}");+ let state: Value = serde_json::from_slice(+ &std::fs::read(dir.path().join("cluster_state.json")).expect("read"),+ )+ .expect("parse");+ assert!(+ !state["data_streams"]["audit"].is_null(),+ "the removal must not have been recorded while a backing index remains: {state}"+ );++ let (st, body) = delete(&app, "/_data_stream/audit").await;+ assert_eq!(st, StatusCode::OK, "retry after the cause is fixed: {body}");+ assert!(!first.exists(), "the retry left the backing index on disk");+}diff --git a/engine/crates/xerj-engine/src/engine.rs b/engine/crates/xerj-engine/src/engine.rsindex 34f14da08..a111b5857 100644--- a/engine/crates/xerj-engine/src/engine.rs+++ b/engine/crates/xerj-engine/src/engine.rs@@ -2944,12 +2944,19 @@ impl Engine {// fixes for an interrupted rollover, so it is not the ordering to// ship.//- // A backing index that cannot be destroyed therefore aborts the- // delete: the stream is put back and the caller gets the error, so- // the operator can retry rather than be told `acknowledged` about- // data that is still on disk. A retry is safe — an already-deleted- // backing index is simply absent from `self.indices` on the next- // pass.+ // A backing index that cannot be destroyed therefore fails the+ // delete: the stream is put back, the removal is never recorded, and+ // the caller gets the error rather than being told `acknowledged`+ // about data that is still on disk.+ //+ // Note what "fails" does *not* mean. The loop does not stop at the+ // first error — every backing index that can be destroyed is+ // destroyed, and only the ones that could not are still there. The+ // 500 says the delete did not finish, not that nothing happened; the+ // caller asked for the whole stream to go, so making the progress we+ // can is the useful half. A retry is safe and completes the job — an+ // already-deleted backing index is simply absent from `self.indices`+ // on the next pass.let mut delete_err: Option<EngineError> = None;for backing in &ds.backing_indices {let Some((_, idx)) = self.indices.remove(backing) else {