forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commite24615a
committed
Fix visibility check when XID is committed in CLOG but not in procarray.
TransactionIdIsInProgress had a fast path to return 'false' if thesingle-item CLOG cache said that the transaction was known to becommitted. However, that was wrong, because a transaction is firstmarked as committed in the CLOG but doesn't become visible to othersuntil it has removed its XID from the proc array. That could lead to anerror: ERROR: t_xmin is uncommitted in tuple to be updatedor for an UPDATE to go ahead without blocking, before the previousUPDATE on the same row was made visible.The window is usually very short, but synchronous replication makes itmuch wider, because the wait for synchronous replica happens in thatwindow.Another thing that makes it hard to hit is that it's hard to get sucha commit-in-progress transaction into the single item CLOG cache.Normally, if you call TransactionIdIsInProgress on such a transaction,it determines that the XID is in progress without checking the CLOGand without populating the cache. One way to prime the cache is toexplicitly call pg_xact_status() on the XID. Another way is to use alot of subtransactions, so that the subxid cache in the proc array isoverflown, making TransactionIdIsInProgress rely on pg_subtrans andCLOG checks.This has been broken ever since it was introduced in 2008, but the racecondition is very hard to hit, especially without synchronousreplication. There were a couple of reports of the error starting fromsummer 2021, but no one was able to find the root cause then.TransactionIdIsKnownCompleted() is now unused. In 'master', remove it,but I left it in place in backbranches in case it's used by extensions.Also change pg_xact_status() to check TransactionIdIsInProgress().Previously, it only checked the CLOG, and returned "committed" beforethe transaction was actually made visible to other queries. Note thatthis also means that you cannot use pg_xact_status() to reproduce thebug anymore, even if the code wasn't fixed.Report and analysis by Konstantin Knizhnik. Patch by Simon Riggs, withthe pg_xact_status() change added by me.Author: Simon RiggsReviewed-by: Andres FreundDiscussion:https://www.postgresql.org/message-id/flat/4da7913d-398c-e2ad-d777-f752cf7f0bbb%40garret.ru1 parent99504ff commite24615a
File tree
3 files changed
+32
-23
lines changed- src/backend
- access/transam
- storage/ipc
- utils/adt
3 files changed
+32
-23
lines changedLines changed: 9 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
226 | 226 |
| |
227 | 227 |
| |
228 | 228 |
| |
229 |
| - | |
230 |
| - | |
231 |
| - | |
232 |
| - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
233 | 238 |
| |
234 | 239 |
| |
235 | 240 |
| |
|
Lines changed: 11 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
262 | 262 |
| |
263 | 263 |
| |
264 | 264 |
| |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
265 | 270 |
| |
266 | 271 |
| |
267 | 272 |
| |
| |||
1404 | 1409 |
| |
1405 | 1410 |
| |
1406 | 1411 |
| |
1407 |
| - | |
| 1412 | + | |
1408 | 1413 |
| |
1409 | 1414 |
| |
1410 | 1415 |
| |
| |||
1562 | 1567 |
| |
1563 | 1568 |
| |
1564 | 1569 |
| |
| 1570 | + | |
1565 | 1571 |
| |
1566 | 1572 |
| |
1567 | 1573 |
| |
| |||
1576 | 1582 |
| |
1577 | 1583 |
| |
1578 | 1584 |
| |
| 1585 | + | |
| 1586 | + | |
1579 | 1587 |
| |
| 1588 | + | |
1580 | 1589 |
| |
1581 | 1590 |
| |
1582 | 1591 |
| |
| |||
1594 | 1603 |
| |
1595 | 1604 |
| |
1596 | 1605 |
| |
| 1606 | + | |
1597 | 1607 |
| |
1598 | 1608 |
| |
1599 | 1609 |
| |
|
Lines changed: 12 additions & 18 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
36 | 36 |
| |
37 | 37 |
| |
38 | 38 |
| |
| 39 | + | |
39 | 40 |
| |
40 | 41 |
| |
41 | 42 |
| |
| |||
677 | 678 |
| |
678 | 679 |
| |
679 | 680 |
| |
680 |
| - | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
681 | 690 |
| |
682 | 691 |
| |
683 | 692 |
| |
684 |
| - | |
685 |
| - | |
686 | 693 |
| |
687 | 694 |
| |
688 |
| - | |
689 |
| - | |
690 |
| - | |
691 |
| - | |
692 |
| - | |
693 |
| - | |
694 |
| - | |
695 |
| - | |
696 |
| - | |
697 |
| - | |
698 |
| - | |
699 |
| - | |
700 |
| - | |
701 |
| - | |
702 |
| - | |
| 695 | + | |
| 696 | + | |
703 | 697 |
| |
704 | 698 |
| |
705 | 699 |
| |
|
0 commit comments
Comments
(0)