Skip to content

armgit / xerj

Public Imported from GitHub
0

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.

feat(api): keep closed indices visible in _cat/indices with status close (#463)

xerj-org2426f9e51d0a
diff --git a/engine/crates/xerj-api/src/es_compat.rs b/engine/crates/xerj-api/src/es_compat.rs
index 8d2ed5032..4c365067c 100644
--- a/engine/crates/xerj-api/src/es_compat.rs
+++ b/engine/crates/xerj-api/src/es_compat.rs
@@ -668,6 +668,18 @@ async fn cat_indices_inner(
// operator can delete or retry, and omitting them is what made a failed
// index invisible to every dashboard (issue #206).
let failed = state.engine.list_failed_indices();
+ // #463: a `_close` that reclaimed RAM released the index's in-memory handle,
+ // so it is absent from `list_indices` (loaded-only). List those indices with
+ // status `close` rather than omitting them — an operator who closed an index
+ // must still see it (the same visibility guarantee #206 restored for failed
+ // indices). No doc count is shown: we do not load the index just to count.
+ let closed_all: Vec<String> = state
+ .engine
+ .closed_indices
+ .iter()
+ .map(|e| e.key().clone())
+ .filter(|n| !indices.iter().any(|i| &i.name == n) && !failed.iter().any(|f| &f.name == n))
+ .collect();
// Narrow to the path pattern when present (`/_cat/indices/{pattern}`):
// a comma-separated list of concrete names and/or `*` globs. ES rules:
@@ -687,6 +699,7 @@ async fn cat_indices_inner(
if !is_wildcard
&& !indices.iter().any(|i| i.name == p)
&& !failed.iter().any(|f| f.name == p)
+ && !closed_all.iter().any(|n| n == p)
{
return ApiError::new(xerj_common::XerjError::index_not_found(p))
.into_response();
@@ -752,6 +765,21 @@ async fn cat_indices_inner(
.map(|f| (f.name.clone(), stable_index_uuid(&f.name)))
.collect();
+ // #463: closed indices selected by the same pattern rules as above.
+ let selected_closed: Vec<String> = match pattern.as_deref() {
+ None => closed_all.clone(),
+ Some(pat) => closed_all
+ .iter()
+ .filter(|n| {
+ pat.split(',')
+ .map(str::trim)
+ .filter(|s| !s.is_empty())
+ .any(|p| p == "_all" || p == "*" || n.as_str() == p || glob_match_simple(p, n))
+ })
+ .cloned()
+ .collect(),
+ };
+
if params.format.as_deref() == Some("json") {
let mut arr: Vec<Value> = rows
.iter()
@@ -784,6 +812,20 @@ async fn cat_indices_inner(
"pri.store.size": "0b",
})
}));
+ arr.extend(selected_closed.iter().map(|name| {
+ json!({
+ "health": "",
+ "status": "close",
+ "index": name,
+ "uuid": stable_index_uuid(name),
+ "pri": "1",
+ "rep": "0",
+ "docs.count": "0",
+ "docs.deleted": "0",
+ "store.size": "0b",
+ "pri.store.size": "0b",
+ })
+ }));
return Json(arr).into_response();
}
@@ -796,6 +838,13 @@ async fn cat_indices_inner(
for (name, uuid) in &failed_rows {
lines.push(format!("red open {name} {uuid} 1 0 0 0 0b 0b 0b"));
}
+ for name in &selected_closed {
+ // Empty health column (rendered `-`), status `close` (#463).
+ lines.push(format!(
+ "- close {name} {} 1 0 0 0 0b 0b 0b",
+ stable_index_uuid(name)
+ ));
+ }
// ES returns an empty body (not a bare newline) when nothing matches.
let body = if lines.is_empty() {
String::new()
diff --git a/engine/crates/xerj-api/tests/close_frees_memory.rs b/engine/crates/xerj-api/tests/close_frees_memory.rs
index 1a6c092f5..a11d229a6 100644
--- a/engine/crates/xerj-api/tests/close_frees_memory.rs
+++ b/engine/crates/xerj-api/tests/close_frees_memory.rs
@@ -131,3 +131,48 @@ async fn probe_close_hydration_and_reopen_roundtrip() {
eprintln!("PROBE post-open total hits = {total:?}");
assert_eq!(total, Some(200), "reopen must be lossless: {q}");
}
+
+/// #463 (+#206 visibility guarantee): a closed index whose in-memory handle was
+/// released must still appear in `_cat/indices` with status `close` — omitting
+/// it is the exact invisibility regression #206 fixed for failed indices. This
+/// is the fail-before for the release change (before the cat_indices fix the row
+/// vanishes because the released index is absent from the loaded-only listing).
+#[tokio::test]
+async fn closed_index_stays_visible_in_cat_indices() {
+ let (app, _dir) = app().await;
+
+ let (st, before) = call(&app, "GET", "/_cat/indices?format=json", Value::Null).await;
+ assert_eq!(st, StatusCode::OK);
+ assert!(
+ before
+ .as_array()
+ .is_some_and(|a| a.iter().any(|r| r["index"] == "docs")),
+ "docs should be listed before close: {before}"
+ );
+
+ let (st, _) = call(&app, "POST", "/docs/_close", Value::Null).await;
+ assert_eq!(st, StatusCode::OK);
+
+ let (st, after) = call(&app, "GET", "/_cat/indices?format=json", Value::Null).await;
+ assert_eq!(st, StatusCode::OK);
+ let row = after
+ .as_array()
+ .and_then(|a| a.iter().find(|r| r["index"] == "docs"));
+ assert!(
+ row.is_some(),
+ "#463/#206: a closed index must stay visible in _cat/indices, not vanish: {after}"
+ );
+ assert_eq!(
+ row.unwrap()["status"],
+ "close",
+ "#463: the closed index must report status close: {after}"
+ );
+
+ // And a concrete-name lookup of the closed index must not 404.
+ let (st, _) = call(&app, "GET", "/_cat/indices/docs?format=json", Value::Null).await;
+ assert_eq!(
+ st,
+ StatusCode::OK,
+ "a concrete _cat lookup of a closed index must not 404"
+ );
+}