Re: race condition in pg_class
Noah Misch <noah@leadboat.com>
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Replace tests of ALTER DATABASE RESET TABLESPACE.
- 4adb0380b9bf 19 (unreleased) landed
-
meson: Flush stdout in testwrap
- d9bc60705274 16.9 landed
- 9de86e367a67 17.5 landed
- 5941946d0934 18.0 landed
-
Fix catcache invalidation of a list entry that's being built
- af8cd1639ab2 18.0 cited
-
Stop reading uninitialized memory in heap_inplace_lock().
- a0c0078b1355 12.21 landed
- ad24b7565910 14.14 landed
- 3e5ea478d875 13.17 landed
- d34ffbaa1029 15.9 landed
- 2d63c964f010 16.5 landed
- e11907682846 17.1 landed
- e947224cbbce 18.0 landed
-
Fix use of uninitialized value in previous commit.
- 0cf3d41cbb42 15.9 landed
- 90f5412a9a51 16.5 landed
-
Back-patch "Refactor code in tablecmds.c to check and process tablespace moves"
- dc845383cd12 12.21 landed
- 1299564cb9c7 13.17 landed
-
Fix data loss at inplace update after heap_update().
- 7354b680ab64 12.21 landed
- a8ad1929d2ec 13.17 landed
- 8590c942c1a6 15.9 landed
- 82c2d9e02206 14.14 landed
- 63f01980560a 16.5 landed
- fd27b878c2ea 17.1 landed
- a07e03fd8fa7 18.0 landed
-
For inplace update durability, make heap_update() callers wait.
- cafcc3ad0ed3 12.21 landed
- 14c57cb63907 13.17 landed
- f51b34b3eddb 14.14 landed
- 5c837f8fa022 15.9 landed
- 51ff46de29f6 16.5 landed
- 3b7a689e1a80 17.1 landed
- aac2c9b4fde8 18.0 landed
-
Warn if LOCKTAG_TUPLE is held at commit, under debug_assertions.
- b779d37a3db2 12.21 landed
- 5ef9b4a2f796 13.17 landed
- c9de1b8ac8df 14.14 landed
- 41e0ba33d5ab 15.9 landed
- acc63ef4fbe6 16.5 landed
- f33bf1c7d501 17.1 landed
- dbf3f974ee04 18.0 landed
-
Don't lose partitioned table reltuples=0 after relhassubclass=f.
- e81deeefcac2 16.4 landed
- 2b4a2a79edd2 15.8 landed
- 2b415e95a8a7 14.13 landed
- f5bb46fb2e65 17.0 landed
- 7102070329d8 18.0 landed
-
Fix new assertion for MERGE view_name ... DO NOTHING.
- 0d3b35c367c2 17.0 landed
- d5e6891502ca 18.0 landed
-
Remove configuration-dependent output from new inplace-inval test.
- 79567599cd21 12.20 landed
- f31c1e34bc80 14.13 landed
- ca30e8ba958a 13.16 landed
- 7857c8dc4481 16.4 landed
- 458fada72b32 15.8 landed
- b99414de9052 17.0 landed
-
AccessExclusiveLock new relations just after assigning the OID.
- 7af775bbae57 12.20 landed
- e038b7756df8 14.13 landed
- b899cde0b86a 13.16 landed
- 0f2835ea6fc1 15.8 landed
- fc8c25806e84 16.4 landed
- 5b823b179e5e 17.0 landed
-
Cope with inplace update making catcache stale during TOAST fetch.
- 7a21306aee0a 13.16 landed
- 11f3815d6af8 12.20 landed
- af73e37fa181 14.13 landed
- b08a4b6163eb 15.8 landed
- e4afd7153bd8 16.4 landed
- f9f47f0d93d1 17.0 landed
-
Expand comments and add an assertion in nodeModifyTable.c.
- fea47de3016a 12.20 landed
- c3437fb7255b 13.16 landed
- ad4653268c12 14.13 landed
- f0544432c3cc 15.8 landed
- f8135d8b54ff 16.4 landed
- d5f788b41dc2 17.0 landed
-
Improve test coverage for changes to inplace-updated catalogs.
- 796d191028bb 12.20 landed
- 65aae93c456a 13.16 landed
- 2d06bdbc0cc3 14.13 landed
- 3c6becd3d180 15.8 landed
- dd8008e8ec95 16.4 landed
- 0844b3968985 17.0 landed
-
Lock before setting relhassubclass on RELKIND_PARTITIONED_INDEX.
- e2eefb97e31a 12.20 landed
- 1a6d65b64e84 13.16 landed
- 578db9c9257d 14.13 landed
- a338e41374e4 15.8 landed
- 480b58fabd35 16.4 landed
- 0cecc908e974 17.0 landed
-
Lock owned sequences during ALTER TABLE SET { LOGGED | UNLOGGED }.
- 24561b498f11 15.8 landed
- 112d055706bf 16.4 landed
- f88cdb36c457 17.0 landed
-
Make TAP todo_start effects the same under Meson and prove_check.
- 288426902ee5 16.4 landed
- 22a4b104ba70 17.0 landed
-
Add an injection_points isolation test suite.
- c35f419d6efb 17.0 landed
-
Add wait event type "InjectionPoint", a custom type like "Extension".
- bb93640a681c 17.0 landed
-
Create waitfuncs.c for pg_isolation_test_session_is_blocked().
- abfbd13af0e9 17.0 landed
-
Rework planning and execution of UPDATE and DELETE.
- 86dc90056dfd 14.0 cited
Attachments
- inplace005-UNEXPECTEDPASS-tap-meson-v1.patch (text/plain) patch v1
- inplace010-tests-v1.patch (text/plain) patch v1
- inplace040-waitfuncs-v1.patch (text/plain) patch v1
- inplace050-tests-inj-v1.patch (text/plain) patch v1
- inplace060-nodeModifyTable-comments-v1.patch (text/plain) patch v1
- inplace070-rel-locks-missing-v1.patch (text/plain) patch v1
- inplace080-catcache-detoast-inplace-stale-v1.patch (text/plain) patch v1
- inplace090-LOCKTAG_TUPLE-eoxact-v1.patch (text/plain) patch v1
- inplace110-successors-v1.patch (text/plain) patch v1
- inplace120-locktag-v1.patch (text/plain) patch v1
I'm attaching patches implementing the LockTuple() design. It turns out we don't just lose inplace updates. We also overwrite unrelated tuples, reproduced at inplace.spec. Good starting points are README.tuplock and the heap_inplace_update_scan() header comment. On Wed, Nov 01, 2023 at 08:09:15PM -0700, Noah Misch wrote: > On Fri, Oct 27, 2023 at 04:26:12PM -0700, Noah Misch wrote: > > On Fri, Oct 27, 2023 at 06:40:55PM -0400, Tom Lane wrote: > > > We could perhaps make this work by using the existing tuple-lock > > > infrastructure, rather than inventing new locktags (a choice that > > > spills to a lot of places including clients that examine pg_locks). > > > I'd also like to find a solution that fixes the case of a conflicting > > > manual UPDATE (although certainly that's a stretch goal we may not be > > > able to reach). I implemented that; search for ri_needLockTagTuple. > - GRANT passes to heapam the fixed-size portion of the pre-modification tuple. > heap_update() compares those bytes to the oldtup in shared buffers to see if > an inplace update happened. (HEAD could get the bytes from a new > heap_update() parameter, while back branches would need a different passing > approach.) This could have been fine, but ... > - LockTuple(), as seen in its attached prototype. I like this least at the > moment, because it changes pg_locks content without having a clear advantage > over the previous option. ... I settled on the LockTuple() design for these reasons: - Solves more conflicts by waiting, instead of by ERROR or by retry loops. - Extensions wanting inplace updates don't have a big disadvantage over core code inplace updates. - One could use this to stop "tuple concurrently updated" for pg_class rows, by using SearchSysCacheLocked1() for all pg_class DDL and making that function wait for any existing xmax like inplace_xmax_lock() does. I don't expect to write that, but it's a nice option to have. - pg_locks shows the new lock acquisitions. Separable, nontrivial things not fixed in the attached patch stack: - Inplace update uses transactional CacheInvalidateHeapTuple(). ROLLBACK of CREATE INDEX wrongly discards the inval, leading to the relhasindex=t loss still seen in inplace-inval.spec. CacheInvalidateRelmap() does this right. - AtEOXact_Inval(true) is outside the RecordTransactionCommit() critical section, but it is critical. We must not commit transactional DDL without other backends receiving an inval. (When the inplace inval becomes nontransactional, it will face the same threat.) - Trouble is possible, I bet, if the system crashes between the inplace-update memcpy() and XLogInsert(). See the new XXX comment below the memcpy(). Might solve this by inplace update setting DELAY_CHKPT, writing WAL, and finally issuing memcpy() into the buffer. - [consequences limited to transient failure] Since a PROC_IN_VACUUM backend's xmin does not stop pruning, an MVCC scan in that backend can find zero tuples when one is live. This is like what all backends got in the days of SnapshotNow catalog scans. See the pgbench test suite addition. (Perhaps the fix is to make VACUUM do its MVCC scans outside of PROC_IN_VACUUM, setting that flag later and unsetting it earlier.) If you find decisions in this thread's patches are tied to any of those such that I should not separate those, let's discuss that. Topics in the patches that I feel are most fruitful for debate: - This makes inplace update block if the tuple has an updater. It's like one GRANT blocking another, except an inplace updater won't get "ERROR: tuple concurrently updated" like one of the GRANTs would. I had implemented versions that avoided this blocking by mutating each tuple in the updated tuple chain. That worked, but it had corner cases bad for maintainability, listed in the inplace_xmax_lock() header comment. I'd rather accept the blocking, so hackers can rule out those corner cases. A long-running GRANT already hurts VACUUM progress more just by keeping an XID running. - Pre-checks could make heap_inplace_update_cancel() calls rarer. Avoiding one of those avoids an exclusive buffer lock, and it avoids waiting on concurrent heap_update() if any. We'd pre-check the syscache tuple. EventTriggerOnLogin() does it that way, because the code was already in that form. I expect only vac_update_datfrozenxid() concludes !dirty enough to matter. I didn't bother with the optimization, but it would be simple. - If any citus extension user feels like porting its heap_inplace_update() call to this, I'd value hearing about your experience. - I paid more than my usual attention to test coverage, considering the patch stack's intensity compared to most back-patch bug fixes. I've kept all the above topics brief; feel free to ask for more details. Thanks, nm