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.

fix(engine): honour cluster.routing.allocation.disk.threshold_enabled=false (#1596)

Jay Hemnani362671649868
diff --git a/engine/crates/xerj-engine/src/engine.rs b/engine/crates/xerj-engine/src/engine.rs
index ddf89c192..79985d2e7 100644
--- a/engine/crates/xerj-engine/src/engine.rs
+++ b/engine/crates/xerj-engine/src/engine.rs
@@ -3987,6 +3987,7 @@ impl Engine {
let cluster_settings = self.cluster_settings.clone();
const FLOOD_STAGE_SETTING: &str = "cluster.routing.allocation.disk.watermark.flood_stage";
const BREAKER_LIMIT_SETTING: &str = "indices.breaker.total.limit";
+ const DISK_THRESHOLD_SETTING: &str = "cluster.routing.allocation.disk.threshold_enabled";
// Snapshot the uncapped machine memory once: a percentage override is
// resolved against it, and it is the hard clamp for an absolute one.
let machine_memory_bytes = crate::governor::effective_memory_limit_bytes();
@@ -4054,6 +4055,19 @@ impl Engine {
.and_then(crate::governor::parse_flood_stage_pct);
governor.set_disk_flood_pct_override(flood_override);
+ // `threshold_enabled: false` turns the flood stage
+ // off and releases an engaged block, as in ES.
+ let threshold_enabled = settings
+ .get("persistent")
+ .and_then(|p| p.get(DISK_THRESHOLD_SETTING))
+ .or_else(|| {
+ settings
+ .get("transient")
+ .and_then(|t| t.get(DISK_THRESHOLD_SETTING))
+ })
+ .and_then(crate::governor::parse_setting_bool);
+ governor.set_disk_threshold_enabled(threshold_enabled);
+
// Runtime parent-memory-breaker watermark override
// (#1250): raise the watermark on a big box live via
// `PUT _cluster/settings {indices.breaker.total.limit}`,
diff --git a/engine/crates/xerj-engine/src/governor.rs b/engine/crates/xerj-engine/src/governor.rs
index 0ac401dc7..3625b6f7b 100644
--- a/engine/crates/xerj-engine/src/governor.rs
+++ b/engine/crates/xerj-engine/src/governor.rs
@@ -128,6 +128,10 @@ pub struct ResourceGovernor {
/// lets an operator clear/relax the block without a restart, matching
/// ES's `PUT _cluster/settings` recovery flow.
disk_flood_pct: AtomicU8,
+ /// `false` while the `cluster.routing.allocation.disk.threshold_enabled`
+ /// cluster setting is `false`: the flood stage never engages, and an
+ /// engaged block is released on the next sample, as in ES.
+ disk_threshold_enabled: AtomicBool,
/// Latched: the data-dir filesystem is at/over the flood-stage watermark.
disk_blocked: AtomicBool,
/// Last sampled used-percentage of the data-dir filesystem.
@@ -249,6 +253,13 @@ impl ResourceGovernor {
self.disk_flood_pct.store(effective, Ordering::Relaxed);
}
+ /// Applies the `cluster.routing.allocation.disk.threshold_enabled` cluster
+ /// setting (`None` = unset = enabled).
+ pub fn set_disk_threshold_enabled(&self, enabled: Option<bool>) {
+ self.disk_threshold_enabled
+ .store(enabled.unwrap_or(true), Ordering::Relaxed);
+ }
+
/// Applies (or clears) a runtime override of the parent RSS watermark, read
/// each sampler tick from the `indices.breaker.total.limit` persistent
/// cluster setting (parsed by [`parse_breaker_total_limit`]) — see
@@ -428,7 +439,10 @@ impl ResourceGovernor {
self.disk_used_pct.store(disk_used_pct, Ordering::Relaxed);
let cur = self.disk_blocked.load(Ordering::Relaxed);
let release_pct = (flood_pct as u64).saturating_sub(1);
- let next = if cur {
+ let enabled = self.disk_threshold_enabled.load(Ordering::Relaxed);
+ let next = if !enabled {
+ false
+ } else if cur {
disk_used_pct >= release_pct
} else {
disk_used_pct >= flood_pct as u64
@@ -441,6 +455,11 @@ impl ResourceGovernor {
free = %human_bytes(disk_avail_bytes),
"disk flood-stage watermark crossed — engaging read_only_allow_delete write block"
);
+ } else if !enabled {
+ tracing::info!(
+ used_pct = disk_used_pct,
+ "disk threshold disabled by cluster setting — releasing write block"
+ );
} else {
tracing::info!(
used_pct = disk_used_pct,
@@ -968,6 +987,7 @@ fn build(config: &Config) -> ResourceGovernor {
max_concurrent_bulks,
disk_flood_pct_default: limits.disk_flood_stage_percent.min(100),
disk_flood_pct: AtomicU8::new(limits.disk_flood_stage_percent.min(100)),
+ disk_threshold_enabled: AtomicBool::new(true),
disk_blocked: AtomicBool::new(false),
disk_used_pct: AtomicU64::new(0),
}
@@ -1214,6 +1234,16 @@ pub fn parse_flood_stage_pct(v: &Value) -> Option<u8> {
Some(pct.min(100) as u8)
}
+/// Parses a boolean cluster setting: a JSON bool or the string `"true"` /
+/// `"false"` (what `PUT _cluster/settings` stores for either form).
+pub fn parse_setting_bool(v: &Value) -> Option<bool> {
+ match v {
+ Value::Bool(b) => Some(*b),
+ Value::String(s) => s.trim().parse().ok(),
+ _ => None,
+ }
+}
+
/// Parses the parent memory-breaker watermark override from an
/// `indices.breaker.total.limit` cluster-settings value, resolving it to an
/// absolute byte count. Accepts the two ES-compatible forms:
@@ -1881,6 +1911,28 @@ mod tests {
assert!(g.check_disk_block("i").is_err());
}
+ #[test]
+ fn disk_threshold_disabled_releases_and_suppresses_block() {
+ let mut cfg = Config::default();
+ cfg.limits.disk_flood_stage_percent = 95;
+ let g = build(&cfg);
+ g.refresh(0, 0, 97);
+ assert!(g.check_disk_block("i").is_err());
+
+ // `threshold_enabled: false` releases an engaged block on the next
+ // sample and keeps it off however full the disk gets.
+ g.set_disk_threshold_enabled(Some(false));
+ g.refresh(0, 0, 97);
+ assert!(g.check_disk_block("i").is_ok());
+ g.refresh(0, 0, 100);
+ assert!(g.check_disk_block("i").is_ok());
+
+ // Unsetting it (`None`) turns the watermark back on.
+ g.set_disk_threshold_enabled(None);
+ g.refresh(0, 0, 97);
+ assert!(g.check_disk_block("i").is_err());
+ }
+
#[test]
fn disk_flood_pct_override_is_noop_when_disabled_at_startup() {
let mut cfg = Config::default();
@@ -1903,6 +1955,15 @@ mod tests {
assert_eq!(parse_flood_stage_pct(&Value::Null), None);
}
+ #[test]
+ fn parse_setting_bool_accepts_es_shapes() {
+ assert_eq!(parse_setting_bool(&Value::from(false)), Some(false));
+ assert_eq!(parse_setting_bool(&Value::from("false")), Some(false));
+ assert_eq!(parse_setting_bool(&Value::from("true")), Some(true));
+ assert_eq!(parse_setting_bool(&Value::from("no")), None);
+ assert_eq!(parse_setting_bool(&Value::Null), None);
+ }
+
/// The `indices.breaker.total.limit` override parser (#1250) must accept
/// both ES forms — a percentage of real machine memory, and an absolute
/// byte-size — and reject garbage so the override reverts to the boot