forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit118e99c
committed
Fix low-probability loss of NOTIFY messages due to XID wraparound.
Up to now async.c has used TransactionIdIsInProgress() to detect whethera notify message's source transaction is still running. However, thatfunction has a quick-exit path that reports that XIDs before RecentXminare no longer running. If a listening backend is doing nothing butlistening, and not running any queries, there is nothing that will advanceits value of RecentXmin. Once 2 billion transactions elapse, theRecentXmin check causes active transactions to be reported as not running.If they aren't committed yet according to CLOG, async.c decides theyaborted and discards their messages. The timing for that is a bit tightbut it can happen when multiple backends are sending notifies concurrently.The net symptom therefore is that a sufficiently-long-survivinglisten-only backend starts to miss some fraction of NOTIFY traffic,but only under heavy load.The only function that updates RecentXmin is GetSnapshotData().A brute-force fix would therefore be to take a snapshot beforeprocessing incoming notify messages. But that would add cycles,as well as contention for the ProcArrayLock. We can be smarter:having taken the snapshot, let's use that to check for runningXIDs, and not call TransactionIdIsInProgress() at all. In thisway we reduce the number of ProcArrayLock acquisitions from oneper message to one per notify interrupt; that's the same underlight load but should be a benefit under heavy load. Light testingsays that this change is a wash performance-wise for normal loads.I looked around for other callers of TransactionIdIsInProgress()that might be at similar risk, and didn't find any; all of themare inside transactions that presumably have already taken asnapshot.Problem report and diagnosis by Marko Tiikkaja, patch by me.Back-patch to all supported branches, since it's been like thissince 9.0.Discussion:https://postgr.es/m/20170926182935.14128.65278@wrigleys.postgresql.org1 parent46912d9 commit118e99c
3 files changed
+33
-15
lines changedLines changed: 29 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
137 | 137 |
| |
138 | 138 |
| |
139 | 139 |
| |
| 140 | + | |
140 | 141 |
| |
| 142 | + | |
141 | 143 |
| |
142 | 144 |
| |
143 | 145 |
| |
| |||
387 | 389 |
| |
388 | 390 |
| |
389 | 391 |
| |
390 |
| - | |
| 392 | + | |
| 393 | + | |
391 | 394 |
| |
392 | 395 |
| |
393 | 396 |
| |
| |||
798 | 801 |
| |
799 | 802 |
| |
800 | 803 |
| |
801 |
| - | |
| 804 | + | |
802 | 805 |
| |
803 | 806 |
| |
804 | 807 |
| |
| |||
987 | 990 |
| |
988 | 991 |
| |
989 | 992 |
| |
990 |
| - | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
991 | 996 |
| |
992 | 997 |
| |
993 | 998 |
| |
| |||
1744 | 1749 |
| |
1745 | 1750 |
| |
1746 | 1751 |
| |
| 1752 | + | |
1747 | 1753 |
| |
1748 | 1754 |
| |
1749 | 1755 |
| |
| |||
1767 | 1773 |
| |
1768 | 1774 |
| |
1769 | 1775 |
| |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
1770 | 1779 |
| |
1771 | 1780 |
| |
1772 | 1781 |
| |
| |||
1854 | 1863 |
| |
1855 | 1864 |
| |
1856 | 1865 |
| |
1857 |
| - | |
| 1866 | + | |
| 1867 | + | |
1858 | 1868 |
| |
1859 | 1869 |
| |
1860 | 1870 |
| |
| |||
1882 | 1892 |
| |
1883 | 1893 |
| |
1884 | 1894 |
| |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
1885 | 1898 |
| |
1886 | 1899 |
| |
1887 | 1900 |
| |
| |||
1903 | 1916 |
| |
1904 | 1917 |
| |
1905 | 1918 |
| |
1906 |
| - | |
| 1919 | + | |
| 1920 | + | |
1907 | 1921 |
| |
1908 | 1922 |
| |
1909 | 1923 |
| |
| |||
1928 | 1942 |
| |
1929 | 1943 |
| |
1930 | 1944 |
| |
1931 |
| - | |
| 1945 | + | |
1932 | 1946 |
| |
1933 | 1947 |
| |
1934 | 1948 |
| |
| |||
1939 | 1953 |
| |
1940 | 1954 |
| |
1941 | 1955 |
| |
1942 |
| - | |
1943 |
| - | |
1944 |
| - | |
1945 |
| - | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
1946 | 1965 |
| |
1947 | 1966 |
| |
1948 | 1967 |
| |
|
Lines changed: 3 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
81 | 81 |
| |
82 | 82 |
| |
83 | 83 |
| |
84 |
| - | |
85 |
| - | |
86 | 84 |
| |
87 | 85 |
| |
88 | 86 |
| |
| |||
1479 | 1477 |
| |
1480 | 1478 |
| |
1481 | 1479 |
| |
1482 |
| - | |
1483 |
| - | |
| 1480 | + | |
| 1481 | + | |
1484 | 1482 |
| |
1485 |
| - | |
| 1483 | + | |
1486 | 1484 |
| |
1487 | 1485 |
| |
1488 | 1486 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
78 | 78 |
| |
79 | 79 |
| |
80 | 80 |
| |
| 81 | + | |
81 | 82 |
| |
82 | 83 |
| |
83 | 84 |
| |
|
0 commit comments
Comments
(0)