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

View File

@@ -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),
})
}

View File

@@ -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);

View File

@@ -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,

View File

@@ -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 {

View File

@@ -191,6 +191,24 @@ fn admin_pool_sort_keys_for_request(keys: &mut [StoredProviderCatalogKey], sort:
}
}
fn admin_pool_repository_key_order(sort: AdminPoolKeySort) -> ProviderCatalogKeyListOrder {
match (sort.field, sort.direction) {
(AdminPoolKeySortField::Default, _) => ProviderCatalogKeyListOrder::Name,
(AdminPoolKeySortField::ImportedAt, AdminPoolKeySortDirection::Asc) => {
ProviderCatalogKeyListOrder::CreatedAtAsc
}
(AdminPoolKeySortField::ImportedAt, AdminPoolKeySortDirection::Desc) => {
ProviderCatalogKeyListOrder::CreatedAtDesc
}
(AdminPoolKeySortField::LastUsedAt, AdminPoolKeySortDirection::Asc) => {
ProviderCatalogKeyListOrder::LastUsedAtAsc
}
(AdminPoolKeySortField::LastUsedAt, AdminPoolKeySortDirection::Desc) => {
ProviderCatalogKeyListOrder::LastUsedAtDesc
}
}
}
pub(super) async fn build_admin_pool_list_keys_response(
state: &AdminAppState<'_>,
request_context: &AdminRequestContext<'_>,
@@ -305,7 +323,7 @@ pub(super) async fn build_admin_pool_list_keys_response(
.take(page_size)
.collect::<Vec<_>>();
(keys, total)
} else if !quick_selectors.is_empty() || sort.field != AdminPoolKeySortField::Default {
} else if !quick_selectors.is_empty() {
let mut keys = state
.list_provider_catalog_keys_by_provider_ids(std::slice::from_ref(&provider.id))
.await?
@@ -354,7 +372,7 @@ pub(super) async fn build_admin_pool_list_keys_response(
},
offset: page_offset,
limit: page_size,
order: ProviderCatalogKeyListOrder::Name,
order: admin_pool_repository_key_order(sort),
})
.await?;
(key_page.items, key_page.total)