forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit955a684
committed
Fix race condition leading to hanging logical slot creation.
The snapshot assembly during the creation of logical slots reliedwaiting for transactions in xl_running_xacts to end, by checking fortheir commit/abort records. Unfortunately, despite locking, it ispossible to see an xl_running_xact record listing transactions asready, that have already WAL-logged an commit/abort record, as thelocking just prevents the ProcArray to be adjusted, and the commitrecord has to be logged first.That lead to either delayed or hanging snapshot creation, becausesnapbuild.c would wait "forever" to see commit/abort records for sometransactions. That hang resolved only if a xl_running_xacts recordwithout any running transactions happened to be logged, far fromcertain on a busy server.It's impractical to prevent that via more heavyweight locking, thelikelihood of deadlocks and significantly increased contention wouldbe too big.Instead change the initial snapshot creation to be solely based ontracking the oldest running transaction viaxl_running_xacts->oldestRunningXid - that actually ends upsignificantly simplifying the code. That has two disadvantages:1) Because we cannot fully "trust" the contents of xl_running_xacts, we cannot use it to build the initial snapshot. Instead we have to wait twice for all running transactions to finish.2) Previously a slot, unless the race occurred, could be created when the all transaction perceived as running based on commit/abort records, now we have to wait for the next xl_running_xacts record.To address that, trigger logging new xl_running_xacts record fromwithin snapbuild.c exactly when necessary.Unfortunately snabuild.c's SnapBuild is stored on disk, one of thestupider ideas of a certain Mr Freund, so we can't change it in aminor release. As this is going to be backpatched, we have to hackaround a bit to keep on-disk compatibility. A later commit willrejigger that on master.Author: Andres Freund, based on a quite different patch from Petr JelinekAnalyzed-By: Petr JelinekReviewed-By: Petr JelinekDiscussion:https://postgr.es/m/f37e975c-908f-858e-707f-058d3b1eb214@2ndquadrant.comBackpatch: 9.4-, where logical decoding has been introduced1 parent9aab83f commit955a684
File tree
6 files changed
+220
-249
lines changed- contrib/test_decoding
- expected
- specs
- src
- backend/replication/logical
- include/replication
6 files changed
+220
-249
lines changedLines changed: 12 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | 1 |
| |
2 | 2 |
| |
3 |
| - | |
4 |
| - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
5 | 6 |
| |
6 | 7 |
| |
7 | 8 |
| |
8 | 9 |
| |
9 |
| - | |
| 10 | + | |
| 11 | + | |
10 | 12 |
| |
11 | 13 |
| |
12 | 14 |
| |
13 | 15 |
| |
14 | 16 |
| |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
15 | 23 |
| |
16 | 24 |
| |
17 | 25 |
| |
18 | 26 |
| |
| 27 | + | |
19 | 28 |
| |
20 | 29 |
| |
21 | 30 |
| |
|
Lines changed: 5 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
24 | 24 |
| |
25 | 25 |
| |
26 | 26 |
| |
27 |
| - | |
| 27 | + | |
| 28 | + | |
28 | 29 |
| |
29 | 30 |
| |
30 | 31 |
| |
31 | 32 |
| |
32 | 33 |
| |
33 | 34 |
| |
34 | 35 |
| |
35 |
| - | |
| 36 | + | |
| 37 | + | |
36 | 38 |
| |
37 | 39 |
| |
38 | 40 |
| |
39 | 41 |
| |
40 | 42 |
| |
41 | 43 |
| |
42 | 44 |
| |
43 |
| - | |
| 45 | + |
Lines changed: 0 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
622 | 622 |
| |
623 | 623 |
| |
624 | 624 |
| |
625 |
| - | |
626 |
| - | |
627 |
| - | |
628 | 625 |
| |
629 | 626 |
| |
630 | 627 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1725 | 1725 |
| |
1726 | 1726 |
| |
1727 | 1727 |
| |
1728 |
| - | |
| 1728 | + | |
1729 | 1729 |
| |
1730 | 1730 |
| |
1731 | 1731 |
| |
|
0 commit comments
Comments
(0)