- Notifications
You must be signed in to change notification settings - Fork5.3k
Commiteba917d
committed
Fix bug where we truncated CLOG that was still needed by LISTEN/NOTIFY
The async notification queue contains the XID of the sender, and whenprocessing notifications we call TransactionIdDidCommit() on theXID. But we had no safeguards to prevent the CLOG segments containingthose XIDs from being truncated away. As a result, if a backend didn'tfor some reason process its notifications for a long time, or when anew backend issued LISTEN, you could get an error like:test=# listen c21;ERROR: 58P01: could not access status of transaction 14279685DETAIL: Could not open file "pg_xact/000D": No such file or directory.LOCATION: SlruReportIOError, slru.c:1087To fix, make VACUUM "freeze" the XIDs in the async notification queuebefore truncating the CLOG. Old XIDs are replaced withFrozenTransactionId or InvalidTransactionId.Note: This commit is not a full fix. A race condition remains, where abackend is executing asyncQueueReadAllNotifications() and has justmade a local copy of an async SLRU page which contains old XIDs, whilevacuum concurrently truncates the CLOG covering those XIDs. When thebackend then calls TransactionIdDidCommit() on those XIDs from thelocal copy, you still get the error. The next commit will fix thatremaining race condition.This was first reported by Sergey Zhuravlev in 2021, with many otherpeople hitting the same issue later. Thanks to:- Alexandra Wang, Daniil Davydov, Andrei Varashen and Jacques Combrink for investigating and providing reproducable test cases,- Matheus Alcantara and Arseniy Mukhin for review and earlier proposed patches to fix this,- Álvaro Herrera and Masahiko Sawada for reviews,- Yura Sokolov aka funny-falcon for the idea of marking transactions as committed in the notification queue, and- Joel Jacobson for the final patch version. I hope I didn't forget anyone.Backpatch to all supported versions. I believe the bug goes back allthe way to commitd1e0272, which introduced the SLRU-based asyncnotification queue.Discussion:https://www.postgresql.org/message-id/16961-25f29f95b3604a8a@postgresql.orgDiscussion:https://www.postgresql.org/message-id/18804-bccbbde5e77a68c2@postgresql.orgDiscussion:https://www.postgresql.org/message-id/CAK98qZ3wZLE-RZJN_Y%2BTFjiTRPPFPBwNBpBi5K5CU8hUHkzDpw@mail.gmail.comBackpatch-through: 141 parent7cb05dd commiteba917d
3 files changed
+121
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2244 | 2244 | | |
2245 | 2245 | | |
2246 | 2246 | | |
| 2247 | + | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
| 2279 | + | |
| 2280 | + | |
| 2281 | + | |
| 2282 | + | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
| 2286 | + | |
| 2287 | + | |
| 2288 | + | |
| 2289 | + | |
| 2290 | + | |
| 2291 | + | |
| 2292 | + | |
| 2293 | + | |
| 2294 | + | |
| 2295 | + | |
| 2296 | + | |
| 2297 | + | |
| 2298 | + | |
| 2299 | + | |
| 2300 | + | |
| 2301 | + | |
| 2302 | + | |
| 2303 | + | |
| 2304 | + | |
| 2305 | + | |
| 2306 | + | |
| 2307 | + | |
| 2308 | + | |
| 2309 | + | |
| 2310 | + | |
| 2311 | + | |
| 2312 | + | |
| 2313 | + | |
| 2314 | + | |
| 2315 | + | |
| 2316 | + | |
| 2317 | + | |
| 2318 | + | |
| 2319 | + | |
| 2320 | + | |
| 2321 | + | |
| 2322 | + | |
| 2323 | + | |
| 2324 | + | |
| 2325 | + | |
| 2326 | + | |
| 2327 | + | |
| 2328 | + | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
| 2346 | + | |
| 2347 | + | |
| 2348 | + | |
| 2349 | + | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
2247 | 2358 | | |
2248 | 2359 | | |
2249 | 2360 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
1788 | 1789 | | |
1789 | 1790 | | |
1790 | 1791 | | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
1791 | 1798 | | |
1792 | 1799 | | |
1793 | 1800 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
54 | 57 | | |
0 commit comments
Comments
(0)