mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
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.
This commit is contained in:
@ -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);
|
||||
|
||||
@ -951,6 +954,19 @@ ParallelWorkerMain(Datum main_arg)
|
||||
* backend-local state to match the original backend.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
Reference in New Issue
Block a user