Skip to content

Commit 106ebee

Browse files
drdrshlevkk
andauthored
Fix local dev (#112)
* Fix Dev env * Update tests/sharding/query_routing_setup.sql * Update tests/sharding/query_routing_setup.sql * bring pgcat.toml on ci and local dev to parity * more parity * pool names * pool names * less diff * fix tests * fmt * add other user to setup Co-authored-by: Lev Kokotov <levkk@users.noreply.github.com>
1 parent b79f55a commit 106ebee

File tree

4 files changed

+83
-24
lines changed

4 files changed

+83
-24
lines changed

.circleci/pgcat.toml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ admin_password = "admin_pass"
3535
# pool
3636
# configs are structured as pool.<pool_name>
3737
# the pool_name is what clients use as database name when connecting
38-
# For the example below a client can connect using "postgres://sharding_user:sharding_user@pgcat_host:pgcat_port/sharded"
38+
# For the example below a client can connect using "postgres://sharding_user:sharding_user@pgcat_host:pgcat_port/sharded_db"
3939
[pools.sharded_db]
4040
# Pool mode (see PgBouncer docs for more).
4141
# session: one server connection per connected client
@@ -80,6 +80,11 @@ password = "sharding_user"
8080
# is the sum of pool_size across all users.
8181
pool_size = 9
8282

83+
[pools.sharded_db.users.1]
84+
username = "other_user"
85+
password = "other_user"
86+
pool_size = 21
87+
8388
# Shard 0
8489
[pools.sharded_db.shards.0]
8590
# [ host, port, role ]
@@ -103,3 +108,23 @@ servers = [
103108
[ "localhost", 5432, "replica" ],
104109
]
105110
database = "shard2"
111+
112+
113+
[pools.simple_db]
114+
pool_mode = "session"
115+
default_role = "primary"
116+
query_parser_enabled = true
117+
primary_reads_enabled = true
118+
sharding_function = "pg_bigint_hash"
119+
120+
[pools.simple_db.users.0]
121+
username = "simple_user"
122+
password = "simple_user"
123+
pool_size = 5
124+
125+
[pools.simple_db.shards.0]
126+
servers = [
127+
[ "127.0.0.1", 5432, "primary" ],
128+
[ "localhost", 5432, "replica" ]
129+
]
130+
database = "some_db"

pgcat.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ port = 6432
1414
# How long to wait before aborting a server connection (ms).
1515
connect_timeout = 5000
1616

17-
# How much time to give `SELECT 1` health check query to return with a result (ms).
17+
# How much time to give the health check query to return with a result (ms).
1818
healthcheck_timeout = 1000
1919

2020
# For how long to ban a server if it fails a health check (seconds).
@@ -29,14 +29,14 @@ autoreload = false
2929

3030
# Credentials to access the virtual administrative database (pgbouncer or pgcat)
3131
# Connecting to that database allows running commands like `SHOW POOLS`, `SHOW DATABASES`, etc..
32-
admin_username = "user"
33-
admin_password = "pass"
32+
admin_username = "admin_user"
33+
admin_password = "admin_pass"
3434

3535
# pool
3636
# configs are structured as pool.<pool_name>
3737
# the pool_name is what clients use as database name when connecting
38-
# For the example below a client can connect using "postgres://sharding_user:sharding_user@pgcat_host:pgcat_port/sharded"
39-
[pools.sharded]
38+
# For the example below a client can connect using "postgres://sharding_user:sharding_user@pgcat_host:pgcat_port/sharded_db"
39+
[pools.sharded_db]
4040
# Pool mode (see PgBouncer docs for more).
4141
# session: one server connection per connected client
4242
# transaction: one server connection per client transaction
@@ -72,21 +72,21 @@ primary_reads_enabled = true
7272
sharding_function = "pg_bigint_hash"
7373

7474
# Credentials for users that may connect to this cluster
75-
[pools.sharded.users.0]
75+
[pools.sharded_db.users.0]
7676
username = "sharding_user"
7777
password = "sharding_user"
7878
# Maximum number of server connections that can be established for this user
7979
# The maximum number of connection from a single Pgcat process to any database in the cluster
8080
# is the sum of pool_size across all users.
8181
pool_size = 9
8282

83-
[pools.sharded.users.1]
83+
[pools.sharded_db.users.1]
8484
username = "other_user"
8585
password = "other_user"
8686
pool_size = 21
8787

8888
# Shard 0
89-
[pools.sharded.shards.0]
89+
[pools.sharded_db.shards.0]
9090
# [ host, port, role ]
9191
servers = [
9292
[ "127.0.0.1", 5432, "primary" ],
@@ -95,14 +95,14 @@ servers = [
9595
# Database name (e.g. "postgres")
9696
database = "shard0"
9797

98-
[pools.sharded.shards.1]
98+
[pools.sharded_db.shards.1]
9999
servers = [
100100
[ "127.0.0.1", 5432, "primary" ],
101101
[ "localhost", 5432, "replica" ],
102102
]
103103
database = "shard1"
104104

105-
[pools.sharded.shards.2]
105+
[pools.sharded_db.shards.2]
106106
servers = [
107107
[ "127.0.0.1", 5432, "primary" ],
108108
[ "localhost", 5432, "replica" ],

src/config.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -521,30 +521,33 @@ mod test {
521521

522522
assert_eq!(get_config().general.ban_time, 60);
523523
assert_eq!(get_config().pools.len(), 2);
524-
assert_eq!(get_config().pools["sharded"].shards.len(), 3);
524+
assert_eq!(get_config().pools["sharded_db"].shards.len(), 3);
525525
assert_eq!(get_config().pools["simple_db"].shards.len(), 1);
526-
assert_eq!(get_config().pools["sharded"].users.len(), 2);
526+
assert_eq!(get_config().pools["sharded_db"].users.len(), 2);
527527
assert_eq!(get_config().pools["simple_db"].users.len(), 1);
528528

529529
assert_eq!(
530-
get_config().pools["sharded"].shards["0"].servers[0].0,
530+
get_config().pools["sharded_db"].shards["0"].servers[0].0,
531531
"127.0.0.1"
532532
);
533533
assert_eq!(
534-
get_config().pools["sharded"].shards["1"].servers[0].2,
534+
get_config().pools["sharded_db"].shards["1"].servers[0].2,
535535
"primary"
536536
);
537-
assert_eq!(get_config().pools["sharded"].shards["1"].database, "shard1");
538537
assert_eq!(
539-
get_config().pools["sharded"].users["0"].username,
538+
get_config().pools["sharded_db"].shards["1"].database,
539+
"shard1"
540+
);
541+
assert_eq!(
542+
get_config().pools["sharded_db"].users["0"].username,
540543
"sharding_user"
541544
);
542545
assert_eq!(
543-
get_config().pools["sharded"].users["1"].password,
546+
get_config().pools["sharded_db"].users["1"].password,
544547
"other_user"
545548
);
546-
assert_eq!(get_config().pools["sharded"].users["1"].pool_size, 21);
547-
assert_eq!(get_config().pools["sharded"].default_role, "any");
549+
assert_eq!(get_config().pools["sharded_db"].users["1"].pool_size, 21);
550+
assert_eq!(get_config().pools["sharded_db"].default_role, "any");
548551

549552
assert_eq!(
550553
get_config().pools["simple_db"].shards["0"].servers[0].0,

tests/sharding/query_routing_setup.sql

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
21
DROP DATABASE IF EXISTS shard0;
32
DROP DATABASE IF EXISTS shard1;
43
DROP DATABASE IF EXISTS shard2;
4+
DROP DATABASE IF EXISTS some_db;
55

66
CREATE DATABASE shard0;
77
CREATE DATABASE shard1;
88
CREATE DATABASE shard2;
9+
CREATE DATABASE some_db;
910

1011
\c shard0
1112

@@ -41,21 +42,51 @@ CREATE TABLE data (
4142

4243
CREATE TABLE data_shard_2 PARTITION OF data FOR VALUES WITH (MODULUS 3, REMAINDER 2);
4344

45+
46+
\c some_db
47+
48+
DROP TABLE IF EXISTS data CASCADE;
49+
50+
CREATE TABLE data (
51+
id BIGINT,
52+
value VARCHAR
53+
);
54+
4455
DROP ROLE IF EXISTS sharding_user;
56+
DROP ROLE IF EXISTS other_user;
57+
DROP ROLE IF EXISTS simple_user;
4558
CREATE ROLE sharding_user ENCRYPTED PASSWORD 'sharding_user' LOGIN;
59+
CREATE ROLE other_user ENCRYPTED PASSWORD 'other_user' LOGIN;
60+
CREATE ROLE simple_user ENCRYPTED PASSWORD 'simple_user' LOGIN;
4661

47-
GRANT CONNECT ON DATABASE shard0 TO sharding_user;
48-
GRANT CONNECT ON DATABASE shard1 TO sharding_user;
49-
GRANT CONNECT ON DATABASE shard2 TO sharding_user;
62+
GRANT CONNECT ON DATABASE shard0 TO sharding_user;
63+
GRANT CONNECT ON DATABASE shard1 TO sharding_user;
64+
GRANT CONNECT ON DATABASE shard2 TO sharding_user;
65+
66+
GRANT CONNECT ON DATABASE shard0 TO other_user;
67+
GRANT CONNECT ON DATABASE shard1 TO other_user;
68+
GRANT CONNECT ON DATABASE shard2 TO other_user;
69+
70+
GRANT CONNECT ON DATABASE some_db TO simple_user;
5071

5172
\c shard0
5273
GRANT ALL ON SCHEMA public TO sharding_user;
5374
GRANT ALL ON TABLE data TO sharding_user;
75+
GRANT ALL ON SCHEMA public TO other_user;
76+
GRANT ALL ON TABLE data TO other_user;
5477

5578
\c shard1
5679
GRANT ALL ON SCHEMA public TO sharding_user;
5780
GRANT ALL ON TABLE data TO sharding_user;
81+
GRANT ALL ON SCHEMA public TO other_user;
82+
GRANT ALL ON TABLE data TO other_user;
5883

5984
\c shard2
6085
GRANT ALL ON SCHEMA public TO sharding_user;
6186
GRANT ALL ON TABLE data TO sharding_user;
87+
GRANT ALL ON SCHEMA public TO other_user;
88+
GRANT ALL ON TABLE data TO other_user;
89+
90+
\c some_db
91+
GRANT ALL ON SCHEMA public TO simple_user;
92+
GRANT ALL ON TABLE data TO simple_user;

0 commit comments

Comments
 (0)