File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -77,13 +77,39 @@ pub async fn parse(path: &str) -> Result<Config, Error> {
77
77
}
78
78
} ;
79
79
80
- // We use addresses as unique identifiers,
81
- // let's make sure they are unique in the config as well.
80
+ // Quick config sanity check.
82
81
for shard in & config. shards {
82
+ // We use addresses as unique identifiers,
83
+ // let's make sure they are unique in the config as well.
83
84
let mut dup_check = HashSet :: new ( ) ;
85
+ let mut primary_count = 0 ;
84
86
85
87
for server in & shard. 1 . servers {
86
88
dup_check. insert ( server) ;
89
+
90
+ // Check that we define only zero or one primary.
91
+ match server. 2 . as_ref ( ) {
92
+ "primary" => primary_count += 1 ,
93
+ _ => ( ) ,
94
+ } ;
95
+
96
+ // Check role spelling.
97
+ match server. 2 . as_ref ( ) {
98
+ "primary" => ( ) ,
99
+ "replica" => ( ) ,
100
+ _ => {
101
+ println ! (
102
+ "> Shard {} server role must be either 'primary' or 'replica', got: '{}'" ,
103
+ shard. 0 , server. 2
104
+ ) ;
105
+ return Err ( Error :: BadConfig ) ;
106
+ }
107
+ } ;
108
+ }
109
+
110
+ if primary_count > 1 {
111
+ println ! ( "> Shard {} has more than on primary configured." , & shard. 0 ) ;
112
+ return Err ( Error :: BadConfig ) ;
87
113
}
88
114
89
115
if dup_check. len ( ) != shard. 1 . servers . len ( ) {
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ echo "Giving Postgres 5 seconds to start up..."
8
8
9
9
# sleep 5
10
10
11
- psql -f query_routing_setup.sql
11
+ # psql -f query_routing_setup.sql
12
12
13
13
psql -h 127.0.0.1 -p 6432 -f query_routing_test_insert.sql
14
14
You can’t perform that action at this time.
0 commit comments