Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Handle lack of DSM slots in parallel btree build.
authorThomas Munro <tmunro@postgresql.org>
Thu, 30 Jan 2020 21:25:34 +0000 (10:25 +1300)
committerThomas Munro <tmunro@postgresql.org>
Thu, 30 Jan 2020 21:27:53 +0000 (10:27 +1300)
If no DSM slots are available, a ParallelContext can still be
created, but its seg pointer is NULL.  Teach parallel btree build
to cope with that by falling back to a regular non-parallel build,
to avoid crashing with a segmentation fault.

Back-patch to 11, where parallel CREATE INDEX landed.

Reported-by: Nicola Contu
Reviewed-by: Peter Geoghegan
Discussion: https://postgr.es/m/CA%2BhUKGJgJEBnkuODBVomyK3MWFvDBbMVj%3Dgdt6DnRPU-5sQ6UQ%40mail.gmail.com

src/backend/access/nbtree/nbtsort.c

index d0b9013caf401ae9529d604e60ee735a725c1fac..0b941ae12ca441b5e75a3b6fb9a8561f21f8923c 100644 (file)
@@ -1352,6 +1352,15 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
    Assert(request > 0);
    pcxt = CreateParallelContext("postgres", "_bt_parallel_build_main",
                                 request);
+
+   /* If no DSM segment was available, back out (do serial build) */
+   if (pcxt->seg == NULL)
+   {
+       DestroyParallelContext(pcxt);
+       ExitParallelMode();
+       return;
+   }
+
    scantuplesortstates = leaderparticipates ? request + 1 : request;
 
    /*