feat: show ecc2 chronic saturation mode

This commit is contained in:
Affaan Mustafa
2026-04-08 03:20:47 -07:00
parent f498dc0971
commit a6f798e505
3 changed files with 88 additions and 44 deletions

View File

@@ -157,7 +157,7 @@ where
RFut: Future<Output = Result<usize>>,
Rec: FnMut(usize, usize) -> Result<()>,
{
if should_rebalance_first(prior_activity) {
if prior_activity.prefers_rebalance_first() {
let rebalanced = rebalance().await?;
let first_dispatch = dispatch().await?;
return Ok((first_dispatch, rebalanced, DispatchPassSummary::default()));
@@ -182,21 +182,6 @@ where
Ok((first_dispatch, rebalanced, recovery_dispatch))
}
fn should_rebalance_first(activity: &super::store::DaemonActivity) -> bool {
if activity.last_dispatch_deferred == 0 {
return false;
}
match (
activity.last_dispatch_at.as_ref(),
activity.last_recovery_dispatch_at.as_ref(),
) {
(Some(dispatch_at), Some(recovery_at)) => recovery_at < dispatch_at,
(Some(_), None) => true,
_ => false,
}
}
async fn maybe_auto_dispatch_with<F, Fut>(cfg: &Config, dispatch: F) -> Result<usize>
where
F: Fn() -> Fut,
@@ -648,34 +633,6 @@ mod tests {
Ok(())
}
#[test]
fn should_rebalance_first_only_after_unrecovered_deferred_pressure() {
let now = chrono::Utc::now();
assert!(!should_rebalance_first(&DaemonActivity::default()));
let unresolved = DaemonActivity {
last_dispatch_at: Some(now),
last_dispatch_routed: 0,
last_dispatch_deferred: 2,
last_dispatch_leads: 1,
last_recovery_dispatch_at: None,
last_recovery_dispatch_routed: 0,
last_recovery_dispatch_leads: 0,
last_rebalance_at: None,
last_rebalance_rerouted: 0,
last_rebalance_leads: 0,
};
assert!(should_rebalance_first(&unresolved));
let recovered = DaemonActivity {
last_recovery_dispatch_at: Some(now + chrono::Duration::seconds(1)),
last_recovery_dispatch_routed: 1,
..unresolved.clone()
};
assert!(!should_rebalance_first(&recovered));
}
#[tokio::test]
async fn coordinate_backlog_cycle_rebalances_first_after_unrecovered_deferred_pressure() -> Result<()> {
let cfg = Config {

View File

@@ -27,6 +27,23 @@ pub struct DaemonActivity {
pub last_rebalance_leads: usize,
}
impl DaemonActivity {
pub fn prefers_rebalance_first(&self) -> bool {
if self.last_dispatch_deferred == 0 {
return false;
}
match (
self.last_dispatch_at.as_ref(),
self.last_recovery_dispatch_at.as_ref(),
) {
(Some(dispatch_at), Some(recovery_at)) => recovery_at < dispatch_at,
(Some(_), None) => true,
_ => false,
}
}
}
impl StateStore {
pub fn open(path: &Path) -> Result<Self> {
let conn = Connection::open(path)?;
@@ -1039,4 +1056,33 @@ mod tests {
Ok(())
}
#[test]
fn daemon_activity_detects_rebalance_first_mode() {
let now = chrono::Utc::now();
let clear = DaemonActivity::default();
assert!(!clear.prefers_rebalance_first());
let unresolved = DaemonActivity {
last_dispatch_at: Some(now),
last_dispatch_routed: 0,
last_dispatch_deferred: 2,
last_dispatch_leads: 1,
last_recovery_dispatch_at: None,
last_recovery_dispatch_routed: 0,
last_recovery_dispatch_leads: 0,
last_rebalance_at: None,
last_rebalance_rerouted: 0,
last_rebalance_leads: 0,
};
assert!(unresolved.prefers_rebalance_first());
let recovered = DaemonActivity {
last_recovery_dispatch_at: Some(now + chrono::Duration::seconds(1)),
last_recovery_dispatch_routed: 1,
..unresolved
};
assert!(!recovered.prefers_rebalance_first());
}
}