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

Commitfb70587

Browse files
committed
Patch from Massimo Dal Zotto <dz@cs.unitn.it>
The following patches add to the backend a new debugging flag -K which printsa debug trace of all locking operations on user relations (those with oidgreater than 20000). The code is compiled only if LOCK_MGR_DEBUG is defined,so the patch should be harmless if not explicitly enabled.I'm using the code to trace deadlock conditions caused by application queriesusing the command "$POSTMASTER -D $PGDATA -o '-d 1 -K 1'.The patches are for version 6.0 dated 970126.
1 parentba82bb3 commitfb70587

File tree

4 files changed

+161
-40
lines changed

4 files changed

+161
-40
lines changed

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

Lines changed: 129 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.6 1996/12/26 17:50:26 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.7 1997/02/12 05:23:49 scrappy Exp $
1111
*
1212
* NOTES
1313
* Outside modules can create a lock table and acquire/release
@@ -57,41 +57,65 @@
5757

5858
#else/* LOCK_MGR_DEBUG */
5959

60+
intlockDebug=0;
61+
62+
#ifndefLOCK_DEBUG_OID_MIN
63+
/*
64+
* This is totally arbitrary. It is the minimum relation oid
65+
* which will trigger the locking debug when the -K option
66+
* is given to the backend. This is done to avoid tracing
67+
* locks on system relations.
68+
*/
69+
#defineLOCK_DEBUG_OID_MIN 20000
70+
#endif
71+
6072
#defineLOCK_PRINT(where,tag,type)\
61-
elog(NOTICE, "%s: rel (%d) dbid (%d) tid (%d,%d) type (%d)\n",where, \
62-
tag->relId, tag->dbId, \
63-
( (tag->tupleId.ip_blkid.data[0] >= 0) ? \
64-
BlockIdGetBlockNumber(&tag->tupleId.ip_blkid) : -1 ), \
65-
tag->tupleId.ip_posid, \
66-
type);
73+
if ((lockDebug >= 1) && (tag->relId >= LOCK_DEBUG_OID_MIN)) \
74+
elog(DEBUG, \
75+
"%s: pid (%d) rel (%d) dbid (%d) tid (%d,%d) type (%d)",where, \
76+
getpid(),\
77+
tag->relId, tag->dbId, \
78+
((tag->tupleId.ip_blkid.bi_hi<<16)+\
79+
tag->tupleId.ip_blkid.bi_lo),\
80+
tag->tupleId.ip_posid, \
81+
type);
6782

6883
#defineLOCK_DUMP(where,lock,type)\
69-
elog(NOTICE, "%s: rel (%d) dbid (%d) tid (%d,%d) nHolding (%d) holders (%d,%d,%d,%d,%d) type (%d)\n",where, \
70-
lock->tag.relId, lock->tag.dbId, \
71-
((lock->tag.tupleId.ip_blkid.data[0] >= 0) ? \
72-
BlockIdGetBlockNumber(&lock->tag.tupleId.ip_blkid) : -1 ), \
73-
lock->tag.tupleId.ip_posid, \
74-
lock->nHolding,\
75-
lock->holders[1],\
76-
lock->holders[2],\
77-
lock->holders[3],\
78-
lock->holders[4],\
79-
lock->holders[5],\
80-
type);
84+
if ((lockDebug >= 1) && (lock->tag.relId >= LOCK_DEBUG_OID_MIN)) \
85+
elog(DEBUG, \
86+
"%s: pid (%d) rel (%d) dbid (%d) tid (%d,%d) nHolding (%d) "\
87+
"holders (%d,%d,%d,%d,%d) type (%d)",where, \
88+
getpid(),\
89+
lock->tag.relId, lock->tag.dbId, \
90+
((lock->tag.tupleId.ip_blkid.bi_hi<<16)+\
91+
lock->tag.tupleId.ip_blkid.bi_lo),\
92+
lock->tag.tupleId.ip_posid, \
93+
lock->nHolding,\
94+
lock->holders[1],\
95+
lock->holders[2],\
96+
lock->holders[3],\
97+
lock->holders[4],\
98+
lock->holders[5],\
99+
type);
81100

82101
#defineXID_PRINT(where,xidentP)\
83-
elog(NOTICE,\
84-
"%s:xid (%d) pid (%d) lock (%x) nHolding (%d) holders (%d,%d,%d,%d,%d)",\
85-
where,\
86-
xidentP->tag.xid,\
87-
xidentP->tag.pid,\
88-
xidentP->tag.lock,\
89-
xidentP->nHolding,\
90-
xidentP->holders[1],\
91-
xidentP->holders[2],\
92-
xidentP->holders[3],\
93-
xidentP->holders[4],\
94-
xidentP->holders[5]);
102+
if ((lockDebug >= 2) && \
103+
(((LOCK *)MAKE_PTR(xidentP->tag.lock))->tag.relId \
104+
>= LOCK_DEBUG_OID_MIN)) \
105+
elog(DEBUG,\
106+
"%s: pid (%d) xid (%d) pid (%d) lock (%x) nHolding (%d) "\
107+
"holders (%d,%d,%d,%d,%d)",\
108+
where,\
109+
getpid(),\
110+
xidentP->tag.xid,\
111+
xidentP->tag.pid,\
112+
xidentP->tag.lock,\
113+
xidentP->nHolding,\
114+
xidentP->holders[1],\
115+
xidentP->holders[2],\
116+
xidentP->holders[3],\
117+
xidentP->holders[4],\
118+
xidentP->holders[5]);
95119

96120
#endif/* LOCK_MGR_DEBUG */
97121

@@ -528,7 +552,7 @@ LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKT lockt)
528552
}
529553
if (!found)
530554
{
531-
XID_PRINT("queueing XidEnt LockAcquire:",result);
555+
XID_PRINT("LockAcquire:queueing XidEnt",result);
532556
ProcAddLock(&result->queue);
533557
result->nHolding=0;
534558
memset((char*)result->holders,0,sizeof(int)*MAX_LOCKTYPES);
@@ -1102,7 +1126,7 @@ LockReleaseAll(LockTableId tableId, SHM_QUEUE *lockQueue)
11021126
#endif
11031127
SHMQueueFirst(lockQueue,(Pointer*)&xidLook,&xidLook->queue);
11041128

1105-
XID_PRINT("LockReleaseAll:",xidLook);
1129+
XID_PRINT("LockReleaseAll",xidLook);
11061130

11071131
#ifndefUSER_LOCKS
11081132
SpinAcquire(masterLock);
@@ -1322,3 +1346,75 @@ LockingDisabled()
13221346
{
13231347
returnLockingIsDisabled;
13241348
}
1349+
1350+
#ifdefDEADLOCK_DEBUG
1351+
/*
1352+
* Dump all locks. Must have already acquired the masterLock.
1353+
*/
1354+
void
1355+
DumpLocks()
1356+
{
1357+
SHMEM_OFFSETlocation;
1358+
PROC*proc;
1359+
SHM_QUEUE*lockQueue;
1360+
intdone;
1361+
XIDLookupEnt*xidLook=NULL;
1362+
XIDLookupEnt*tmp=NULL;
1363+
SHMEM_OFFSETend;
1364+
SPINLOCKmasterLock;
1365+
intnLockTypes;
1366+
LOCK*lock;
1367+
intpid,count;
1368+
inttableId=1;
1369+
LOCKTAB*ltable;
1370+
1371+
pid=getpid();
1372+
ShmemPIDLookup(pid,&location);
1373+
if (location==INVALID_OFFSET)
1374+
return;
1375+
proc= (PROC*)MAKE_PTR(location);
1376+
if (proc!=MyProc)
1377+
return;
1378+
lockQueue=&proc->lockQueue;
1379+
1380+
Assert (tableId<NumTables);
1381+
ltable=AllTables[tableId];
1382+
if (!ltable)
1383+
return;
1384+
1385+
nLockTypes=ltable->ctl->nLockTypes;
1386+
masterLock=ltable->ctl->masterLock;
1387+
1388+
if (SHMQueueEmpty(lockQueue))
1389+
return;
1390+
1391+
SHMQueueFirst(lockQueue,(Pointer*)&xidLook,&xidLook->queue);
1392+
end=MAKE_OFFSET(lockQueue);
1393+
1394+
LOCK_DUMP("DumpLocks",MyProc->waitLock,0);
1395+
XID_PRINT("DumpLocks",xidLook);
1396+
1397+
for (count=0;;) {
1398+
/* ---------------------------
1399+
* XXX Here we assume the shared memory queue is circular and
1400+
* that we know its internal structure. Should have some sort of
1401+
* macros to allow one to walk it. mer 20 July 1991
1402+
* ---------------------------
1403+
*/
1404+
done= (xidLook->queue.next==end);
1405+
lock= (LOCK*)MAKE_PTR(xidLook->tag.lock);
1406+
1407+
LOCK_DUMP("DumpLocks",lock,0);
1408+
1409+
if (count++>2000) {
1410+
elog(NOTICE,"DumpLocks: xid loop detected, giving up");
1411+
break;
1412+
}
1413+
1414+
if (done)
1415+
break;
1416+
SHMQueueFirst(&xidLook->queue,(Pointer*)&tmp,&tmp->queue);
1417+
xidLook=tmp;
1418+
}
1419+
}
1420+
#endif

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.14 1997/02/11 23:05:38 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.15 1997/02/1205:23:54 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -46,7 +46,7 @@
4646
* This is so that we can support more backends. (system-wide semaphore
4747
* sets run out pretty fast.) -ay 4/95
4848
*
49-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.14 1997/02/11 23:05:38 momjian Exp $
49+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.15 1997/02/1205:23:54 scrappy Exp $
5050
*/
5151
#include<sys/time.h>
5252
#ifndefWIN32
@@ -685,6 +685,10 @@ HandleDeadLock(int sig)
685685
lock=MyProc->waitLock;
686686
size=lock->waitProcs.size;/* so we can look at this in the core */
687687

688+
#ifdefDEADLOCK_DEBUG
689+
DumpLocks();
690+
#endif
691+
688692
/* ------------------------
689693
* Get this process off the lock's wait queue
690694
* ------------------------

‎src/backend/tcop/postgres.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.29 1997/02/03 04:43:31 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.30 1997/02/12 05:24:22 scrappy Exp $
1111
*
1212
* NOTES
1313
* this is the "main" module of the postgres backend and
@@ -91,6 +91,9 @@ static bool DebugPrintRewrittenParsetree = false;
9191
/*static bool EnableRewrite = true; , never changes why have it*/
9292
CommandDestwhereToSendOutput;
9393

94+
#ifdefLOCK_MGR_DEBUG
95+
externintlockDebug;
96+
#endif
9497
externintlockingOff;
9598
externintNBuffers;
9699

@@ -757,6 +760,9 @@ static void usage(char* progname)
757760
fprintf(stderr," F: turn off fsync\n");
758761
fprintf(stderr," f: forbid plantype generation\n");
759762
fprintf(stderr," i: don't execute the query, just show the plan tree\n");
763+
#ifdefLOCK_MGR_DEBUG
764+
fprintf(stderr," K: set locking debug level [0|1|2]\n");
765+
#endif
760766
fprintf(stderr," L: turn off locking\n");
761767
fprintf(stderr," m: set up a listening backend at portno to support multiple front-ends\n");
762768
fprintf(stderr," M: start as postmaster\n");
@@ -846,7 +852,10 @@ PostgresMain(int argc, char *argv[])
846852
*/
847853
flagC=flagQ=flagS=flagE=flagEu=ShowStats=0;
848854
ShowParserStats=ShowPlannerStats=ShowExecutorStats=0;
849-
855+
#ifdefLOCK_MGR_DEBUG
856+
lockDebug=0;
857+
#endif
858+
850859
/* get hostname is either the environment variable PGHOST
851860
or 'localhost' */
852861
if (!(hostName=getenv("PGHOST"))) {
@@ -858,7 +867,7 @@ PostgresMain(int argc, char *argv[])
858867
DataDir=getenv("PGDATA");/* default */
859868
multiplexedBackend= false;/* default */
860869

861-
while ((flag=getopt(argc,argv,"B:bCD:d:Eef:iLm:MNo:P:pQSst:x:F"))
870+
while ((flag=getopt(argc,argv,"B:bCD:d:Eef:iK:Lm:MNo:P:pQSst:x:F"))
862871
!=EOF)
863872
switch (flag) {
864873

@@ -955,6 +964,14 @@ PostgresMain(int argc, char *argv[])
955964
dontExecute=1;
956965
break;
957966

967+
case'K':
968+
#ifdefLOCK_MGR_DEBUG
969+
lockDebug=atoi(optarg);
970+
#else
971+
fprintf(stderr,"Lock debug not compiled in\n");
972+
#endif
973+
break;
974+
958975
case'L':
959976
/* --------------------
960977
* turn off locking
@@ -1283,7 +1300,7 @@ PostgresMain(int argc, char *argv[])
12831300
*/
12841301
if (IsUnderPostmaster== false) {
12851302
puts("\nPOSTGRES backend interactive interface");
1286-
puts("$Revision: 1.29 $ $Date: 1997/02/03 04:43:31 $");
1303+
puts("$Revision: 1.30 $ $Date: 1997/02/12 05:24:22 $");
12871304
}
12881305

12891306
/* ----------------

‎src/include/storage/lock.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: lock.h,v 1.3 1996/11/05 06:11:00 scrappy Exp $
9+
* $Id: lock.h,v 1.4 1997/02/12 05:25:13 scrappy Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -211,4 +211,8 @@ extern bool LockReleaseAll(LockTableId tableId, SHM_QUEUE *lockQueue);
211211
externintLockShmemSize(void);
212212
externboolLockingDisabled(void);
213213

214+
#ifdefDEADLOCK_DEBUG
215+
externvoidDumpLocks(void);
216+
#endif
217+
214218
#endif/* LOCK_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp