Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8cacea7

Browse files
committed
Ensure sufficient alignment for ParallelTableScanDescData in BTShared.
Previously ParallelTableScanDescData was just a member in BTShared, but after c2fe139 that doesn't guarantee sufficient alignment as specific AMs might (are likely to) need atomic variables in the struct. One might think that MAXALIGNing would be sufficient, but as a comment in shm_toc_allocate() explains, that's not enough. For now, copy the hack described there. For parallel sequential scans no such change is needed, as its allocations go through shm_toc_allocate(). An alternative approach would have been to allocate the parallel scan descriptor in a separate TOC entry, but there seems little benefit in doing so. Per buildfarm member dromedary. Author: Andres Freund Discussion: https://postgr.es/m/20190311203126.ty5gbfz42gjbm6i6@alap3.anarazel.de
1 parent c2fe139 commit 8cacea7

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/backend/access/nbtree/nbtsort.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,21 @@ typedef struct BTShared
157157
bool brokenhotchain;
158158

159159
/*
160-
* This variable-sized field must come last.
161-
*
162-
* See _bt_parallel_estimate_shared() and table_parallelscan_estimate().
160+
* ParallelTableScanDescData data follows. Can't directly embed here, as
161+
* implementations of the parallel table scan desc interface might need
162+
* stronger alignment.
163163
*/
164-
ParallelTableScanDescData heapdesc;
165164
} BTShared;
166165

166+
/*
167+
* Return pointer to a BTShared's parallel table scan.
168+
*
169+
* c.f. shm_toc_allocate as to why BUFFERALIGN is used, rather than just
170+
* MAXALIGN.
171+
*/
172+
#define ParallelTableScanFromBTShared(shared) \
173+
(ParallelTableScanDesc) ((char *) (shared) + BUFFERALIGN(sizeof(BTShared)))
174+
167175
/*
168176
* Status for leader in parallel index build.
169177
*/
@@ -1317,7 +1325,8 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
13171325
btshared->havedead = false;
13181326
btshared->indtuples = 0.0;
13191327
btshared->brokenhotchain = false;
1320-
table_parallelscan_initialize(btspool->heap, &btshared->heapdesc,
1328+
table_parallelscan_initialize(btspool->heap,
1329+
ParallelTableScanFromBTShared(btshared),
13211330
snapshot);
13221331

13231332
/*
@@ -1407,7 +1416,8 @@ _bt_end_parallel(BTLeader *btleader)
14071416
static Size
14081417
_bt_parallel_estimate_shared(Relation heap, Snapshot snapshot)
14091418
{
1410-
return add_size(offsetof(BTShared, heapdesc),
1419+
/* c.f. shm_toc_allocate as to why BUFFERALIGN is used */
1420+
return add_size(BUFFERALIGN(sizeof(BTShared)),
14111421
table_parallelscan_estimate(heap, snapshot));
14121422
}
14131423

@@ -1672,7 +1682,8 @@ _bt_parallel_scan_and_sort(BTSpool *btspool, BTSpool *btspool2,
16721682
/* Join parallel scan */
16731683
indexInfo = BuildIndexInfo(btspool->index);
16741684
indexInfo->ii_Concurrent = btshared->isconcurrent;
1675-
scan = table_beginscan_parallel(btspool->heap, &btshared->heapdesc);
1685+
scan = table_beginscan_parallel(btspool->heap,
1686+
ParallelTableScanFromBTShared(btshared));
16761687
reltuples = IndexBuildHeapScan(btspool->heap, btspool->index, indexInfo,
16771688
true, _bt_build_callback,
16781689
(void *) &buildstate, scan);

0 commit comments

Comments
 (0)