Skip to content

Commit df85139

Browse files
authored
Update README. Comments. Version bump. (#60)
* update readme * comments * just a version bump
1 parent 509e481 commit df85139

15 files changed

+196
-155
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pgcat"
3-
version = "0.1.0"
3+
version = "0.1.0-beta2"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

README.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ PostgreSQL pooler (like PgBouncer) with sharding, load balancing and failover su
1818
| Load balancing of read queries | :white_check_mark: | Using round-robin between replicas. Primary is included when `primary_reads_enabled` is enabled (default). |
1919
| Sharding | :white_check_mark: | Transactions are sharded using `SET SHARD TO` and `SET SHARDING KEY TO` syntax extensions; see examples below. |
2020
| Failover | :white_check_mark: | Replicas are tested with a health check. If a health check fails, remaining replicas are attempted; see below for algorithm description and examples. |
21-
| Statistics reporting | :white_check_mark: | Statistics available in the admin database (`pgcat` and `pgbouncer`) with `SHOW STATS`, `SHOW POOLS` and others. |
22-
| Live configuration reloading | :white_check_mark: | Reload supported settings with a `SIGHUP` to the process, e.g. `kill -s SIGHUP $(pgrep pgcat)` or `RELOAD` query issued to the admin database. |
21+
| Statistics | :white_check_mark: | Statistics available in the admin database (`pgcat` and `pgbouncer`) with `SHOW STATS`, `SHOW POOLS` and others. |
22+
| Live configuration reloading | :white_check_mark: | Reload supported settings with a `SIGHUP` to the process, e.g. `kill -s SIGHUP $(pgrep pgcat)` or `RELOAD` query issued to the admin database. |
2323
| Client authentication | :x: :wrench: | On the roadmap; currently all clients are allowed to connect and one user is used to connect to Postgres. |
24+
| Admin database | :white_check_mark: | The admin database, similar to PgBouncer's, allows to query for statistics and reload the configuration. |
2425

2526
## Deployment
2627

@@ -89,7 +90,7 @@ See [sharding README](./tests/sharding/README.md) for sharding logic testing.
8990
| Load balancing | :white_check_mark: | :white_check_mark: | We could test this by emitting statistics for each replica and compare them. |
9091
| Failover | :white_check_mark: | :white_check_mark: | Misconfigure a replica in `pgcat.toml` and watch it forward queries to spares. CI testing is using Toxiproxy. |
9192
| Sharding | :white_check_mark: | :white_check_mark: | See `tests/sharding` and `tests/ruby` for an Rails/ActiveRecord example. |
92-
| Statistics reporting | :x: | :white_check_mark: | Run `nc -l -u 8125` and watch the stats come in every 15 seconds. |
93+
| Statistics | :white_check_mark: | :white_check_mark: | Query the admin database with `psql -h 127.0.0.1 -p 6432 -d pgbouncer -c 'SHOW STATS'`. |
9394
| Live config reloading | :white_check_mark: | :white_check_mark: | Run `kill -s SIGHUP $(pgrep pgcat)` and watch the config reload. |
9495

9596
## Usage
@@ -232,11 +233,15 @@ SELECT * FROM users WHERE email = '[email protected]'; -- shard setting lasts unt
232233

233234
### Statistics reporting
234235

235-
Stats are reported using StatsD every 15 seconds. The address is configurable with `statsd_address`, the default is `127.0.0.1:8125`. The stats are very similar to what Pgbouncer reports and the names are kept to be comparable.
236+
The stats are very similar to what Pgbouncer reports and the names are kept to be comparable. They are accessible by querying the admin database `pgcat`, and `pgbouncer` for compatibility.
237+
238+
```
239+
psql -h 127.0.0.1 -p 6432 -d pgbouncer -c 'SHOW DATABASES'
240+
```
236241

237242
### Live configuration reloading
238243

239-
The config can be reloaded by sending a `kill -s SIGHUP` to the process. Not all settings are currently supported by live reload:
244+
The config can be reloaded by sending a `kill -s SIGHUP` to the process or by querying `RELOAD` to the admin database. Not all settings are currently supported by live reload:
240245

241246
| **Config** | **Requires restart** |
242247
|-------------------------|----------------------|
@@ -246,7 +251,6 @@ The config can be reloaded by sending a `kill -s SIGHUP` to the process. Not all
246251
| `connect_timeout` | yes |
247252
| `healthcheck_timeout` | no |
248253
| `ban_time` | no |
249-
| `statsd_address` | yes |
250254
| `user` | yes |
251255
| `shards` | yes |
252256
| `default_role` | no |

src/admin.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
/// Admin database.
12
use bytes::{Buf, BufMut, BytesMut};
23
use log::{info, trace};
3-
use tokio::net::tcp::OwnedWriteHalf;
4-
54
use std::collections::HashMap;
5+
use tokio::net::tcp::OwnedWriteHalf;
66

77
use crate::config::{get_config, parse};
88
use crate::errors::Error;
99
use crate::messages::*;
1010
use crate::pool::ConnectionPool;
1111
use crate::stats::get_stats;
1212

13-
/// Handle admin client
13+
/// Handle admin client.
1414
pub async fn handle_admin(
1515
stream: &mut OwnedWriteHalf,
1616
mut query: BytesMut,
@@ -58,7 +58,7 @@ pub async fn handle_admin(
5858
}
5959
}
6060

61-
/// SHOW LISTS
61+
/// Column-oriented statistics.
6262
async fn show_lists(stream: &mut OwnedWriteHalf, pool: &ConnectionPool) -> Result<(), Error> {
6363
let stats = get_stats();
6464

@@ -125,7 +125,7 @@ async fn show_lists(stream: &mut OwnedWriteHalf, pool: &ConnectionPool) -> Resul
125125
write_all_half(stream, res).await
126126
}
127127

128-
/// SHOW VERSION
128+
/// Show PgCat version.
129129
async fn show_version(stream: &mut OwnedWriteHalf) -> Result<(), Error> {
130130
let mut res = BytesMut::new();
131131

@@ -140,7 +140,7 @@ async fn show_version(stream: &mut OwnedWriteHalf) -> Result<(), Error> {
140140
write_all_half(stream, res).await
141141
}
142142

143-
/// SHOW POOLS
143+
/// Show utilization of connection pools for each shard and replicas.
144144
async fn show_pools(stream: &mut OwnedWriteHalf, pool: &ConnectionPool) -> Result<(), Error> {
145145
let stats = get_stats();
146146
let config = {
@@ -189,14 +189,15 @@ async fn show_pools(stream: &mut OwnedWriteHalf, pool: &ConnectionPool) -> Resul
189189

190190
res.put(command_complete("SHOW"));
191191

192+
// ReadyForQuery
192193
res.put_u8(b'Z');
193194
res.put_i32(5);
194195
res.put_u8(b'I');
195196

196197
write_all_half(stream, res).await
197198
}
198199

199-
/// SHOW DATABASES
200+
/// Show shards and replicas.
200201
async fn show_databases(stream: &mut OwnedWriteHalf, pool: &ConnectionPool) -> Result<(), Error> {
201202
let guard = get_config();
202203
let config = &*guard.clone();
@@ -221,7 +222,6 @@ async fn show_databases(stream: &mut OwnedWriteHalf, pool: &ConnectionPool) -> R
221222

222223
let mut res = BytesMut::new();
223224

224-
// RowDescription
225225
res.put(row_description(&columns));
226226

227227
for shard in 0..pool.shards() {
@@ -265,7 +265,7 @@ async fn ignore_set(stream: &mut OwnedWriteHalf) -> Result<(), Error> {
265265
custom_protocol_response_ok(stream, "SET").await
266266
}
267267

268-
/// RELOAD
268+
/// Reload the configuration file without restarting the process.
269269
async fn reload(stream: &mut OwnedWriteHalf) -> Result<(), Error> {
270270
info!("Reloading config");
271271

@@ -280,7 +280,6 @@ async fn reload(stream: &mut OwnedWriteHalf) -> Result<(), Error> {
280280

281281
let mut res = BytesMut::new();
282282

283-
// CommandComplete
284283
res.put(command_complete("RELOAD"));
285284

286285
// ReadyForQuery
@@ -291,13 +290,14 @@ async fn reload(stream: &mut OwnedWriteHalf) -> Result<(), Error> {
291290
write_all_half(stream, res).await
292291
}
293292

293+
/// Shows current configuration.
294294
async fn show_config(stream: &mut OwnedWriteHalf) -> Result<(), Error> {
295295
let guard = get_config();
296296
let config = &*guard.clone();
297297
let config: HashMap<String, String> = config.into();
298298
drop(guard);
299299

300-
// Configs that cannot be changed dynamically.
300+
// Configs that cannot be changed without restarting.
301301
let immutables = ["host", "port", "connect_timeout"];
302302

303303
// Columns
@@ -327,14 +327,15 @@ async fn show_config(stream: &mut OwnedWriteHalf) -> Result<(), Error> {
327327

328328
res.put(command_complete("SHOW"));
329329

330+
// ReadyForQuery
330331
res.put_u8(b'Z');
331332
res.put_i32(5);
332333
res.put_u8(b'I');
333334

334335
write_all_half(stream, res).await
335336
}
336337

337-
/// SHOW STATS
338+
/// Show shard and replicas statistics.
338339
async fn show_stats(stream: &mut OwnedWriteHalf, pool: &ConnectionPool) -> Result<(), Error> {
339340
let columns = vec![
340341
("database", DataType::Text),
@@ -378,6 +379,7 @@ async fn show_stats(stream: &mut OwnedWriteHalf, pool: &ConnectionPool) -> Resul
378379

379380
res.put(command_complete("SHOW"));
380381

382+
// ReadyForQuery
381383
res.put_u8(b'Z');
382384
res.put_i32(5);
383385
res.put_u8(b'I');

0 commit comments

Comments
 (0)