diff --git a/src/config.rs b/src/config.rs index fe9206d..b517c78 100644 --- a/src/config.rs +++ b/src/config.rs @@ -77,13 +77,39 @@ pub async fn parse(path: &str) -> Result { } }; - // We use addresses as unique identifiers, - // let's make sure they are unique in the config as well. + // Quick config sanity check. for shard in &config.shards { + // We use addresses as unique identifiers, + // let's make sure they are unique in the config as well. let mut dup_check = HashSet::new(); + let mut primary_count = 0; for server in &shard.1.servers { dup_check.insert(server); + + // Check that we define only zero or one primary. + match server.2.as_ref() { + "primary" => primary_count += 1, + _ => (), + }; + + // Check role spelling. + match server.2.as_ref() { + "primary" => (), + "replica" => (), + _ => { + println!( + "> Shard {} server role must be either 'primary' or 'replica', got: '{}'", + shard.0, server.2 + ); + return Err(Error::BadConfig); + } + }; + } + + if primary_count > 1 { + println!("> Shard {} has more than on primary configured.", &shard.0); + return Err(Error::BadConfig); } if dup_check.len() != shard.1.servers.len() { diff --git a/tests/sharding/query_routing.sh b/tests/sharding/query_routing.sh index acc8532..d6098fa 100644 --- a/tests/sharding/query_routing.sh +++ b/tests/sharding/query_routing.sh @@ -8,7 +8,7 @@ echo "Giving Postgres 5 seconds to start up..." # sleep 5 -psql -f query_routing_setup.sql +# psql -f query_routing_setup.sql psql -h 127.0.0.1 -p 6432 -f query_routing_test_insert.sql