mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-06 17:37:47 +08:00
feat(routing): consolidate scheduling strategy configuration
This commit is contained in:
@@ -79,12 +79,7 @@ const SYSTEM_CONFIG_CACHE_TTL: Duration = Duration::from_secs(30);
|
||||
// five minutes of total age. Direct database edits that bypass AppState
|
||||
// invalidation can therefore take at most this bounded interval to appear.
|
||||
const SYSTEM_CONFIG_CACHE_MAX_STALENESS: Duration = Duration::from_secs(5 * 60);
|
||||
const SCHEDULER_AFFECTING_SYSTEM_CONFIG_KEYS: &[&str] = &[
|
||||
"enable_format_conversion",
|
||||
"keep_priority_on_conversion",
|
||||
"provider_priority_mode",
|
||||
"scheduling_mode",
|
||||
];
|
||||
const SCHEDULER_AFFECTING_SYSTEM_CONFIG_KEYS: &[&str] = &["enable_format_conversion"];
|
||||
const AUTH_AFFECTING_SYSTEM_CONFIG_KEYS: &[&str] = &[
|
||||
crate::constants::DEFAULT_USER_GROUP_CONFIG_KEY,
|
||||
crate::constants::ANTIGRAVITY_BEARER_BRIDGE_CONFIG_KEY,
|
||||
@@ -4350,12 +4345,13 @@ mod tests {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn system_config_entry_write_refreshes_cache_and_scheduler_affinity_for_routing_keys() {
|
||||
async fn system_config_entry_write_refreshes_cache_and_scheduler_affinity_for_format_conversion(
|
||||
) {
|
||||
let state = AppState::new()
|
||||
.expect("app state should build")
|
||||
.with_data_state_for_tests(
|
||||
GatewayDataState::disabled().with_system_config_values_for_tests([(
|
||||
"keep_priority_on_conversion".to_string(),
|
||||
"enable_format_conversion".to_string(),
|
||||
json!(false),
|
||||
)]),
|
||||
);
|
||||
@@ -4364,7 +4360,7 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
state
|
||||
.read_system_config_json_value("keep_priority_on_conversion")
|
||||
.read_system_config_json_value("enable_format_conversion")
|
||||
.await
|
||||
.expect("system config read should succeed"),
|
||||
Some(json!(false))
|
||||
@@ -4385,13 +4381,13 @@ mod tests {
|
||||
|
||||
let initial_epoch = state.scheduler_affinity_epoch();
|
||||
state
|
||||
.upsert_system_config_entry("keep_priority_on_conversion", &json!(true), None)
|
||||
.upsert_system_config_entry("enable_format_conversion", &json!(true), None)
|
||||
.await
|
||||
.expect("admin config write should succeed");
|
||||
|
||||
assert_eq!(
|
||||
state
|
||||
.read_system_config_json_value("keep_priority_on_conversion")
|
||||
.read_system_config_json_value("enable_format_conversion")
|
||||
.await
|
||||
.expect("system config read should use refreshed cache"),
|
||||
Some(json!(true))
|
||||
|
||||
@@ -680,10 +680,4 @@ impl SchedulerRuntimeState for AppState {
|
||||
expected_epoch,
|
||||
)
|
||||
}
|
||||
|
||||
async fn read_scheduler_ordering_config(
|
||||
&self,
|
||||
) -> Result<crate::scheduler::config::SchedulerOrderingConfig, GatewayError> {
|
||||
crate::scheduler::config::read_scheduler_ordering_config(self).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,9 @@ const BOOTSTRAP_SYSTEM_DEFAULT_ROUTING_GROUP_NAME: &str = "system-default";
|
||||
impl AppState {
|
||||
/// Make sure an enabled system-default routing group exists.
|
||||
///
|
||||
/// When none exists, one is created from the legacy scheduler system-config
|
||||
/// keys so that removing those keys later does not change behaviour. Returns
|
||||
/// the created group, or `None` when nothing had to be created (no routing
|
||||
/// storage, no writer, or a system default already exists).
|
||||
/// When none exists, one is created from the routing defaults.
|
||||
/// Returns the created group, or `None` when nothing had to be created (no
|
||||
/// routing storage, no writer, or a system default already exists).
|
||||
pub async fn ensure_system_default_routing_group(
|
||||
&self,
|
||||
) -> Result<Option<StoredRoutingGroup>, std::io::Error> {
|
||||
@@ -44,16 +43,12 @@ impl AppState {
|
||||
warn!(
|
||||
event_name = "routing_system_default_bootstrap_skipped",
|
||||
log_type = "event",
|
||||
"no system default routing group exists and routing storage is read-only; scheduler falls back to legacy system config"
|
||||
"no system default routing group exists and routing storage is read-only; scheduler uses routing defaults"
|
||||
);
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let legacy = crate::scheduler::config::read_legacy_scheduler_ordering_config(self).await?;
|
||||
let config = RoutingGroupConfig {
|
||||
default_policy: legacy.to_routing_default_policy(),
|
||||
..RoutingGroupConfig::default()
|
||||
};
|
||||
let config = RoutingGroupConfig::default();
|
||||
let config_json = serde_json::to_value(config)
|
||||
.map_err(|err| GatewayError::Internal(format!("serialize routing config: {err}")))?;
|
||||
|
||||
@@ -75,9 +70,10 @@ impl AppState {
|
||||
self.create_routing_group(CreateRoutingGroupRecord {
|
||||
id: uuid::Uuid::new_v4().to_string(),
|
||||
name,
|
||||
description: Some("自动从旧版调度配置迁移生成的系统默认策略".to_string()),
|
||||
description: Some("系统默认调度策略".to_string()),
|
||||
enabled: true,
|
||||
is_system_default: true,
|
||||
sort_order: 0,
|
||||
config_json,
|
||||
version: 1,
|
||||
created_at: now,
|
||||
|
||||
Reference in New Issue
Block a user