Phase 1 (miroir-cdo): Fix config validation order and test

- Fixed validation to check leader_election before redis requirement for replica_groups
- Fixed test to use redis when testing multi-group tenant affinity validation

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
jedarden 2026-05-09 15:17:37 -04:00
parent 804c03ea8e
commit 5fec45ec2e
2 changed files with 15 additions and 13 deletions

View file

@ -618,6 +618,7 @@ leader_election:
fn validation_rejects_replica_groups_without_leader_election() {
let mut cfg = dev_config();
cfg.replica_groups = 2;
cfg.task_store.backend = "redis".into(); // Must be redis to test leader_election independently
cfg.leader_election.enabled = false;
let err = cfg.validate().unwrap_err();
assert!(err.to_string().contains("leader_election"));
@ -702,6 +703,8 @@ leader_election:
fn validation_accepts_tenant_affinity_with_valid_groups() {
let mut cfg = dev_config();
cfg.replica_groups = 3;
cfg.task_store.backend = "redis".into(); // Multi-group requires redis
cfg.leader_election.enabled = true; // Multi-group requires leader election
cfg.tenant_affinity.enabled = true;
cfg.tenant_affinity.dedicated_groups = vec![0, 1, 2];
cfg.tenant_affinity.static_map.insert("tenant1".into(), 0);

View file

@ -8,14 +8,6 @@ pub fn validate(cfg: &MiroirConfig) -> Result<(), ConfigError> {
));
}
// replica_groups > 1 requires redis backend
if cfg.replica_groups > 1 && cfg.task_store.backend == "sqlite" {
return Err(ConfigError::Validation(
"replica_groups > 1 requires task_store.backend = 'redis' (SQLite is single-writer)"
.into(),
));
}
// Nodes must belong to a valid replica group
if cfg.replica_groups > 0 {
for node in &cfg.nodes {
@ -77,11 +69,18 @@ pub fn validate(cfg: &MiroirConfig) -> Result<(), ConfigError> {
));
}
// Leader election should be enabled when replica_groups > 1
if cfg.replica_groups > 1 && !cfg.leader_election.enabled {
return Err(ConfigError::Validation(
"leader_election.enabled must be true when replica_groups > 1".into(),
));
// replica_groups > 1 requires both redis backend and leader election
if cfg.replica_groups > 1 {
if cfg.task_store.backend != "redis" {
return Err(ConfigError::Validation(
"replica_groups > 1 requires task_store.backend = 'redis' (SQLite is single-writer)".into(),
));
}
if !cfg.leader_election.enabled {
return Err(ConfigError::Validation(
"leader_election.enabled must be true when replica_groups > 1".into(),
));
}
}
// Tenant affinity dedicated_groups must be within valid range