- Notifications
You must be signed in to change notification settings - Fork5
Commit2ad36c4
committed
Improve table locking behavior in the face of current DDL.
In the previous coding, callers were faced with an awkward choice:look up the name, do permissions checks, and then lock the table; orlook up the name, lock the table, and then do permissions checks.The first choice was wrong because the results of the name lookupand permissions checks might be out-of-date by the time the tablelock was acquired, while the second allowed a user with no privilegesto interfere with access to a table by users who do have privileges(e.g. if a malicious backend queues up for an AccessExclusiveLock ona table on which AccessShareLock is already held, further attemptsto access the table will be blocked until the AccessExclusiveLockis obtained and the malicious backend's transaction rolls back).To fix, allow callers of RangeVarGetRelid() to pass a callback whichgets executed after performing the name lookup but before acquiringthe relation lock. If the name lookup is retried (becauseinvalidation messages are received), the callback will be re-executedas well, so we get the best of both worlds. RangeVarGetRelid() isrenamed to RangeVarGetRelidExtended(); callers not wishing to supplya callback can continue to invoke it as RangeVarGetRelid(), which isnow a macro. Since the only one caller that uses nowait = true nowpasses a callback anyway, the RangeVarGetRelid() macro defaults nowaitas well. The callback can also be used for supplemental locking - forexample, REINDEX INDEX needs to acquire the table lock before the indexlock to reduce deadlock possibilities.There's a lot more work to be done here to fix all the cases where thiscan be a problem, but this commit provides the general infrastructureand fixes the following specific cases: REINDEX INDEX, REINDEX TABLE,LOCK TABLE, and and DROP TABLE/INDEX/SEQUENCE/VIEW/FOREIGN TABLE.Per discussion with Noah Misch and Alvaro Herrera.1 parenta87ebac commit2ad36c4
File tree
21 files changed
+339
-199
lines changed- src
- backend
- access/heap
- catalog
- commands
- parser
- rewrite
- tcop
- utils/adt
- include/catalog
- pl/plpgsql/src
21 files changed
+339
-199
lines changedLines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
979 | 979 |
| |
980 | 980 |
| |
981 | 981 |
| |
982 |
| - | |
| 982 | + | |
983 | 983 |
| |
984 | 984 |
| |
985 | 985 |
| |
| |||
1001 | 1001 |
| |
1002 | 1002 |
| |
1003 | 1003 |
| |
1004 |
| - | |
| 1004 | + | |
1005 | 1005 |
| |
1006 | 1006 |
| |
1007 | 1007 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
606 | 606 |
| |
607 | 607 |
| |
608 | 608 |
| |
609 |
| - | |
| 609 | + | |
610 | 610 |
| |
611 | 611 |
| |
612 | 612 |
| |
|
Lines changed: 8 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
111 | 111 |
| |
112 | 112 |
| |
113 | 113 |
| |
114 |
| - | |
115 | 114 |
| |
116 | 115 |
| |
117 | 116 |
| |
| |||
1301 | 1300 |
| |
1302 | 1301 |
| |
1303 | 1302 |
| |
1304 |
| - | |
| 1303 | + | |
1305 | 1304 |
| |
1306 | 1305 |
| |
1307 | 1306 |
| |
| |||
2763 | 2762 |
| |
2764 | 2763 |
| |
2765 | 2764 |
| |
2766 |
| - | |
2767 |
| - | |
| 2765 | + | |
| 2766 | + | |
2768 | 2767 |
| |
2769 | 2768 |
| |
2770 | 2769 |
| |
2771 | 2770 |
| |
2772 | 2771 |
| |
2773 | 2772 |
| |
2774 | 2773 |
| |
| 2774 | + | |
| 2775 | + | |
| 2776 | + | |
2775 | 2777 |
| |
| 2778 | + | |
2776 | 2779 |
| |
2777 | 2780 |
| |
2778 | 2781 |
| |
| |||
2800 | 2803 |
| |
2801 | 2804 |
| |
2802 | 2805 |
| |
2803 |
| - | |
| 2806 | + | |
2804 | 2807 |
| |
2805 | 2808 |
| |
2806 | 2809 |
| |
|
Lines changed: 19 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
219 | 219 |
| |
220 | 220 |
| |
221 | 221 |
| |
| 222 | + | |
| 223 | + | |
| 224 | + | |
222 | 225 |
| |
223 | 226 |
| |
224 |
| - | |
225 |
| - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
226 | 230 |
| |
227 | 231 |
| |
228 | 232 |
| |
| |||
308 | 312 |
| |
309 | 313 |
| |
310 | 314 |
| |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
311 | 328 |
| |
312 | 329 |
| |
313 | 330 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
111 | 111 |
| |
112 | 112 |
| |
113 | 113 |
| |
114 |
| - | |
| 114 | + | |
115 | 115 |
| |
116 | 116 |
| |
117 | 117 |
| |
|
Lines changed: 97 additions & 39 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
63 | 63 |
| |
64 | 64 |
| |
65 | 65 |
| |
66 |
| - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
67 | 70 |
| |
68 | 71 |
| |
69 | 72 |
| |
| |||
129 | 132 |
| |
130 | 133 |
| |
131 | 134 |
| |
132 |
| - | |
| 135 | + | |
133 | 136 |
| |
134 | 137 |
| |
135 | 138 |
| |
| |||
1725 | 1728 |
| |
1726 | 1729 |
| |
1727 | 1730 |
| |
1728 |
| - | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
1729 | 1753 |
| |
1730 | 1754 |
| |
1731 |
| - | |
1732 |
| - | |
1733 |
| - | |
1734 |
| - | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
1735 | 1758 |
| |
1736 |
| - | |
1737 |
| - | |
1738 |
| - | |
1739 |
| - | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
1740 | 1769 |
| |
1741 |
| - | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
1742 | 1779 |
| |
1743 | 1780 |
| |
1744 |
| - | |
1745 |
| - | |
| 1781 | + | |
1746 | 1782 |
| |
1747 | 1783 |
| |
1748 |
| - | |
1749 |
| - | |
1750 |
| - | |
1751 |
| - | |
1752 |
| - | |
| 1784 | + | |
| 1785 | + | |
1753 | 1786 |
| |
1754 |
| - | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
1755 | 1799 |
| |
1756 | 1800 |
| |
1757 | 1801 |
| |
| |||
1762 | 1806 |
| |
1763 | 1807 |
| |
1764 | 1808 |
| |
1765 |
| - | |
1766 | 1809 |
| |
1767 | 1810 |
| |
1768 |
| - | |
1769 |
| - | |
1770 |
| - | |
1771 |
| - | |
1772 |
| - | |
1773 |
| - | |
1774 |
| - | |
1775 |
| - | |
1776 |
| - | |
1777 |
| - | |
1778 |
| - | |
1779 |
| - | |
1780 |
| - | |
1781 |
| - | |
1782 |
| - | |
1783 |
| - | |
1784 |
| - | |
1785 |
| - | |
| 1811 | + | |
| 1812 | + | |
1786 | 1813 |
| |
1787 | 1814 |
| |
1788 | 1815 |
| |
1789 | 1816 |
| |
1790 | 1817 |
| |
1791 | 1818 |
| |
1792 | 1819 |
| |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
1793 | 1851 |
| |
1794 | 1852 |
| |
1795 | 1853 |
| |
|
0 commit comments
Comments
(0)