From f6b8f19a084ce949522fcbc940dc116c034cfc47 Mon Sep 17 00:00:00 2001 From: Peter Geoghegan Date: Mon, 5 Apr 2021 17:17:40 -0700 Subject: [PATCH] Allocate access strategy in parallel VACUUM workers. Commit 49f49def took entirely the wrong approach to fixing this issue. Just allocate a local buffer access strategy in each individual worker instead of trying to propagate state. This state was never propagated by parallel VACUUM in the first place. It looks like the only reason that this worked following commit 40d964ec was that it involved static global variables, which are initialized to 0 per the C standard. A more comprehensive fix may be necessary, even on HEAD. This fix should at least get the buildfarm green once again. Thanks once again to Thomas Munro for continued off-list assistance with the issue. --- src/backend/access/heap/vacuumlazy.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index 0763ed85d0..c259693a8b 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -194,11 +194,6 @@ typedef struct LVShared Oid relid; int elevel; - /* - * Buffer access strategy from leader - */ - BufferAccessStrategy bstrategy; - /* * An indication for vacuum workers to perform either index vacuum or * index cleanup. first_time is true only if for_cleanup is true and @@ -3485,7 +3480,6 @@ begin_parallel_vacuum(LVRelState *vacrel, BlockNumber nblocks, MemSet(shared, 0, est_shared); shared->relid = RelationGetRelid(vacrel->rel); shared->elevel = elevel; - shared->bstrategy = vacrel->bstrategy; shared->maintenance_work_mem_worker = (nindexes_mwm > 0) ? maintenance_work_mem / Min(parallel_workers, nindexes_mwm) : @@ -3726,7 +3720,8 @@ parallel_vacuum_main(dsm_segment *seg, shm_toc *toc) vacrel.rel = rel; vacrel.indrels = indrels; vacrel.nindexes = nindexes; - vacrel.bstrategy = lvshared->bstrategy; + /* Each parallel VACUUM worker gets its own access strategy */ + vacrel.bstrategy = GetAccessStrategy(BAS_VACUUM); vacrel.indstats = (IndexBulkDeleteResult **) palloc0(nindexes * sizeof(IndexBulkDeleteResult *)); @@ -3765,6 +3760,7 @@ parallel_vacuum_main(dsm_segment *seg, shm_toc *toc) vac_close_indexes(nindexes, indrels, RowExclusiveLock); table_close(rel, ShareUpdateExclusiveLock); + FreeAccessStrategy(vacrel.bstrategy); pfree(vacrel.indstats); }