forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit3bbf668
committed
Fix multiple problems in WAL replay.
Most of the replay functions for WAL record types that modify more thanone page failed to ensure that those pages were locked correctly to ensurethat concurrent queries could not see inconsistent page states. This isa hangover from coding decisions made long before Hot Standby was added,when it was hardly necessary to acquire buffer locks during WAL replayat all, let alone hold them for carefully-chosen periods.The key problem was that RestoreBkpBlocks was written to hold lock on eachpage restored from a full-page image for only as long as it took to updatethat page. This was guaranteed to break any WAL replay function in whichthere was any update-ordering constraint between pages, because even if thenominal order of the pages is the right one, any mixture of full-page andnon-full-page updates in the same record would result in out-of-orderupdates. Moreover, it wouldn't work for situations where there's arequirement to maintain lock on one page while updating another. Failureto honor an update ordering constraint in this way is thought to be thecause of bug #7648 from Daniel Farina: what seems to have happened thereis that a btree page being split was rewritten from a full-page imagebefore the new right sibling page was written, and because lock on theoriginal page was not maintained it was possible for hot standby queries totry to traverse the page's right-link to the not-yet-existing sibling page.To fix, get rid of RestoreBkpBlocks as such, and instead create a newfunction RestoreBackupBlock that restores just one full-page image at atime. This function can be invoked by WAL replay functions at the pointswhere they would otherwise perform non-full-page updates; in this way, thephysical order of page updates remains the same no matter which pages arereplaced by full-page images. We can then further adjust the logic inindividual replay functions if it is necessary to hold buffer locksfor overlapping periods. A side benefit is that we can simplify thehandling of concurrency conflict resolution by moving that code into therecord-type-specfic functions; there's no more need to contort the codelayout to keep conflict resolution in front of the RestoreBkpBlocks call.In connection with that, standardize on zero-based numbering rather thanone-based numbering for referencing the full-page images. In HEAD, Iremoved the macros XLR_BKP_BLOCK_1 through XLR_BKP_BLOCK_4. They arestill there in the header files in previous branches, but are no longerused by the code.In addition, fix some other bugs identified in the course of making thesechanges:spgRedoAddNode could fail to update the parent downlink at all, if theparent tuple is in the same page as either the old or new split tuple andwe're not doing a full-page image: it would get fooled by the LSN havingbeen advanced already. This would result in permanent index corruption,not just transient failure of concurrent queries.Also, ginHeapTupleFastInsert's "merge lists" case failed to mark the oldtail page as a candidate for a full-page image; in the worst case thiscould result in torn-page corruption.heap_xlog_freeze() was inconsistent about using a cleanup lock or plainexclusive lock: it did the former in the normal path but the latter for afull-page image. A plain exclusive lock seems sufficient, so change tothat.Also, remove gistRedoPageDeleteRecord(), which has been dead code sinceVACUUM FULL was rewritten.Back-patch to 9.0, where hot standby was introduced. Note however that 9.0had a significantly different WAL-logging scheme for GIST index updates,and it doesn't appear possible to make that scheme safe for concurrent hotstandby queries, because it can leave inconsistent states in the index evenbetween WAL records. Given the lack of complaints from the field, we won'twork too hard on fixing that branch.1 parent9b3ac49 commit3bbf668
File tree
10 files changed
+753
-464
lines changed- src
- backend/access
- gin
- gist
- heap
- nbtree
- spgist
- transam
- include/access
10 files changed
+753
-464
lines changedLines changed: 9 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
290 | 290 |
| |
291 | 291 |
| |
292 | 292 |
| |
293 |
| - | |
| 293 | + | |
294 | 294 |
| |
295 | 295 |
| |
296 | 296 |
| |
| |||
313 | 313 |
| |
314 | 314 |
| |
315 | 315 |
| |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
316 | 324 |
| |
317 | 325 |
| |
318 | 326 |
| |
|
Lines changed: 85 additions & 36 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
77 | 77 |
| |
78 | 78 |
| |
79 | 79 |
| |
| 80 | + | |
| 81 | + | |
| 82 | + | |
80 | 83 |
| |
81 | 84 |
| |
82 | 85 |
| |
| |||
109 | 112 |
| |
110 | 113 |
| |
111 | 114 |
| |
| 115 | + | |
| 116 | + | |
| 117 | + | |
112 | 118 |
| |
113 | 119 |
| |
114 | 120 |
| |
| |||
159 | 165 |
| |
160 | 166 |
| |
161 | 167 |
| |
162 |
| - | |
163 |
| - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
164 | 172 |
| |
| 173 | + | |
165 | 174 |
| |
166 | 175 |
| |
167 | 176 |
| |
| |||
256 | 265 |
| |
257 | 266 |
| |
258 | 267 |
| |
| 268 | + | |
| 269 | + | |
| 270 | + | |
259 | 271 |
| |
260 | 272 |
| |
261 | 273 |
| |
| |||
369 | 381 |
| |
370 | 382 |
| |
371 | 383 |
| |
372 |
| - | |
373 |
| - | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
374 | 388 |
| |
| 389 | + | |
375 | 390 |
| |
376 | 391 |
| |
377 | 392 |
| |
| |||
420 | 435 |
| |
421 | 436 |
| |
422 | 437 |
| |
423 |
| - | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
424 | 441 |
| |
425 | 442 |
| |
426 |
| - | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
427 | 446 |
| |
428 |
| - | |
429 |
| - | |
| 447 | + | |
| 448 | + | |
430 | 449 |
| |
431 |
| - | |
| 450 | + | |
432 | 451 |
| |
433 | 452 |
| |
434 | 453 |
| |
435 | 454 |
| |
436 | 455 |
| |
437 | 456 |
| |
438 |
| - | |
| 457 | + | |
439 | 458 |
| |
440 |
| - | |
441 | 459 |
| |
442 | 460 |
| |
443 | 461 |
| |
444 |
| - | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
445 | 465 |
| |
446 |
| - | |
447 |
| - | |
| 466 | + | |
| 467 | + | |
448 | 468 |
| |
449 |
| - | |
| 469 | + | |
450 | 470 |
| |
451 | 471 |
| |
452 | 472 |
| |
453 | 473 |
| |
454 | 474 |
| |
455 | 475 |
| |
456 | 476 |
| |
457 |
| - | |
| 477 | + | |
458 | 478 |
| |
459 |
| - | |
460 | 479 |
| |
461 | 480 |
| |
462 | 481 |
| |
463 |
| - | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
464 | 485 |
| |
465 |
| - | |
466 |
| - | |
| 486 | + | |
| 487 | + | |
467 | 488 |
| |
468 |
| - | |
| 489 | + | |
469 | 490 |
| |
470 | 491 |
| |
471 | 492 |
| |
472 | 493 |
| |
473 | 494 |
| |
474 | 495 |
| |
475 |
| - | |
| 496 | + | |
476 | 497 |
| |
477 |
| - | |
| 498 | + | |
478 | 499 |
| |
479 | 500 |
| |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
480 | 506 |
| |
481 | 507 |
| |
482 | 508 |
| |
| |||
505 | 531 |
| |
506 | 532 |
| |
507 | 533 |
| |
508 |
| - | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
509 | 537 |
| |
510 | 538 |
| |
511 | 539 |
| |
| |||
553 | 581 |
| |
554 | 582 |
| |
555 | 583 |
| |
556 |
| - | |
557 |
| - | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
558 | 587 |
| |
559 |
| - | |
560 |
| - | |
561 |
| - | |
| 588 | + | |
| 589 | + | |
562 | 590 |
| |
563 |
| - | |
| 591 | + | |
564 | 592 |
| |
565 |
| - | |
566 |
| - | |
567 |
| - | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
568 | 602 |
| |
569 |
| - | |
570 | 603 |
| |
571 | 604 |
| |
572 | 605 |
| |
| |||
585 | 618 |
| |
586 | 619 |
| |
587 | 620 |
| |
588 |
| - | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
589 | 625 |
| |
| 626 | + | |
590 | 627 |
| |
591 | 628 |
| |
592 | 629 |
| |
| |||
632 | 669 |
| |
633 | 670 |
| |
634 | 671 |
| |
| 672 | + | |
| 673 | + | |
| 674 | + | |
635 | 675 |
| |
636 | 676 |
| |
637 | 677 |
| |
| |||
645 | 685 |
| |
646 | 686 |
| |
647 | 687 |
| |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
648 | 698 |
| |
649 | 699 |
| |
650 | 700 |
| |
| |||
678 | 728 |
| |
679 | 729 |
| |
680 | 730 |
| |
681 |
| - | |
682 | 731 |
| |
683 | 732 |
| |
684 | 733 |
| |
|
0 commit comments
Comments
(0)