Fix up rickety handling of relation-truncation interlocks.
Tom Lane <tgl@sss.pgh.pa.us>
Fix up rickety handling of relation-truncation interlocks. Move rd_targblock, rd_fsm_nblocks, and rd_vm_nblocks from relcache to the smgr relation entries, so that they will get reset to InvalidBlockNumber whenever an smgr-level flush happens. Because we now send smgr invalidation messages immediately (not at end of transaction) when a relation truncation occurs, this ensures that other backends will reset their values before they next access the relation. We no longer need the unreliable assumption that a VACUUM that's doing a truncation will hold its AccessExclusive lock until commit --- in fact, we can intentionally release that lock as soon as we've completed the truncation. This patch therefore reverts (most of) Alvaro's patch of 2009-11-10, as well as my marginal hacking on it yesterday. We can also get rid of assorted no-longer-needed relcache flushes, which are far more expensive than an smgr flush because they kill a lot more state. In passing this patch fixes smgr_redo's failure to perform visibility-map truncation, and cleans up some rather dubious assumptions in freespace.c and visibilitymap.c about when rd_fsm_nblocks and rd_vm_nblocks can be out of date.
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/access/heap/hio.c | modified | +6 −5 |
| src/backend/access/heap/visibilitymap.c | modified | +46 −32 |
| src/backend/access/transam/xlogutils.c | modified | +1 −4 |
| src/backend/catalog/storage.c | modified | +15 −9 |
| src/backend/commands/cluster.c | modified | +4 −7 |
| src/backend/commands/sequence.c | modified | +3 −2 |
| src/backend/commands/vacuum.c | modified | +2 −8 |
| src/backend/commands/vacuumlazy.c | modified | +19 −47 |
| src/backend/executor/execMain.c | modified | +4 −3 |
| src/backend/storage/freespace/freespace.c | modified | +43 −33 |
| src/backend/storage/smgr/smgr.c | modified | +25 −18 |
| src/backend/utils/cache/relcache.c | modified | +4 −35 |
| src/include/commands/vacuum.h | modified | +2 −2 |
| src/include/storage/smgr.h | modified | +12 −1 |
| src/include/utils/rel.h | modified | +21 −10 |