Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit73bf871

Browse files
committed
Remove redundant PGPROC.lockGroupLeaderIdentifier field.
We don't really need this field, because it's either zero or redundant withPGPROC.pid. The use of zero to mark "not a group leader" is not necessarysince we can just as well test whether lockGroupLeader is NULL. This doesnot save very much, either as to code or data, but the simplification seemsworthwhile anyway.
1 parentea56b06 commit73bf871

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

‎src/backend/storage/lmgr/README

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -650,27 +650,16 @@ those cases so that they no longer use heavyweight locking in the first place
650650
(which is not a crazy idea, given that such lock acquisitions are not expected
651651
to deadlock and that heavyweight lock acquisition is fairly slow anyway).
652652

653-
Group locking adds four new members to each PGPROC: lockGroupLeaderIdentifier,
654-
lockGroupLeader, lockGroupMembers, and lockGroupLink. The first is simply a
655-
safety mechanism. A newly started parallel worker has to try to join the
656-
leader's lock group, but it has no guarantee that the group leader is still
657-
alive by the time it gets started. We try to ensure that the parallel leader
658-
dies after all workers in normal cases, but also that the system could survive
659-
relatively intact if that somehow fails to happen. This is one of the
660-
precautions against such a scenario: the leader relays its PGPROC and also its
661-
PID to the worker, and the worker fails to join the lock group unless the
662-
given PGPROC still has the same PID. We assume that PIDs are not recycled
663-
quickly enough for this interlock to fail.
664-
665-
A PGPROC's lockGroupLeader is NULL for processes not involved in parallel
666-
query. When a process wants to cooperate with parallel workers, it becomes a
667-
lock group leader, which means setting this field to point to its own
668-
PGPROC. When a parallel worker starts up, it points this field at the leader,
669-
with the above-mentioned interlock. The lockGroupMembers field is only used in
653+
Group locking adds three new members to each PGPROC: lockGroupLeader,
654+
lockGroupMembers, and lockGroupLink. A PGPROC's lockGroupLeader is NULL for
655+
processes not involved in parallel query. When a process wants to cooperate
656+
with parallel workers, it becomes a lock group leader, which means setting
657+
this field to point to its own PGPROC. When a parallel worker starts up, it
658+
points this field at the leader. The lockGroupMembers field is only used in
670659
the leader; it is a list of the member PGPROCs of the lock group (the leader
671660
and all workers). The lockGroupLink field is the list link for this list.
672661

673-
Allfour of these fields are considered to be protected by a lock manager
662+
Allthree of these fields are considered to be protected by a lock manager
674663
partition lock. The partition lock that protects these fields within a given
675664
lock group is chosen by taking the leader's pgprocno modulo the number of lock
676665
manager partitions. This unusual arrangement has a major advantage: the
@@ -679,6 +668,18 @@ change while the deadlock detector is running, because it knows that it holds
679668
all the lock manager locks. Also, holding this single lock allows safe
680669
manipulation of the lockGroupMembers list for the lock group.
681670

671+
We need an additional interlock when setting these fields, because a newly
672+
started parallel worker has to try to join the leader's lock group, but it
673+
has no guarantee that the group leader is still alive by the time it gets
674+
started. We try to ensure that the parallel leader dies after all workers
675+
in normal cases, but also that the system could survive relatively intact
676+
if that somehow fails to happen. This is one of the precautions against
677+
such a scenario: the leader relays its PGPROC and also its PID to the
678+
worker, and the worker fails to join the lock group unless the given PGPROC
679+
still has the same PID and is still a lock group leader. We assume that
680+
PIDs are not recycled quickly enough for this interlock to fail.
681+
682+
682683
User Locks (Advisory Locks)
683684
---------------------------
684685

‎src/backend/storage/lmgr/proc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ InitProcess(void)
401401
pg_atomic_init_u32(&MyProc->procArrayGroupNext,INVALID_PGPROCNO);
402402

403403
/* Check that group locking fields are in a proper initial state. */
404-
Assert(MyProc->lockGroupLeaderIdentifier==0);
405404
Assert(MyProc->lockGroupLeader==NULL);
406405
Assert(dlist_is_empty(&MyProc->lockGroupMembers));
407406

@@ -565,7 +564,6 @@ InitAuxiliaryProcess(void)
565564
SwitchToSharedLatch();
566565

567566
/* Check that group locking fields are in a proper initial state. */
568-
Assert(MyProc->lockGroupLeaderIdentifier==0);
569567
Assert(MyProc->lockGroupLeader==NULL);
570568
Assert(dlist_is_empty(&MyProc->lockGroupMembers));
571569

@@ -822,7 +820,6 @@ ProcKill(int code, Datum arg)
822820
dlist_delete(&MyProc->lockGroupLink);
823821
if (dlist_is_empty(&leader->lockGroupMembers))
824822
{
825-
leader->lockGroupLeaderIdentifier=0;
826823
leader->lockGroupLeader=NULL;
827824
if (leader!=MyProc)
828825
{
@@ -1771,7 +1768,6 @@ BecomeLockGroupLeader(void)
17711768
leader_lwlock=LockHashPartitionLockByProc(MyProc);
17721769
LWLockAcquire(leader_lwlock,LW_EXCLUSIVE);
17731770
MyProc->lockGroupLeader=MyProc;
1774-
MyProc->lockGroupLeaderIdentifier=MyProcPid;
17751771
dlist_push_head(&MyProc->lockGroupMembers,&MyProc->lockGroupLink);
17761772
LWLockRelease(leader_lwlock);
17771773
}
@@ -1795,6 +1791,9 @@ BecomeLockGroupMember(PGPROC *leader, int pid)
17951791
/* Group leader can't become member of group */
17961792
Assert(MyProc!=leader);
17971793

1794+
/* Can't already be a member of a group */
1795+
Assert(MyProc->lockGroupLeader==NULL);
1796+
17981797
/* PID must be valid. */
17991798
Assert(pid!=0);
18001799

@@ -1808,9 +1807,10 @@ BecomeLockGroupMember(PGPROC *leader, int pid)
18081807
leader_lwlock=LockHashPartitionLockByProc(leader);
18091808
LWLockAcquire(leader_lwlock,LW_EXCLUSIVE);
18101809

1811-
/*Try to jointhegroup */
1812-
if (leader->lockGroupLeaderIdentifier==pid)
1810+
/*Is thistheleader we're looking for? */
1811+
if (leader->pid==pid&&leader->lockGroupLeader==leader)
18131812
{
1813+
/* OK, join the group */
18141814
ok= true;
18151815
MyProc->lockGroupLeader=leader;
18161816
dlist_push_tail(&leader->lockGroupMembers,&MyProc->lockGroupLink);

‎src/include/storage/proc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ struct PGPROC
166166
* Support for lock groups. Use LockHashPartitionLockByProc on the group
167167
* leader to get the LWLock protecting these fields.
168168
*/
169-
intlockGroupLeaderIdentifier;/* MyProcPid, if I'm a leader */
170169
PGPROC*lockGroupLeader;/* lock group leader, if I'm a member */
171170
dlist_headlockGroupMembers;/* list of members, if I'm a leader */
172171
dlist_nodelockGroupLink;/* my member link, if I'm a member */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp