forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitff9f111
committed
Fix WAL replay in presence of an incomplete record
Physical replication always ships WAL segment files to replicas oncethey are complete. This is a problem if one WAL record is split acrossa segment boundary and the primary server crashes before writing downthe segment with the next portion of the WAL record: WAL writing aftercrash recovery would happily resume at the point where the broken recordstarted, overwriting that record ... but any standby or backup may havealready received a copy of that segment, and they are not rewinding.This causes standbys to stop following the primary after the lattercrashes: LOG: invalid contrecord length 7262 at A8/D9FFFBC8because the standby is still trying to read the continuation record(contrecord) for the original long WAL record, but it is not there andit will never be. A workaround is to stop the replica, delete the WALfile, and restart it -- at which point a fresh copy is brought over fromthe primary. But that's pretty labor intensive, and I bet many userswould just give up and re-clone the standby instead.A fix for this problem was already attempted in commit515e3d8, butit only addressed the case for the scenario of WAL archiving, sostreaming replication would still be a problem (as well as other thingssuch as taking a filesystem-level backup while the server is down afterhaving crashed), and it had performance scalability problems too; so ithad to be reverted.This commit fixes the problem using an approach suggested by AndresFreund, whereby the initial portion(s) of the split-up WAL record arekept, and a special type of WAL record is written where the contrecordwas lost, so that WAL replay in the replica knows to skip the brokenparts. With this approach, we can continue to stream/archive segmentfiles as soon as they are complete, and replay of the broken recordswill proceed across the crash point without a hitch.Because a new type of WAL record is added, users should be careful toupgrade standbys first, primaries later. Otherwise they risk the standbybeing unable to start if the primary happens to write such a record.A new TAP test that exercises this is added, but the portability of itis yet to be seen.This has been wrong since the introduction of physical replication, sobackpatch all the way back. In stable branches, keep the newXLogReaderState members at the end of the struct, to avoid an ABIbreak.Author: Álvaro Herrera <alvherre@alvh.no-ip.org>Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>Reviewed-by: Nathan Bossart <bossartn@amazon.com>Discussion:https://postgr.es/m/202108232252.dh7uxf6oxwcy@alvherre.pgsql1 parent2acb7cc commitff9f111
File tree
9 files changed
+450
-7
lines changed- src
- backend/access
- rmgrdesc
- transam
- include
- access
- catalog
- test/recovery/t
- tools/pgindent
9 files changed
+450
-7
lines changedLines changed: 12 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
139 | 139 |
| |
140 | 140 |
| |
141 | 141 |
| |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
142 | 151 |
| |
143 | 152 |
| |
144 | 153 |
| |
| |||
178 | 187 |
| |
179 | 188 |
| |
180 | 189 |
| |
| 190 | + | |
| 191 | + | |
| 192 | + | |
181 | 193 |
| |
182 | 194 |
| |
183 | 195 |
| |
|
Lines changed: 149 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
199 | 199 |
| |
200 | 200 |
| |
201 | 201 |
| |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
202 | 211 |
| |
203 | 212 |
| |
204 | 213 |
| |
| |||
892 | 901 |
| |
893 | 902 |
| |
894 | 903 |
| |
| 904 | + | |
| 905 | + | |
895 | 906 |
| |
896 | 907 |
| |
| 908 | + | |
897 | 909 |
| |
898 | 910 |
| |
899 | 911 |
| |
| |||
2246 | 2258 |
| |
2247 | 2259 |
| |
2248 | 2260 |
| |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
2249 | 2273 |
| |
2250 | 2274 |
| |
2251 | 2275 |
| |
| |||
4394 | 4418 |
| |
4395 | 4419 |
| |
4396 | 4420 |
| |
| 4421 | + | |
| 4422 | + | |
| 4423 | + | |
| 4424 | + | |
| 4425 | + | |
| 4426 | + | |
| 4427 | + | |
| 4428 | + | |
| 4429 | + | |
| 4430 | + | |
| 4431 | + | |
| 4432 | + | |
| 4433 | + | |
4397 | 4434 |
| |
4398 | 4435 |
| |
4399 | 4436 |
| |
| |||
7069 | 7106 |
| |
7070 | 7107 |
| |
7071 | 7108 |
| |
| 7109 | + | |
| 7110 | + | |
| 7111 | + | |
| 7112 | + | |
| 7113 | + | |
| 7114 | + | |
7072 | 7115 |
| |
7073 | 7116 |
| |
7074 | 7117 |
| |
| |||
7655 | 7698 |
| |
7656 | 7699 |
| |
7657 | 7700 |
| |
7658 |
| - | |
7659 |
| - | |
| 7701 | + | |
| 7702 | + | |
| 7703 | + | |
7660 | 7704 |
| |
7661 | 7705 |
| |
7662 | 7706 |
| |
| |||
7689 | 7733 |
| |
7690 | 7734 |
| |
7691 | 7735 |
| |
7692 |
| - | |
7693 |
| - | |
| 7736 | + | |
| 7737 | + | |
| 7738 | + | |
| 7739 | + | |
| 7740 | + | |
| 7741 | + | |
7694 | 7742 |
| |
7695 | 7743 |
| |
7696 | 7744 |
| |
| |||
7821 | 7869 |
| |
7822 | 7870 |
| |
7823 | 7871 |
| |
| 7872 | + | |
| 7873 | + | |
| 7874 | + | |
| 7875 | + | |
| 7876 | + | |
| 7877 | + | |
| 7878 | + | |
| 7879 | + | |
| 7880 | + | |
| 7881 | + | |
| 7882 | + | |
| 7883 | + | |
7824 | 7884 |
| |
7825 | 7885 |
| |
7826 | 7886 |
| |
| |||
7873 | 7933 |
| |
7874 | 7934 |
| |
7875 | 7935 |
| |
| 7936 | + | |
| 7937 | + | |
| 7938 | + | |
| 7939 | + | |
| 7940 | + | |
| 7941 | + | |
| 7942 | + | |
| 7943 | + | |
| 7944 | + | |
| 7945 | + | |
| 7946 | + | |
7876 | 7947 |
| |
7877 | 7948 |
| |
7878 | 7949 |
| |
7879 | 7950 |
| |
7880 | 7951 |
| |
7881 | 7952 |
| |
7882 |
| - | |
7883 | 7953 |
| |
7884 | 7954 |
| |
7885 | 7955 |
| |
| |||
9365 | 9435 |
| |
9366 | 9436 |
| |
9367 | 9437 |
| |
| 9438 | + | |
| 9439 | + | |
| 9440 | + | |
| 9441 | + | |
| 9442 | + | |
| 9443 | + | |
| 9444 | + | |
| 9445 | + | |
| 9446 | + | |
| 9447 | + | |
| 9448 | + | |
| 9449 | + | |
| 9450 | + | |
| 9451 | + | |
| 9452 | + | |
| 9453 | + | |
| 9454 | + | |
| 9455 | + | |
| 9456 | + | |
| 9457 | + | |
| 9458 | + | |
| 9459 | + | |
| 9460 | + | |
| 9461 | + | |
| 9462 | + | |
| 9463 | + | |
| 9464 | + | |
| 9465 | + | |
| 9466 | + | |
| 9467 | + | |
| 9468 | + | |
| 9469 | + | |
| 9470 | + | |
| 9471 | + | |
| 9472 | + | |
| 9473 | + | |
| 9474 | + | |
| 9475 | + | |
| 9476 | + | |
| 9477 | + | |
| 9478 | + | |
| 9479 | + | |
| 9480 | + | |
| 9481 | + | |
| 9482 | + | |
| 9483 | + | |
| 9484 | + | |
9368 | 9485 |
| |
9369 | 9486 |
| |
9370 | 9487 |
| |
| |||
10295 | 10412 |
| |
10296 | 10413 |
| |
10297 | 10414 |
| |
| 10415 | + | |
| 10416 | + | |
| 10417 | + | |
| 10418 | + | |
| 10419 | + | |
| 10420 | + | |
| 10421 | + | |
10298 | 10422 |
| |
10299 | 10423 |
| |
10300 | 10424 |
| |
| |||
10462 | 10586 |
| |
10463 | 10587 |
| |
10464 | 10588 |
| |
| 10589 | + | |
| 10590 | + | |
| 10591 | + | |
| 10592 | + | |
| 10593 | + | |
| 10594 | + | |
| 10595 | + | |
| 10596 | + | |
| 10597 | + | |
| 10598 | + | |
| 10599 | + | |
| 10600 | + | |
| 10601 | + | |
| 10602 | + | |
| 10603 | + | |
| 10604 | + | |
| 10605 | + | |
| 10606 | + | |
| 10607 | + | |
| 10608 | + | |
10465 | 10609 |
| |
10466 | 10610 |
| |
10467 | 10611 |
| |
|
Lines changed: 39 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
278 | 278 |
| |
279 | 279 |
| |
280 | 280 |
| |
| 281 | + | |
281 | 282 |
| |
282 | 283 |
| |
283 | 284 |
| |
| |||
293 | 294 |
| |
294 | 295 |
| |
295 | 296 |
| |
| 297 | + | |
| 298 | + | |
296 | 299 |
| |
297 | 300 |
| |
298 | 301 |
| |
| |||
319 | 322 |
| |
320 | 323 |
| |
321 | 324 |
| |
| 325 | + | |
322 | 326 |
| |
| 327 | + | |
323 | 328 |
| |
324 | 329 |
| |
325 | 330 |
| |
| |||
415 | 420 |
| |
416 | 421 |
| |
417 | 422 |
| |
| 423 | + | |
| 424 | + | |
418 | 425 |
| |
419 | 426 |
| |
420 | 427 |
| |
| |||
448 | 455 |
| |
449 | 456 |
| |
450 | 457 |
| |
451 |
| - | |
452 | 458 |
| |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
453 | 477 |
| |
454 | 478 |
| |
455 | 479 |
| |
| |||
551 | 575 |
| |
552 | 576 |
| |
553 | 577 |
| |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
554 | 592 |
| |
555 | 593 |
| |
556 | 594 |
| |
|
Lines changed: 10 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
76 | 76 |
| |
77 | 77 |
| |
78 | 78 |
| |
| 79 | + | |
| 80 | + | |
79 | 81 |
| |
80 |
| - | |
| 82 | + | |
81 | 83 |
| |
82 | 84 |
| |
83 | 85 |
| |
| |||
249 | 251 |
| |
250 | 252 |
| |
251 | 253 |
| |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
252 | 261 |
| |
253 | 262 |
| |
254 | 263 |
| |
|
Lines changed: 10 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
175 | 175 |
| |
176 | 176 |
| |
177 | 177 |
| |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
178 | 188 |
| |
179 | 189 |
| |
180 | 190 |
| |
|
0 commit comments
Comments
(0)