Re: BUG #17255: Server crashes in index_delete_sort_cmp() due to race condition with vacuum
Peter Geoghegan <pg@bowt.ie>
From: Peter Geoghegan <pg@bowt.ie>
To: Dmitry Dolgov <9erthalion6@gmail.com>
Cc: Alexander Lakhin <exclusion@gmail.com>,
Andres Freund <andres@anarazel.de>, Matthias van de Meent <boekewurm+postgres@gmail.com>, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Date: 2021-11-10T03:07:02Z
Lists: pgsql-bugs
Attachments
- v2-0001-Fix-aborted-HOT-update-bug-in-heap-pruning.patch (application/octet-stream) patch v2-0001
On Tue, Nov 9, 2021 at 3:31 PM Peter Geoghegan <pg@bowt.ie> wrote: > Attached is a WIP fix for the bug. The idea here is to follow all HOT > chains in an initial pass over the page, while even following LIVE > heap-only tuples. Any heap-only tuples that we don't determine are > part of some valid HOT chain (following an initial pass over the whole > heap page) will now be processed in a second pass over the page. I realized that I could easily go further than in v1, and totally get rid of the "marked" array (which tracks whether we have decided to mark an item as LP_DEAD/LP_UNUSED/a new LP_REDIRECT/newly pointed to by another LP_REDIRECT). In my v1 from earlier today we already had an array that records whether or not each item is part of any known valid chain, which is strictly better than knowing whether or not they were "marked" earlier. So why bother with the "marked" array at all, even for assertions? It is less robust (not to mention less efficient) than just using the new "fromvalidchain" array. Attached is v2, which gets rid of the "marked" array as described. It also has better worked out comments and assertions. The patch has stood up to a fair amount of stress-testing. I repeated Alexander's original test case for over an hour with this. Getting the test case to cause an assertion failure would usually take about 5 minutes without any fix. I have yet to do any work on validating the performance of this patch, though that definitely needs to happen. Anybody have any thoughts on how far this should be backpatched? We'll probably need to do that for Postgres 14. Less sure about other branches, which haven't been directly demonstrated to be affected by the bug so far. Haven't tried to break earlier branches with Alexander's test case, though I will note again that Alexander couldn't do that when he tried. -- Peter Geoghegan
Commits
-
vacuumlazy.c: Standardize rel_pages terminology.
- e370f100f05d 15.0 landed
-
vacuumlazy.c: document vistest and OldestXmin.
- 73f6ec3d3c8d 15.0 landed
-
heap pruning: Only call BufferGetBlockNumber() once.
- c702d656a283 15.0 landed
-
Fix possible HOT corruption when RECENTLY_DEAD changes to DEAD while pruning.
- dad1539aec28 14.2 landed
- 18b87b201f73 15.0 landed
-
Assert redirect pointers are sensible after heap_page_prune().
- bb42bfb5ccb5 15.0 landed
-
Remove tupgone special case from vacuumlazy.c.
- 8523492d4e34 14.0 cited
-
Recycle nbtree pages deleted during same VACUUM.
- 9dd963ae2534 14.0 cited
-
snapshot scalability: Don't compute global horizons while building snapshots.
- dc7420c2c927 14.0 cited
-
Refactor heap_page_prune so that instead of changing item states on-the-fly,
- 6f10eb21118f 8.4.0 cited