forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit061b079
committed
Fix multiple bugs in index page locking during hot-standby WAL replay.
In ordinary operation, VACUUM must be careful to take a cleanup lock oneach leaf page of a btree index; this ensures that no indexscans couldstill be "in flight" to heap tuples due to be deleted. (Because ofpossible index-tuple motion due to concurrent page splits, it's not enoughto lock only the pages we're deleting index tuples from.) In Hot Standby,the WAL replay process must likewise lock every leaf page. There wereseveral bugs in the code for that:* The replay scan might come across unused, all-zero pages in the index.While btree_xlog_vacuum itself did the right thing (ie, nothing) withsuch pages, xlogutils.c supposed that such pages must be corrupt andwould throw an error. This accounts for various reports of replicationfailures with "PANIC: WAL contains references to invalid pages". Tofix, add a ReadBufferMode value that instructs XLogReadBufferExtendednot to complain when we're doing this.* btree_xlog_vacuum performed the extra locking if standbyState ==STANDBY_SNAPSHOT_READY, but that's not the correct test: we won't open upfor hot standby queries until the database has reached consistency, andwe don't want to do the extra locking till then either, for fear of readingcorrupted pages (which bufmgr.c would complain about). Fix by exporting anew function from xlog.c that will report whether we're actually in hotstandby replay mode.* To ensure full coverage of the index in the replay scan, btvacuumscanwould emit a dummy WAL record for the last page of the index, if novacuuming work had been done on that page. However, if the last pageof the index is all-zero, that would result in corruption of said page,since the functions called on it weren't prepared to handle that case.There's no need to lock any such pages, so change the logic to targetthe last normal leaf page instead.The first two of these bugs were diagnosed by Andres Freund, the other oneby me. Fixes based on ideas from Heikki Linnakangas and myself.This has been wrong since Hot Standby was introduced, so back-patch to 9.0.1 parent16cad3e commit061b079
7 files changed
+98
-42
lines changedLines changed: 41 additions & 28 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
56 | 56 |
| |
57 | 57 |
| |
58 | 58 |
| |
59 |
| - | |
60 |
| - | |
| 59 | + | |
| 60 | + | |
61 | 61 |
| |
62 | 62 |
| |
63 | 63 |
| |
| |||
763 | 763 |
| |
764 | 764 |
| |
765 | 765 |
| |
766 |
| - | |
| 766 | + | |
767 | 767 |
| |
768 | 768 |
| |
769 | 769 |
| |
| |||
819 | 819 |
| |
820 | 820 |
| |
821 | 821 |
| |
822 |
| - | |
823 |
| - | |
824 |
| - | |
825 |
| - | |
826 |
| - | |
827 |
| - | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
828 | 830 |
| |
829 | 831 |
| |
830 |
| - | |
| 832 | + | |
831 | 833 |
| |
832 | 834 |
| |
833 | 835 |
| |
834 | 836 |
| |
835 |
| - | |
836 |
| - | |
837 |
| - | |
838 |
| - | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
839 | 841 |
| |
840 |
| - | |
841 |
| - | |
| 842 | + | |
| 843 | + | |
842 | 844 |
| |
| 845 | + | |
843 | 846 |
| |
844 | 847 |
| |
845 | 848 |
| |
| |||
914 | 917 |
| |
915 | 918 |
| |
916 | 919 |
| |
917 |
| - | |
918 |
| - | |
919 |
| - | |
920 |
| - | |
921 | 920 |
| |
922 | 921 |
| |
923 | 922 |
| |
| |||
953 | 952 |
| |
954 | 953 |
| |
955 | 954 |
| |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
956 | 962 |
| |
957 | 963 |
| |
958 | 964 |
| |
| |||
1019 | 1025 |
| |
1020 | 1026 |
| |
1021 | 1027 |
| |
1022 |
| - | |
1023 |
| - | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
1024 | 1039 |
| |
1025 | 1040 |
| |
1026 | 1041 |
| |
1027 | 1042 |
| |
1028 |
| - | |
1029 |
| - | |
1030 |
| - | |
1031 |
| - | |
| 1043 | + | |
| 1044 | + | |
1032 | 1045 |
| |
1033 |
| - | |
1034 |
| - | |
| 1046 | + | |
| 1047 | + | |
1035 | 1048 |
| |
1036 | 1049 |
| |
1037 | 1050 |
| |
|
Lines changed: 30 additions & 11 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
482 | 482 |
| |
483 | 483 |
| |
484 | 484 |
| |
485 |
| - | |
| 485 | + | |
486 | 486 |
| |
487 |
| - | |
488 |
| - | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
489 | 504 |
| |
490 |
| - | |
491 |
| - | |
| 505 | + | |
492 | 506 |
| |
493 |
| - | |
| 507 | + | |
494 | 508 |
| |
495 |
| - | |
| 509 | + | |
496 | 510 |
| |
497 | 511 |
| |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
498 | 519 |
| |
499 | 520 |
| |
500 | 521 |
| |
501 | 522 |
| |
502 |
| - | |
503 |
| - | |
504 |
| - | |
505 | 523 |
| |
506 |
| - | |
| 524 | + | |
| 525 | + | |
507 | 526 |
| |
508 | 527 |
| |
509 | 528 |
| |
|
Lines changed: 13 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
7562 | 7562 |
| |
7563 | 7563 |
| |
7564 | 7564 |
| |
7565 |
| - | |
| 7565 | + | |
| 7566 | + | |
7566 | 7567 |
| |
7567 | 7568 |
| |
7568 | 7569 |
| |
| |||
7588 | 7589 |
| |
7589 | 7590 |
| |
7590 | 7591 |
| |
| 7592 | + | |
| 7593 | + | |
| 7594 | + | |
| 7595 | + | |
| 7596 | + | |
| 7597 | + | |
| 7598 | + | |
| 7599 | + | |
| 7600 | + | |
| 7601 | + | |
| 7602 | + | |
7591 | 7603 |
| |
7592 | 7604 |
| |
7593 | 7605 |
| |
|
Lines changed: 6 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
288 | 288 |
| |
289 | 289 |
| |
290 | 290 |
| |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
291 | 295 |
| |
292 | 296 |
| |
293 | 297 |
| |
| |||
328 | 332 |
| |
329 | 333 |
| |
330 | 334 |
| |
| 335 | + | |
| 336 | + | |
331 | 337 |
| |
332 | 338 |
| |
333 | 339 |
| |
|
Lines changed: 4 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
207 | 207 |
| |
208 | 208 |
| |
209 | 209 |
| |
210 |
| - | |
| 210 | + | |
| 211 | + | |
211 | 212 |
| |
212 | 213 |
| |
213 | 214 |
| |
| |||
221 | 222 |
| |
222 | 223 |
| |
223 | 224 |
| |
| 225 | + | |
| 226 | + | |
224 | 227 |
| |
225 | 228 |
| |
226 | 229 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
300 | 300 |
| |
301 | 301 |
| |
302 | 302 |
| |
| 303 | + | |
303 | 304 |
| |
304 | 305 |
| |
305 | 306 |
| |
|
Lines changed: 3 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
38 | 38 |
| |
39 | 39 |
| |
40 | 40 |
| |
41 |
| - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
42 | 44 |
| |
43 | 45 |
| |
44 | 46 |
| |
|
0 commit comments
Comments
(0)