Skip to content

Commit 78d10fa

Browse files
committed
Update docs for 2pc
1 parent 05950a7 commit 78d10fa

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

docs/features/sharding/cross-shard.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ While this works for simple queries, others that involve sorting or aggregation
1515

1616
## Sorting
1717

18-
If the client requests results to be ordered by one or more columns, PgDog can interpret this request and perform the sorting once it receives all data messages from all servers. For queries that span multiple shards, this feature allows to retrieve results in the correct order. For example:
18+
If the client requests results to be ordered by one or more columns, PgDog can interpret this request and perform the sorting once it receives all data messages from all servers. For queries that span multiple shards, this feature allows you to retrieve results in the correct order. For example:
1919

2020
```postgresql
2121
SELECT * FROM users WHERE admin IS true
@@ -71,13 +71,12 @@ DDL statements, i.e., queries that modify the database schema, like `CREATE TABL
7171

7272
This assumes that all shards in the cluster have an identical schema. This is typically desired to make management of sharded databases simpler, but in scenarios where this is not possible, DDL queries can always be routed to specific shards using [manual routing](manual-routing.md).
7373

74-
!!! note
75-
PgDog doesn't use two-phase commit so make sure your DDL
76-
statements are idempotent and can be retried in case of an error.
74+
If [two-phase commit](2pc.md) is enabled, DDL statements have a high chance to be atomic. Alternatively, they can generally be written to be idempotent and safe to retry in case of error.
7775

7876
### Two-phase commit
7977

80-
Currently, PgDog doesn't use two-phase commit to synchronize changes across all shards. Support for this feature is currently being built, and will require database operators to enable [prepared transactions](https://www.postgresql.org/docs/current/sql-prepare-transaction.html).
78+
PgDog supports Postgres' [prepared transactions](https://www.postgresql.org/docs/current/sql-prepare-transaction.html) and [two-phase commit](2pc.md). If enabled, cross-shard writes have a high chance to be atomic and eventually consistent.
79+
8180

8281
## Aggregates
8382

docs/features/sharding/omnishards.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ tables = [
1919
]
2020
```
2121

22-
## Query router
22+
## Query routing
2323

2424
Omnisharded tables are treated differently by the query router. Write queries are sent to all shards concurrently, while read queries are distributed evenly between shards using round robin.
2525

2626
If the query contains a sharding key, it will be used instead, and omnisharded tables in that query will be ignored.
2727

2828
### Consistency
2929

30-
Writing data to omnisharded tables is not currently atomic. While we work on adding support for two-phase commit, make sure writes to omni tables can be repeated in case of failure. This can be done with unique indexes and `ON CONFLICT ... DO UPDATE` queries.
30+
Writing data to omnisharded tables is atomic if you enabled [two-phase commit](2pc.md).
3131

32-
Reads from omni tables are routed to individual shards. If you update data in those tables at the same time, `SELECT` queries to these tables may return different results for a brief period of time.
32+
If you can't or choose not to use 2pc, make sure writes to omnisharded tables can be repeated in case of failure. This can be achieved by using unique indexes and `INSERT ... ON CONFLICT ... DO UPDATE` queries.
33+
34+
Since reads from omnisharded tables are routed to individual shards, while two-phase commit takes place, queries to these tables may return different results for a brief period of time.

docs/features/sharding/supported-queries.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
Postgres has 3 kinds of queries, each handled a little bit differently in a sharded context:
66

77
1. CRUD statements (`INSERT`, `UPDATE`, `SELECT`, `DELETE`, `COPY`) are parsed for sharding keys and routed to one or more shards
8-
5. DDL statements (e.g., `CREATE TABLE`, `BEGIN`, `ROLLBACK`, etc.) are sent to all shards in parallel
9-
6. `SET` statements are intercepted and client state is updated to keep track of session variables
8+
2. DDL statements (e.g., `CREATE TABLE`, `BEGIN`, `ROLLBACK`, etc.) are sent to all shards in parallel
9+
3. `SET` statements are intercepted and client state is updated to keep track of session variables
1010

1111
## CRUD
1212

@@ -20,14 +20,14 @@ Postgres has 3 kinds of queries, each handled a little bit differently in a shar
2020
#### Examples
2121

2222
```postgresql
23-
-- Sharding key equals to a single value
23+
-- Sharding key equals a single value
2424
SELECT * FROM users WHERE user_id = $1
2525
2626
-- Sharding keys IN tuple
2727
SELECT * FROM users WHERE id IN ($1, $2, $3)
2828
```
2929

30-
Queries that don't match this pattern presently will be routed to all shards. We are continuously adding support for more complex patterns.
30+
Queries that don't match this pattern will currently be routed to all shards. We are continuously adding support for more complex patterns.
3131

3232
#### `SELECT` queries that write
3333

@@ -72,4 +72,4 @@ Currently, PgDog only supports `INSERT` statements with one tuple in the `VALUES
7272

7373
## DDL
7474

75-
DDL statements are sent to all shards in parallel. Currently, PgDog doesn't use 2-phase commit so consider using idempotent schema changes to guarantee consistency across shards.
75+
DDL statements (e.g., `CREATE TABLE`) are sent to all shards in parallel. If [two-phase commit](2pc.md) is enabled, DDL statements have a high chance to be atomic.

0 commit comments

Comments
 (0)