- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit0c99e71
committed
Avoid duplicate XIDs at recovery when building initial snapshot
On a primary, sets of XLOG_RUNNING_XACTS records are generated on aperiodic basis to allow recovery to build the initial state oftransactions for a hot standby. The set of transaction IDs is createdby scanning all the entries in ProcArray. However it happens that itslogic never counted on the fact that two-phase transactions finishing toprepare can put ProcArray in a state where there are two entries withthe same transaction ID, one for the initial transaction which getscleared when prepare finishes, and a second, dummy, entry to track thatthe transaction is still running after prepare finishes. This wayensures a continuous presence of the transaction so as callers of forexample TransactionIdIsInProgress() are always able to see it as alive.So, if a XLOG_RUNNING_XACTS takes a standby snapshot while a two-phasetransaction finishes to prepare, the record can finish with duplicatedXIDs, which is a state expected by design. If this record gets appliedon a standby to initial its recovery state, then it would simply fail,so the odds of facing this failure are very low in practice. It wouldbe tempting to change the generation of XLOG_RUNNING_XACTS so asduplicates are removed on the source, but this requires to hold onProcArrayLock for longer and this would impact all workloads,particularly those using heavily two-phase transactions.XLOG_RUNNING_XACTS is also actually used only to initialize the standbystate at recovery, so instead the solution is taken to discardduplicates when applying the initial snapshot.Diagnosed-by: Konstantin KnizhnikAuthor: Michael PaquierDiscussion:https://postgr.es/m/0c96b653-4696-d4b4-6b5d-78143175d113@postgrespro.ruBackpatch-through: 9.31 parentfb583c8 commit0c99e71
1 file changed
+19
-2
lines changedLines changed: 19 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
651 | 651 |
| |
652 | 652 |
| |
653 | 653 |
| |
654 |
| - | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
655 | 657 |
| |
656 | 658 |
| |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
657 | 667 |
| |
| 668 | + | |
658 | 669 |
| |
659 | 670 |
| |
660 | 671 |
| |
| |||
1604 | 1615 |
| |
1605 | 1616 |
| |
1606 | 1617 |
| |
1607 |
| - | |
| 1618 | + | |
| 1619 | + | |
1608 | 1620 |
| |
1609 | 1621 |
| |
1610 | 1622 |
| |
| |||
1616 | 1628 |
| |
1617 | 1629 |
| |
1618 | 1630 |
| |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
1619 | 1636 |
| |
1620 | 1637 |
| |
1621 | 1638 |
| |
|
0 commit comments
Comments
(0)