forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit8a42379
committed
Fix snapshot builds during promotion of hot standby node with 2PC
Some specific logic is done at the end of recovery when involving 2PCtransactions:1) Call RecoverPreparedTransactions(), to recover the state of 2PCtransactions into memory (re-acquire locks, etc.).2) ShutdownRecoveryTransactionEnvironment(), to move back to normaloperations, mainly cleaning up recovery locks and KnownAssignedXids(including any 2PC transaction tracked previously).3) Switch XLogCtl->SharedRecoveryState to RECOVERY_STATE_DONE, which isthe tipping point for any process calling RecoveryInProgress() to checkif the cluster is still in recovery or not.Any snapshot taken between steps 2) and 3) would be empty, causing anytransaction relying on a snapshot at this point to potentially corruptdata as there could still be some 2PC transactions to track, withRecentXmin moving backwards on successive calls to GetSnapshotData() inthe same transaction.As SharedRecoveryState is the point to take into account to know if itis safe to discard KnownAssignedXids, this commit moves step 2) afterstep 3), so as we can never finish with empty snapshots.This exists since the introduction of hot standby, so backpatch all theway down. The window with incorrect snapshots is extremely small, but Ihave seen it when running 023_pitr_prepared_xact.pl, as did buildfarmmember fairywren. Thomas Munro also found it independently. Specialthanks to Andres Freund for taking the time to analyze this issue.Reported-by: Thomas Munro, Michael PaquierAnalyzed-by: Andres FreundDiscussion:https://postgr.es/m/20210422203603.fdnh3fu2mmfp2iov@alap3.anarazel.deBackpatch-through: 9.61 parenta0558cf commit8a42379
1 file changed
+12
-7
lines changedLines changed: 12 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
8111 | 8111 |
| |
8112 | 8112 |
| |
8113 | 8113 |
| |
8114 |
| - | |
8115 |
| - | |
8116 |
| - | |
8117 |
| - | |
8118 |
| - | |
8119 |
| - | |
8120 |
| - | |
8121 | 8114 |
| |
8122 | 8115 |
| |
8123 | 8116 |
| |
| |||
8165 | 8158 |
| |
8166 | 8159 |
| |
8167 | 8160 |
| |
| 8161 | + | |
| 8162 | + | |
| 8163 | + | |
| 8164 | + | |
| 8165 | + | |
| 8166 | + | |
| 8167 | + | |
| 8168 | + | |
| 8169 | + | |
| 8170 | + | |
| 8171 | + | |
| 8172 | + | |
8168 | 8173 |
| |
8169 | 8174 |
| |
8170 | 8175 |
| |
|
0 commit comments
Comments
(0)