forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit74fc838
committed
Fix race between GetNewTransactionId and GetOldestActiveTransactionId.
The race condition goes like this:1. GetNewTransactionId advances nextXid e.g. from 100 to 1012. GetOldestActiveTransactionId reads the new nextXid, 1013. GetOldestActiveTransactionId loops through the proc array. There are no active XIDs there, so it returns 101 as the oldest active XID.4. GetNewTransactionid stores XID 100 to MyPgXact->xidSo, GetOldestActiveTransactionId returned XID 101, even though 100 onlyjust started and is surely still running.This would be hard to hit in practice, and even harder to spot any illeffect if it happens. GetOldestActiveTransactionId is only used whencreating a checkpoint in a master server, and the race condition can onlyhappen on an online checkpoint, as there are no backends running during ashutdown checkpoint. The oldestActiveXid value of an online checkpoint isonly used when starting up a hot standby server, to determine the startingpoint where pg_subtrans is initialized from. For the race condition tohappen, there must be no other XIDs in the proc array that would hold backthe oldest-active XID value, which means that the missed XID must be a toptransaction's XID. However, pg_subtrans is not used for top XIDs, so Ibelieve an off-by-one error is in fact inconsequential. Nevertheless, let'sfix it, as it's clearly wrong and the fix is simple.This has been wrong ever since hot standby was introduced, so backport toall supported versions.Discussion:https://www.postgresql.org/message-id/e7258662-82b6-7a45-56d4-99b337a32bf7@iki.fi1 parentbc2d716 commit74fc838
1 file changed
+8
-8
lines changedLines changed: 8 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2096 | 2096 |
| |
2097 | 2097 |
| |
2098 | 2098 |
| |
2099 |
| - | |
2100 |
| - | |
2101 | 2099 |
| |
2102 |
| - | |
2103 |
| - | |
2104 |
| - | |
2105 |
| - | |
2106 |
| - | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
2107 | 2105 |
| |
| 2106 | + | |
2108 | 2107 |
| |
| 2108 | + | |
2109 | 2109 |
| |
2110 | 2110 |
| |
2111 | 2111 |
| |
2112 | 2112 |
| |
| 2113 | + | |
2113 | 2114 |
| |
2114 | 2115 |
| |
2115 | 2116 |
| |
| |||
2131 | 2132 |
| |
2132 | 2133 |
| |
2133 | 2134 |
| |
2134 |
| - | |
2135 | 2135 |
| |
2136 | 2136 |
| |
2137 | 2137 |
| |
|
0 commit comments
Comments
(0)