diff options
author | Robert Haas <rhaas@postgresql.org> | 2016-02-07 10:16:13 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2016-02-07 10:16:13 -0500 |
commit | a1c1af2a1f6099c039f145c1edb52257f315be51 (patch) | |
tree | 1cb89288ec139185a57ddda01ea53abf5df0c28a /src/backend/access/transam/parallel.c | |
parent | aa2387e2fd532954e88dfd8546ab894b9305123d (diff) | |
download | postgresql-a1c1af2a1f6099c039f145c1edb52257f315be51.tar.gz postgresql-a1c1af2a1f6099c039f145c1edb52257f315be51.zip |
Introduce group locking to prevent parallel processes from deadlocking.
For locking purposes, we now regard heavyweight locks as mutually
non-conflicting between cooperating parallel processes. There are some
possible pitfalls to this approach that are not to be taken lightly,
but it works OK for now and can be changed later if we find a better
approach. Without this, it's very easy for parallel queries to
silently self-deadlock if the user backend holds strong relation locks.
Robert Haas, with help from Amit Kapila. Thanks to Noah Misch and
Andres Freund for extensive discussion of possible issues with this
approach.
Diffstat (limited to 'src/backend/access/transam/parallel.c')
-rw-r--r-- | src/backend/access/transam/parallel.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c index 8eea092fb46..bf2e691f577 100644 --- a/src/backend/access/transam/parallel.c +++ b/src/backend/access/transam/parallel.c @@ -432,6 +432,9 @@ LaunchParallelWorkers(ParallelContext *pcxt) if (pcxt->nworkers == 0) return; + /* We need to be a lock group leader. */ + BecomeLockGroupLeader(); + /* If we do have workers, we'd better have a DSM segment. */ Assert(pcxt->seg != NULL); @@ -952,6 +955,19 @@ ParallelWorkerMain(Datum main_arg) */ /* + * Join locking group. We must do this before anything that could try + * to acquire a heavyweight lock, because any heavyweight locks acquired + * to this point could block either directly against the parallel group + * leader or against some process which in turn waits for a lock that + * conflicts with the parallel group leader, causing an undetected + * deadlock. (If we can't join the lock group, the leader has gone away, + * so just exit quietly.) + */ + if (!BecomeLockGroupMember(fps->parallel_master_pgproc, + fps->parallel_master_pid)) + return; + + /* * Load libraries that were loaded by original backend. We want to do * this before restoring GUCs, because the libraries might define custom * variables. |