- Notifications
You must be signed in to change notification settings - Fork4.9k
Commitf49a80c
Fix "base" snapshot handling in logical decoding
Two closely related bugs are fixed. First, xmin of logical slots wasadvanced too early. During xl_running_xacts processing, xmin of theslot was set to the oldest running xid in the record, but that's wrong:actually, snapshots which will be used for not-yet-replayed transactionsmight consider older txns as running too, so we need to keep xmin backfor them. The problem wasn't noticed earlier because DDL which allowsto delete tuple (set xmax) while some another not-yet-committedtransaction looks at it is pretty rare, if not unique: e.g. all forms ofALTER TABLE which change schema acquire ACCESS EXCLUSIVE lockconflicting with any inserts. The included test case (test_decoding'soldest_xmin) uses ALTER of a composite type, which doesn't have suchinterlocking.To deal with this, we must be able to quickly retrieve oldest xmin(oldest running xid among all assigned snapshots) from ReorderBuffer. Tofix, add another list of ReorderBufferTXNs to the reorderbuffer, wheretransactions are sorted by base-snapshot-LSN. This is slightlydifferent from the existing (sorted by first-LSN) list, because atransaction can have an earlier LSN but a later Xmin, if its firstrecord does not obtain an xmin (eg. xl_xact_assignment). Note this newlist doesn't fully replace the existing txn list: we still need that oneto prevent WAL recycling.The second issue concerns SnapBuilder snapshots and subtransactions.SnapBuildDistributeNewCatalogSnapshot never assigned a snapshot to atransaction that is known to be a subtxn, which is good in the commoncase that the top-level transaction already has one (no point in doingso), but a bug otherwise. To fix, arrange to transfer the snapshot fromthe subtxn to its top-level txn as soon as the kinship gets known.test_decoding's snapshot_transfer verifies this.Also, fix a minor memory leak: refcount of toplevel's old base snapshotwas not decremented when the snapshot is transferred from child.Liberally sprinkle code comments, and rewrite a few existing ones. Thispart is my (Álvaro's) contribution to this commit, as I had to write allthose comments in order to understand the existing code and Arseny'spatch.Reported-by: Arseny Sher <a.sher@postgrespro.ru>Diagnosed-by: Arseny Sher <a.sher@postgrespro.ru>Co-authored-by: Arseny Sher <a.sher@postgrespro.ru>Co-authored-by: Álvaro Herrera <alvherre@alvh.no-ip.org>Reviewed-by: Antonin Houska <ah@cybertec.at>Discussion:https://postgr.es/m/87lgdyz1wj.fsf@ars-thinkpad1 parent4d54543 commitf49a80c
File tree
8 files changed
+409
-104
lines changed- contrib/test_decoding
- expected
- specs
- src
- backend/replication/logical
- include/replication
8 files changed
+409
-104
lines changedLines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
50 | 50 |
| |
51 | 51 |
| |
52 | 52 |
| |
53 |
| - | |
| 53 | + | |
| 54 | + | |
54 | 55 |
| |
55 | 56 |
| |
56 | 57 |
| |
|
Lines changed: 27 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + |
Lines changed: 49 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + |
Lines changed: 37 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + |
Lines changed: 42 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + |
0 commit comments
Comments
(0)