pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Handle lack of DSM slots in parallel btree build.
13+ messages / 3 participants
[nested] [flat]

* pgsql: Handle lack of DSM slots in parallel btree build.
@ 2020-01-30 22:34  Thomas Munro <tmunro@postgresql.org>
  0 siblings, 1 reply; 13+ messages in thread

From: Thomas Munro @ 2020-01-30 22:34 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Handle lack of DSM slots in parallel btree build.

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/74618e77b43cfce670b4725d5b9a300a2afd12d1

Modified Files
--------------
src/backend/access/nbtree/nbtsort.c | 9 +++++++++
1 file changed, 9 insertions(+)



^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* pgsql: Handle lack of DSM slots in parallel btree build.
@ 2020-01-30 22:34  Thomas Munro <tmunro@postgresql.org>
  0 siblings, 0 replies; 13+ messages in thread

From: Thomas Munro @ 2020-01-30 22:34 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Handle lack of DSM slots in parallel btree build.

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

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/1fcf62e0b837c1b814a86f3abf92ad4d36ca30e6

Modified Files
--------------
src/backend/access/nbtree/nbtsort.c | 9 +++++++++
1 file changed, 9 insertions(+)



^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* pgsql: Handle lack of DSM slots in parallel btree build.
@ 2020-01-30 22:34  Thomas Munro <tmunro@postgresql.org>
  0 siblings, 0 replies; 13+ messages in thread

From: Thomas Munro @ 2020-01-30 22:34 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Handle lack of DSM slots in parallel btree build.

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

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2c56b3ac436db2d24aa11bdd22f45becf2030607

Modified Files
--------------
src/backend/access/nbtree/nbtsort.c | 9 +++++++++
1 file changed, 9 insertions(+)



^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* Re: pgsql: Handle lack of DSM slots in parallel btree build.
@ 2020-02-03 20:12  Peter Geoghegan <pg@bowt.ie>
  parent: Thomas Munro <tmunro@postgresql.org>
  0 siblings, 1 reply; 13+ messages in thread

From: Peter Geoghegan @ 2020-02-03 20:12 UTC (permalink / raw)
  To: Thomas Munro <tmunro@postgresql.org>; +Cc: pgsql-committers <pgsql-committers@lists.postgresql.org>

On Thu, Jan 30, 2020 at 2:34 PM Thomas Munro <tmunro@postgresql.org> wrote:
> Handle lack of DSM slots in parallel btree build.
>
> 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.

Uh, this seems to have completely disabled parallel index builds on
the master branch.

-- 
Peter Geoghegan





^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* Re: pgsql: Handle lack of DSM slots in parallel btree build.
@ 2020-02-03 21:03  Thomas Munro <thomas.munro@gmail.com>
  parent: Peter Geoghegan <pg@bowt.ie>
  0 siblings, 1 reply; 13+ messages in thread

From: Thomas Munro @ 2020-02-03 21:03 UTC (permalink / raw)
  To: Peter Geoghegan <pg@bowt.ie>; +Cc: Thomas Munro <tmunro@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>

Hi Peter,

On Tue, Feb 4, 2020 at 9:13 AM Peter Geoghegan <pg@bowt.ie> wrote:
> On Thu, Jan 30, 2020 at 2:34 PM Thomas Munro <tmunro@postgresql.org> wrote:
> > Handle lack of DSM slots in parallel btree build.
> >
> > 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.
>
> Uh, this seems to have completely disabled parallel index builds on
> the master branch.

Oops.  The check needs to move down below InitializeParallelDSM(), and
release any extra resources that might have been acquired (snapshot?).
I will do some testing in a few hours and post a fix.





^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* Re: pgsql: Handle lack of DSM slots in parallel btree build.
@ 2020-02-04 10:17  Thomas Munro <thomas.munro@gmail.com>
  parent: Thomas Munro <thomas.munro@gmail.com>
  0 siblings, 1 reply; 13+ messages in thread

From: Thomas Munro @ 2020-02-04 10:17 UTC (permalink / raw)
  To: Peter Geoghegan <pg@bowt.ie>; +Cc: Thomas Munro <tmunro@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>

On Tue, Feb 4, 2020 at 10:03 AM Thomas Munro <thomas.munro@gmail.com> wrote:
> On Tue, Feb 4, 2020 at 9:13 AM Peter Geoghegan <pg@bowt.ie> wrote:
> > Uh, this seems to have completely disabled parallel index builds on
> > the master branch.
>
> Oops.  The check needs to move down below InitializeParallelDSM(), and
> release any extra resources that might have been acquired (snapshot?).
> I will do some testing in a few hours and post a fix.

Here is take 2.  I tested CI and CIC, and verified that workers are
started or not depending on dsm_create() failure, using the attached
fault injector patch.  (Fuzzing the regression tests repeatedly with
that applied also revealed similar problems elsewhere in the tree,
which I'll write about in a new thread.)

Attachments: download all (2 files, .tar.gz)

0001-Handle-lack-of-DSM-slots-in-parallel-btree-build-tak.patch (application/octet-stream, 1.9K) download From 4c1f89d0c866001740642ef77a69a33b318db430 Mon Sep 17 00:00:00 2001 From: Thomas Munro <thomas.munro@gmail.com> Date: Tue, 4 Feb 2020 18:20:07 +1300 Subject: [PATCH 1/2] Handle lack of DSM slots in parallel btree build, take 2. Commit 74618e77 added a new check intended to fix a bug, but put it in the wrong place so that parallel btree build was always disabled. Only do that after we've actually tried to create a DSM segment. Back-patch to 11, like the earlier commit. Discussion: https://postgr.es/m/CAH2-WzmDABkJzrNnvf%2BOULK-_A_j9gkYg_Dz-H62jzNv4eKQTw%40mail.gmail.com --- src/backend/access/nbtree/nbtsort.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c index e6be7bba59..baec5de999 100644 --- a/src/backend/access/nbtree/nbtsort.c +++ b/src/backend/access/nbtree/nbtsort.c @@ -1332,14 +1332,6 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request) 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; /* @@ -1383,6 +1375,16 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request) /* Everyone's had a chance to ask for space, so now create the DSM */ InitializeParallelDSM(pcxt); + /* If no DSM segment was available, back out (do serial build) */ + if (pcxt->seg == NULL) + { + if (IsMVCCSnapshot(snapshot)) + UnregisterSnapshot(snapshot); + DestroyParallelContext(pcxt); + ExitParallelMode(); + return; + } + /* Store shared build state, for which we reserved space */ btshared = (BTShared *) shm_toc_allocate(pcxt->toc, estbtshared); /* Initialize immutable state */ -- 2.23.0
0002-Inject-random-faults-into-dsm_create.patch (application/octet-stream, 856B) download From e6e14bb78ae75284cc93bbc128437a084cb67fa3 Mon Sep 17 00:00:00 2001 From: Thomas Munro <thomas.munro@gmail.com> Date: Tue, 4 Feb 2020 18:20:20 +1300 Subject: [PATCH 2/2] Inject random faults into dsm_create(). Testing patch, not for commit. --- src/backend/storage/ipc/dsm.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/backend/storage/ipc/dsm.c b/src/backend/storage/ipc/dsm.c index ef64d08357..6220acc79d 100644 --- a/src/backend/storage/ipc/dsm.c +++ b/src/backend/storage/ipc/dsm.c @@ -463,6 +463,13 @@ dsm_create(Size size, int flags) nitems = dsm_control->nitems; for (i = 0; i < nitems; ++i) { + /* BEGIN HACK */ + if (random() % 10 > 5) + { + nitems = dsm_control->maxitems; + break; + } + /* END HACK */ if (dsm_control->item[i].refcnt == 0) { dsm_control->item[i].handle = seg->handle; -- 2.23.0
^ permalink raw reply [nested|flat] 13+ messages in thread

* Re: pgsql: Handle lack of DSM slots in parallel btree build.
@ 2020-02-04 17:42  Peter Geoghegan <pg@bowt.ie>
  parent: Thomas Munro <thomas.munro@gmail.com>
  0 siblings, 1 reply; 13+ messages in thread

From: Peter Geoghegan @ 2020-02-04 17:42 UTC (permalink / raw)
  To: Thomas Munro <thomas.munro@gmail.com>; +Cc: Thomas Munro <tmunro@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>

On Tue, Feb 4, 2020 at 2:18 AM Thomas Munro <thomas.munro@gmail.com> wrote:
> Here is take 2.  I tested CI and CIC, and verified that workers are
> started or not depending on dsm_create() failure, using the attached
> fault injector patch.  (Fuzzing the regression tests repeatedly with
> that applied also revealed similar problems elsewhere in the tree,
> which I'll write about in a new thread.)

Can we reuse _bt_end_parallel() this time around? It would be easy to
add a "bool wait" argument to _bt_end_parallel(). All existing callers
would pass true, but when not using parallelism due to the new DSM
segment check we'd pass false.

-- 
Peter Geoghegan





^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* Re: pgsql: Handle lack of DSM slots in parallel btree build.
@ 2020-02-04 17:47  Peter Geoghegan <pg@bowt.ie>
  parent: Peter Geoghegan <pg@bowt.ie>
  0 siblings, 1 reply; 13+ messages in thread

From: Peter Geoghegan @ 2020-02-04 17:47 UTC (permalink / raw)
  To: Thomas Munro <thomas.munro@gmail.com>; +Cc: Thomas Munro <tmunro@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>

On Tue, Feb 4, 2020 at 9:42 AM Peter Geoghegan <pg@bowt.ie> wrote:
> Can we reuse _bt_end_parallel() this time around? It would be easy to
> add a "bool wait" argument to _bt_end_parallel(). All existing callers
> would pass true, but when not using parallelism due to the new DSM
> segment check we'd pass false.

Hmm. I see why you didn't do it that way -- we don't quite have the
variables set up in the way that _bt_end_parallel() expects them.

This looks good, then.

-- 
Peter Geoghegan





^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* pgsql: Handle lack of DSM slots in parallel btree build, take 2.
@ 2020-02-04 23:35  Thomas Munro <tmunro@postgresql.org>
  0 siblings, 0 replies; 13+ messages in thread

From: Thomas Munro @ 2020-02-04 23:35 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Handle lack of DSM slots in parallel btree build, take 2.

Commit 74618e77 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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d9fe702a2c9843af71419ad0df069859e5581694

Modified Files
--------------
src/backend/access/nbtree/nbtsort.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)



^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* pgsql: Handle lack of DSM slots in parallel btree build, take 2.
@ 2020-02-04 23:36  Thomas Munro <tmunro@postgresql.org>
  0 siblings, 0 replies; 13+ messages in thread

From: Thomas Munro @ 2020-02-04 23:36 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Handle lack of DSM slots in parallel btree build, take 2.

Commit 74618e77 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

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2e2351bd6c45a77b6462bf73102b5735a4e21379

Modified Files
--------------
src/backend/access/nbtree/nbtsort.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)



^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* pgsql: Handle lack of DSM slots in parallel btree build, take 2.
@ 2020-02-04 23:36  Thomas Munro <tmunro@postgresql.org>
  0 siblings, 0 replies; 13+ messages in thread

From: Thomas Munro @ 2020-02-04 23:36 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Handle lack of DSM slots in parallel btree build, take 2.

Commit 74618e77 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

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/c4a2041a43c92c566c42c7ae8029868be317f8d9

Modified Files
--------------
src/backend/access/nbtree/nbtsort.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)



^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* Re: pgsql: Handle lack of DSM slots in parallel btree build.
@ 2020-02-04 23:37  Thomas Munro <thomas.munro@gmail.com>
  parent: Peter Geoghegan <pg@bowt.ie>
  0 siblings, 1 reply; 13+ messages in thread

From: Thomas Munro @ 2020-02-04 23:37 UTC (permalink / raw)
  To: Peter Geoghegan <pg@bowt.ie>; +Cc: Thomas Munro <tmunro@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>

On Wed, Feb 5, 2020 at 6:47 AM Peter Geoghegan <pg@bowt.ie> wrote:
> On Tue, Feb 4, 2020 at 9:42 AM Peter Geoghegan <pg@bowt.ie> wrote:
> > Can we reuse _bt_end_parallel() this time around? It would be easy to
> > add a "bool wait" argument to _bt_end_parallel(). All existing callers
> > would pass true, but when not using parallelism due to the new DSM
> > segment check we'd pass false.
>
> Hmm. I see why you didn't do it that way -- we don't quite have the
> variables set up in the way that _bt_end_parallel() expects them.
>
> This looks good, then.

Thanks.  Pushed.





^ permalink  raw  reply  [nested|flat] 13+ messages in thread

* Re: pgsql: Handle lack of DSM slots in parallel btree build.
@ 2020-02-05 01:46  Peter Geoghegan <pg@bowt.ie>
  parent: Thomas Munro <thomas.munro@gmail.com>
  0 siblings, 0 replies; 13+ messages in thread

From: Peter Geoghegan @ 2020-02-05 01:46 UTC (permalink / raw)
  To: Thomas Munro <thomas.munro@gmail.com>; +Cc: Thomas Munro <tmunro@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>

On Tue, Feb 4, 2020 at 3:38 PM Thomas Munro <thomas.munro@gmail.com> wrote:
> Thanks.  Pushed.

Thanks.

-- 
Peter Geoghegan





^ permalink  raw  reply  [nested|flat] 13+ messages in thread


end of thread, other threads:[~2020-02-05 01:46 UTC | newest]

Thread overview: 13+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-01-30 22:34 pgsql: Handle lack of DSM slots in parallel btree build. Thomas Munro <tmunro@postgresql.org>
2020-02-03 20:12 ` Peter Geoghegan <pg@bowt.ie>
2020-02-03 21:03   ` Thomas Munro <thomas.munro@gmail.com>
2020-02-04 10:17     ` Thomas Munro <thomas.munro@gmail.com>
2020-02-04 17:42       ` Peter Geoghegan <pg@bowt.ie>
2020-02-04 17:47         ` Peter Geoghegan <pg@bowt.ie>
2020-02-04 23:37           ` Thomas Munro <thomas.munro@gmail.com>
2020-02-05 01:46             ` Peter Geoghegan <pg@bowt.ie>
2020-01-30 22:34 pgsql: Handle lack of DSM slots in parallel btree build. Thomas Munro <tmunro@postgresql.org>
2020-01-30 22:34 pgsql: Handle lack of DSM slots in parallel btree build. Thomas Munro <tmunro@postgresql.org>
2020-02-04 23:35 pgsql: Handle lack of DSM slots in parallel btree build, take 2. Thomas Munro <tmunro@postgresql.org>
2020-02-04 23:36 pgsql: Handle lack of DSM slots in parallel btree build, take 2. Thomas Munro <tmunro@postgresql.org>
2020-02-04 23:36 pgsql: Handle lack of DSM slots in parallel btree build, take 2. Thomas Munro <tmunro@postgresql.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox