Track scheduler affinity epochs and key sorting

This commit is contained in:
fawney19
2026-05-11 01:45:49 +08:00
parent 7b81c77424
commit e3574e1918
38 changed files with 656 additions and 23 deletions
@@ -262,6 +262,14 @@ fn admin_monitoring_json_request_count(
})
}
fn admin_monitoring_json_scheduler_affinity_epoch(
object: &serde_json::Map<String, serde_json::Value>,
) -> Option<u64> {
object
.get("scheduler_affinity_epoch")
.and_then(serde_json::Value::as_u64)
}
pub(super) fn admin_monitoring_cache_affinity_record(
raw_key: &str,
raw_value: &str,
@@ -300,12 +308,14 @@ pub(super) fn admin_monitoring_cache_affinity_record(
expire_at: object.get("expire_at").cloned(),
request_count: request_count.unwrap_or(0),
request_count_known: request_count.is_some(),
scheduler_affinity_epoch: None,
})
}
pub(super) fn admin_monitoring_scheduler_affinity_record(
cache_key: &str,
target: &SchedulerAffinityTarget,
epoch: u64,
age: Duration,
ttl: Duration,
now_unix_secs: u64,
@@ -329,6 +339,7 @@ pub(super) fn admin_monitoring_scheduler_affinity_record(
expire_at: Some(serde_json::json!(expire_at)),
request_count: 0,
request_count_known: false,
scheduler_affinity_epoch: Some(epoch),
})
}
@@ -371,6 +382,7 @@ pub(super) fn admin_monitoring_scheduler_affinity_record_from_raw(
expire_at: object.get("expire_at").cloned(),
request_count: request_count.unwrap_or(0),
request_count_known: request_count.is_some(),
scheduler_affinity_epoch: admin_monitoring_json_scheduler_affinity_epoch(object),
})
}
@@ -16,6 +16,7 @@ pub(in super::super) async fn build_admin_monitoring_cache_flush_response(
.iter()
.map(|item| item.raw_key.clone())
.collect::<Vec<_>>();
state.as_ref().invalidate_scheduler_affinity_cache();
let deleted = delete_admin_monitoring_cache_affinity_raw_keys(state, &raw_keys).await?;
clear_admin_monitoring_scheduler_affinity_entries(state, &raw_affinities);
@@ -157,6 +157,7 @@ async fn list_admin_monitoring_cache_affinity_records_matching(
records.push(record);
}
};
let current_scheduler_affinity_epoch = state.as_ref().scheduler_affinity_epoch();
{
let patterns = affinity_keys
@@ -210,6 +211,13 @@ async fn list_admin_monitoring_cache_affinity_records_matching(
let Some(record) = record else {
continue;
};
if key.contains("scheduler_affinity:")
&& record
.scheduler_affinity_epoch
.is_some_and(|epoch| epoch != current_scheduler_affinity_epoch)
{
continue;
}
if affinity_keys.is_some_and(|keys| !keys.contains(&record.affinity_key)) {
continue;
}
@@ -237,6 +245,7 @@ async fn list_admin_monitoring_cache_affinity_records_matching(
let Some(record) = admin_monitoring_scheduler_affinity_record(
&entry.cache_key,
&entry.target,
entry.epoch,
entry.age,
SCHEDULER_AFFINITY_TTL,
now_unix_secs,
@@ -13,6 +13,7 @@ pub(super) struct AdminMonitoringCacheAffinityRecord {
pub(super) expire_at: Option<serde_json::Value>,
pub(super) request_count: u64,
pub(super) request_count_known: bool,
pub(super) scheduler_affinity_epoch: Option<u64>,
}
pub(super) struct AdminMonitoringCacheSnapshot {