Skip to content

Commit 2e2351b

Browse files
committed
Handle lack of DSM slots in parallel btree build, take 2.
Commit 74618e7 added a new check intended to fix a bug, but put it in the wrong place so that parallel btree build was always disabled. Do the check after we've actually tried to create a DSM segment. Back-patch to 11, like the earlier commit. Reviewed-by: Peter Geoghegan Discussion: https://postgr.es/m/CAH2-WzmDABkJzrNnvf%2BOULK-_A_j9gkYg_Dz-H62jzNv4eKQTw%40mail.gmail.com
1 parent 9a85860 commit 2e2351b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/backend/access/nbtree/nbtsort.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,14 +1353,6 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
13531353
pcxt = CreateParallelContext("postgres", "_bt_parallel_build_main",
13541354
request);
13551355

1356-
/* If no DSM segment was available, back out (do serial build) */
1357-
if (pcxt->seg == NULL)
1358-
{
1359-
DestroyParallelContext(pcxt);
1360-
ExitParallelMode();
1361-
return;
1362-
}
1363-
13641356
scantuplesortstates = leaderparticipates ? request + 1 : request;
13651357

13661358
/*
@@ -1404,6 +1396,16 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
14041396
/* Everyone's had a chance to ask for space, so now create the DSM */
14051397
InitializeParallelDSM(pcxt);
14061398

1399+
/* If no DSM segment was available, back out (do serial build) */
1400+
if (pcxt->seg == NULL)
1401+
{
1402+
if (IsMVCCSnapshot(snapshot))
1403+
UnregisterSnapshot(snapshot);
1404+
DestroyParallelContext(pcxt);
1405+
ExitParallelMode();
1406+
return;
1407+
}
1408+
14071409
/* Store shared build state, for which we reserved space */
14081410
btshared = (BTShared *) shm_toc_allocate(pcxt->toc, estbtshared);
14091411
/* Initialize immutable state */

0 commit comments

Comments
 (0)