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.

refactor(wal-tap): do not hold a DashMap guard while taking WAL mutexes (#320)

xerj-org725171ea5e7d
diff --git a/engine/crates/xerj-engine/src/engine.rs b/engine/crates/xerj-engine/src/engine.rs
index 524acaef7..395a1dd06 100644
--- a/engine/crates/xerj-engine/src/engine.rs
+++ b/engine/crates/xerj-engine/src/engine.rs
@@ -2886,11 +2886,18 @@ impl Engine {
/// that already exist rather than waiting for the next one.
pub fn apply_wal_retention_floor(&self) -> usize {
let floor = self.wal_retention_floor();
- let mut applied = 0usize;
- for entry in self.indices.iter() {
- entry.value().set_wal_min_retained_generations(floor);
- applied += 1;
+ // Snapshot the handles first, then take the WAL mutexes — never both
+ // at once. `DashMap::iter` holds a read guard on each map shard for as
+ // long as the iterator lives, and `set_wal_min_retained_generations`
+ // locks every `WalWriter` of the index; holding the first while
+ // acquiring the second would put a lock-order edge between two
+ // subsystems that otherwise have none, for the sake of one avoided
+ // allocation on an operator-triggered path.
+ let indices: Vec<Arc<Index>> = self.indices.iter().map(|e| e.value().clone()).collect();
+ for index in &indices {
+ index.set_wal_min_retained_generations(floor);
}
+ let applied = indices.len();
tracing::debug!(
floor,
indices = applied,