Allocate access strategy in parallel VACUUM workers.
authorPeter Geoghegan <[email protected]>
Tue, 6 Apr 2021 00:17:40 +0000 (17:17 -0700)
committerPeter Geoghegan <[email protected]>
Tue, 6 Apr 2021 00:17:40 +0000 (17:17 -0700)
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

index 0763ed85d0c146acb70bd06ab2d56f682b8ac7e5..c259693a8ba1fa1c8b6bc8b2de81c3393205bc8a 100644 (file)
@@ -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);
 }