forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitcf4401f
committed
Fix race condition in COMMIT PREPARED causing orphaned 2PC files
COMMIT PREPARED removes on-disk 2PC files near its end, but the statechecked if a file is on-disk or not gets read from shared memory whilenot holding the two-phase state lock.Because of that, there was a small window where a second backend doing aPREPARE TRANSACTION could reuse the GlobalTransaction put back into the2PC free list by the COMMIT PREPARED, overwriting the "ondisk" flag readafterwards by the COMMIT PREPARED to decide if its on-disk two-phasestate file should be removed, preventing the file deletion.This commit fixes this issue so as the "ondisk" flag in theGlobalTransaction is read while holding the two-phase state lock, notfrom shared memory after its entry has been added to the free list.Orphaned two-phase state files flushed to disk after a checkpoint arediscarded at the beginning of recovery. However, a truncation ofpg_xact/ would make the startup process issue a FATAL when it cannotread the SLRU page holding the state of the transaction whose 2PC filewas orphaned, which is a necessary step to decide if the 2PC file shouldbe removed or not. Removing manually the file would be necessary inthis case.Issue introduced byeffe7d9, so backpatch all the way down.Mea culpa.Author: wuchengwenDiscussion:https://postgr.es/m/tencent_A7F059B5136A359625C7B2E4A386B3C3F007@qq.comBackpatch-through: 121 parent3b1a377 commitcf4401f
1 file changed
+8
-1
lines changedLines changed: 8 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1505 | 1505 |
| |
1506 | 1506 |
| |
1507 | 1507 |
| |
| 1508 | + | |
1508 | 1509 |
| |
1509 | 1510 |
| |
1510 | 1511 |
| |
| |||
1657 | 1658 |
| |
1658 | 1659 |
| |
1659 | 1660 |
| |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
1660 | 1667 |
| |
1661 | 1668 |
| |
1662 | 1669 |
| |
| |||
1672 | 1679 |
| |
1673 | 1680 |
| |
1674 | 1681 |
| |
1675 |
| - | |
| 1682 | + | |
1676 | 1683 |
| |
1677 | 1684 |
| |
1678 | 1685 |
| |
|
0 commit comments
Comments
(0)