- Notifications
You must be signed in to change notification settings - Fork5k
Commit6af1793
committed
Add info in WAL records in preparation for logical slot conflict handling
This commit only implements one prerequisite part for allowing logicaldecoding. The commit message contains an explanation of the overall design,which later commits will refer back to.Overall design:1. We want to enable logical decoding on standbys, but replay of WALfrom the primary might remove data that is needed by logical decoding,causing error(s) on the standby. To prevent those errors, a new replicationconflict scenario needs to be addressed (as much as hot standby does).2. Our chosen strategy for dealing with this type of replication slotis to invalidate logical slots for which needed data has been removed.3. To do this we need the latestRemovedXid for each change, just as wedo for physical replication conflicts, but we also need to knowwhether any particular change was to data that logical replicationmight access. That way, during WAL replay, we know when there is a risk ofconflict and, if so, if there is a conflict.4. We can't rely on the standby's relcache entries for this purpose inany way, because the startup process can't access catalog contents.5. Therefore every WAL record that potentially removes data from theindex or heap must carry a flag indicating whether or not it is onethat might be accessed during logical decoding.Why do we need this for logical decoding on standby?First, let's forget about logical decoding on standby and recall thaton a primary database, any catalog rows that may be needed by a logicaldecoding replication slot are not removed.This is done thanks to the catalog_xmin associated with the logicalreplication slot.But, with logical decoding on standby, in the following cases:- hot_standby_feedback is off- hot_standby_feedback is on but there is no a physical slot between the primary and the standby. Then, hot_standby_feedback will work, but only while the connection is alive (for example a node restart would break it)Then, the primary may delete system catalog rows that could be neededby the logical decoding on the standby (as it does not know about thecatalog_xmin on the standby).So, it’s mandatory to identify those rows and invalidate the slotsthat may need them if any. Identifying those rows is the purpose ofthis commit.Implementation:When a WAL replay on standby indicates that a catalog table tuple isto be deleted by an xid that is greater than a logical slot'scatalog_xmin, then that means the slot's catalog_xmin conflicts withthe xid, and we need to handle the conflict. While subsequent commitswill do the actual conflict handling, this commit adds a new fieldisCatalogRel in such WAL records (and a new bit set in thexl_heap_visible flags field), that is true for catalog tables, so as toarrange for conflict handling.The affected WAL records are the ones that already contain thesnapshotConflictHorizon field, namely:- gistxlogDelete- gistxlogPageReuse- xl_hash_vacuum_one_page- xl_heap_prune- xl_heap_freeze_page- xl_heap_visible- xl_btree_reuse_page- xl_btree_delete- spgxlogVacuumRedirectDue to this new field being added, xl_hash_vacuum_one_page andgistxlogDelete do now contain the offsets to be deleted as aFLEXIBLE_ARRAY_MEMBER. This is needed to ensure correct alignment.It's not needed on the others struct where isCatalogRel hasbeen added.This commit just introduces the WAL format changes mentioned above. Handlingthe actual conflicts will follow in future commits.Bumps XLOG_PAGE_MAGIC as the several WAL records are changed.Author: "Drouvot, Bertrand" <bertranddrouvot.pg@gmail.com>Author: Andres Freund <andres@anarazel.de> (in an older version)Author: Amit Khandekar <amitdkhan.pg@gmail.com> (in an older version)Reviewed-by: "Drouvot, Bertrand" <bertranddrouvot.pg@gmail.com>Reviewed-by: Andres Freund <andres@anarazel.de>Reviewed-by: Robert Haas <robertmhaas@gmail.com>Reviewed-by: Fabrízio de Royes Mello <fabriziomello@gmail.com>Reviewed-by: Melanie Plageman <melanieplageman@gmail.com>1 parentab73291 commit6af1793
File tree
15 files changed
+61
-29
lines changed- src
- backend/access
- gist
- hash
- heap
- nbtree
- spgist
- include
- access
- utils
15 files changed
+61
-29
lines changedLines changed: 4 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
177 | 177 |
| |
178 | 178 |
| |
179 | 179 |
| |
| 180 | + | |
180 | 181 |
| |
181 | 182 |
| |
182 | 183 |
| |
| |||
203 | 204 |
| |
204 | 205 |
| |
205 | 206 |
| |
206 |
| - | |
207 |
| - | |
208 |
| - | |
209 |
| - | |
210 |
| - | |
211 |
| - | |
212 |
| - | |
213 |
| - | |
| 207 | + | |
214 | 208 |
| |
215 | 209 |
| |
216 | 210 |
| |
| |||
609 | 603 |
| |
610 | 604 |
| |
611 | 605 |
| |
| 606 | + | |
612 | 607 |
| |
613 | 608 |
| |
614 | 609 |
| |
| |||
678 | 673 |
| |
679 | 674 |
| |
680 | 675 |
| |
| 676 | + | |
681 | 677 |
| |
682 | 678 |
| |
683 | 679 |
| |
|
Lines changed: 3 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
980 | 980 |
| |
981 | 981 |
| |
982 | 982 |
| |
| 983 | + | |
983 | 984 |
| |
984 | 985 |
| |
| 986 | + | |
985 | 987 |
| |
986 | 988 |
| |
987 | 989 |
| |
| |||
1010 | 1012 |
| |
1011 | 1013 |
| |
1012 | 1014 |
| |
1013 |
| - | |
1014 |
| - | |
1015 |
| - | |
1016 |
| - | |
1017 |
| - | |
1018 |
| - | |
1019 |
| - | |
1020 |
| - | |
| 1015 | + | |
1021 | 1016 |
| |
1022 | 1017 |
| |
1023 | 1018 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
432 | 432 |
| |
433 | 433 |
| |
434 | 434 |
| |
| 435 | + | |
435 | 436 |
| |
436 | 437 |
| |
437 | 438 |
| |
|
Lines changed: 10 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
6698 | 6698 |
| |
6699 | 6699 |
| |
6700 | 6700 |
| |
| 6701 | + | |
6701 | 6702 |
| |
6702 | 6703 |
| |
6703 | 6704 |
| |
| |||
8280 | 8281 |
| |
8281 | 8282 |
| |
8282 | 8283 |
| |
| 8284 | + | |
| 8285 | + | |
8283 | 8286 |
| |
8284 | 8287 |
| |
8285 | 8288 |
| |
| |||
8870 | 8873 |
| |
8871 | 8874 |
| |
8872 | 8875 |
| |
| 8876 | + | |
| 8877 | + | |
8873 | 8878 |
| |
8874 | 8879 |
| |
8875 | 8880 |
| |
| |||
8956 | 8961 |
| |
8957 | 8962 |
| |
8958 | 8963 |
| |
| 8964 | + | |
8959 | 8965 |
| |
8960 | 8966 |
| |
8961 | 8967 |
| |
8962 | 8968 |
| |
8963 | 8969 |
| |
| 8970 | + | |
| 8971 | + | |
| 8972 | + | |
8964 | 8973 |
| |
8965 | 8974 |
| |
8966 | 8975 |
| |
| |||
8971 | 8980 |
| |
8972 | 8981 |
| |
8973 | 8982 |
| |
8974 |
| - | |
| 8983 | + | |
8975 | 8984 |
| |
8976 | 8985 |
| |
8977 | 8986 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
418 | 418 |
| |
419 | 419 |
| |
420 | 420 |
| |
| 421 | + | |
421 | 422 |
| |
422 | 423 |
| |
423 | 424 |
| |
|
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
836 | 836 |
| |
837 | 837 |
| |
838 | 838 |
| |
| 839 | + | |
839 | 840 |
| |
840 | 841 |
| |
841 | 842 |
| |
| |||
1358 | 1359 |
| |
1359 | 1360 |
| |
1360 | 1361 |
| |
| 1362 | + | |
1361 | 1363 |
| |
1362 | 1364 |
| |
1363 | 1365 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
503 | 503 |
| |
504 | 504 |
| |
505 | 505 |
| |
| 506 | + | |
506 | 507 |
| |
507 | 508 |
| |
508 | 509 |
| |
|
Lines changed: 8 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
51 | 51 |
| |
52 | 52 |
| |
53 | 53 |
| |
| 54 | + | |
| 55 | + | |
54 | 56 |
| |
55 |
| - | |
| 57 | + | |
| 58 | + | |
56 | 59 |
| |
57 | 60 |
| |
58 |
| - | |
| 61 | + | |
59 | 62 |
| |
60 | 63 |
| |
61 | 64 |
| |
| |||
98 | 101 |
| |
99 | 102 |
| |
100 | 103 |
| |
| 104 | + | |
| 105 | + | |
101 | 106 |
| |
102 | 107 |
| |
103 |
| - | |
| 108 | + | |
104 | 109 |
| |
105 | 110 |
| |
106 | 111 |
| |
|
Lines changed: 6 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
251 | 251 |
| |
252 | 252 |
| |
253 | 253 |
| |
254 |
| - | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
255 | 257 |
| |
256 |
| - | |
| 258 | + | |
| 259 | + | |
257 | 260 |
| |
258 | 261 |
| |
259 |
| - | |
260 |
| - | |
| 262 | + | |
261 | 263 |
| |
262 | 264 |
| |
263 | 265 |
| |
|
Lines changed: 6 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
245 | 245 |
| |
246 | 246 |
| |
247 | 247 |
| |
| 248 | + | |
| 249 | + | |
248 | 250 |
| |
249 | 251 |
| |
250 | 252 |
| |
251 |
| - | |
| 253 | + | |
252 | 254 |
| |
253 | 255 |
| |
254 | 256 |
| |
| |||
344 | 346 |
| |
345 | 347 |
| |
346 | 348 |
| |
| 349 | + | |
| 350 | + | |
347 | 351 |
| |
348 | 352 |
| |
349 | 353 |
| |
350 | 354 |
| |
351 | 355 |
| |
352 | 356 |
| |
353 |
| - | |
| 357 | + | |
354 | 358 |
| |
355 | 359 |
| |
356 | 360 |
| |
|
Lines changed: 6 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
188 | 188 |
| |
189 | 189 |
| |
190 | 190 |
| |
| 191 | + | |
| 192 | + | |
191 | 193 |
| |
192 | 194 |
| |
193 |
| - | |
| 195 | + | |
194 | 196 |
| |
195 | 197 |
| |
196 | 198 |
| |
| |||
235 | 237 |
| |
236 | 238 |
| |
237 | 239 |
| |
| 240 | + | |
| 241 | + | |
238 | 242 |
| |
239 | 243 |
| |
240 | 244 |
| |
| |||
245 | 249 |
| |
246 | 250 |
| |
247 | 251 |
| |
248 |
| - | |
| 252 | + | |
249 | 253 |
| |
250 | 254 |
| |
251 | 255 |
| |
|
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
240 | 240 |
| |
241 | 241 |
| |
242 | 242 |
| |
| 243 | + | |
| 244 | + | |
243 | 245 |
| |
244 | 246 |
| |
245 | 247 |
| |
|
Lines changed: 9 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
21 | 21 |
| |
22 | 22 |
| |
23 | 23 |
| |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
24 | 33 |
| |
25 | 34 |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
31 | 31 |
| |
32 | 32 |
| |
33 | 33 |
| |
34 |
| - | |
| 34 | + | |
35 | 35 |
| |
36 | 36 |
| |
37 | 37 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
16 | 16 |
| |
17 | 17 |
| |
18 | 18 |
| |
| 19 | + | |
19 | 20 |
| |
20 | 21 |
| |
21 | 22 |
| |
|
0 commit comments
Comments
(0)