fix: reject bucketed configs in cluster constructor

This commit is contained in:
2026-04-17 14:44:21 +08:00
parent 7de38fa998
commit 008fe2fe5d

View File

@@ -37,7 +37,10 @@ pub struct Cluster {
impl Cluster { impl Cluster {
pub fn new(config: &Config, model: &ModelConfig) -> Self { pub fn new(config: &Config, model: &ModelConfig) -> Self {
let total_instances = config.cluster.total_instances(); let total_instances = config
.cluster
.require_legacy_single_pool("Cluster::new")
.unwrap_or_else(|err| panic!("{err}"));
let mut instances = Vec::with_capacity(total_instances as usize); let mut instances = Vec::with_capacity(total_instances as usize);
for id in 0..total_instances { for id in 0..total_instances {
instances.push(Instance::new( instances.push(Instance::new(
@@ -185,8 +188,8 @@ impl Cluster {
mod tests { mod tests {
use super::*; use super::*;
use crate::config::{ use crate::config::{
CalibrationConfig, ClusterConfig, Config, HardwareConfig, MetaStoreConfig, ModelConfig, BucketConfig, CalibrationConfig, ClusterConfig, Config, HardwareConfig, MetaStoreConfig,
RouterConfig, RouterMode, SimConfig, ModelConfig, RouterConfig, RouterMode, SimConfig,
}; };
use crate::trace::RequestRecord; use crate::trace::RequestRecord;
@@ -285,4 +288,29 @@ mod tests {
assert!(stats.ready_at > pure_pcie); assert!(stats.ready_at > pure_pcie);
} }
#[test]
fn cluster_new_rejects_bucketed_configs() {
let mut cfg = test_config(RouterMode::EstimatedTtft);
cfg.cluster.num_instances = None;
cfg.cluster.buckets = vec![BucketConfig {
name: "short".into(),
input_length_min: 0,
input_length_max: 64,
num_instances: 2,
}];
let panic = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
Cluster::new(&cfg, &cfg.model);
}))
.expect_err("bucketed Cluster::new should panic");
let msg = panic
.downcast_ref::<String>()
.cloned()
.or_else(|| panic.downcast_ref::<&str>().map(|s| (*s).to_string()))
.expect("panic payload should be a string");
assert!(msg.contains("Cluster::new"));
assert!(msg.contains("cluster.buckets"));
}
} }