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

Commit6059c5a

Browse files
committed
Update for deadlock detection.
1 parent06c120e commit6059c5a

File tree

1 file changed

+29
-18
lines changed
  • src/backend/storage/lmgr

1 file changed

+29
-18
lines changed

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

Lines changed: 29 additions & 18 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.46 1998/12/2918:36:29 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.47 1998/12/2919:32:08 momjian 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.46 1998/12/2918:36:29 momjian Exp $
49+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.47 1998/12/2919:32:08 momjian Exp $
5050
*/
5151
#include<sys/time.h>
5252
#include<unistd.h>
@@ -77,7 +77,7 @@
7777
#include"storage/proc.h"
7878
#include"utils/trace.h"
7979

80-
staticvoidHandleDeadLock(void);
80+
staticvoidHandleDeadLock(intsig);
8181
staticPROC*ProcWakeup(PROC*proc,interrType);
8282

8383
#defineDeadlockCheckTimer pg_options[OPT_DEADLOCKTIMEOUT]
@@ -154,6 +154,8 @@ InitProcess(IPCKey key)
154154
* Routine called if deadlock timer goes off. See ProcSleep()
155155
* ------------------
156156
*/
157+
pqsignal(SIGALRM,HandleDeadLock);
158+
157159
SpinAcquire(ProcStructLock);
158160

159161
/* attach to the free list */
@@ -447,8 +449,10 @@ ProcSleep(PROC_QUEUE *waitQueue,/* lock->waitProcs */
447449
TransactionIdxid)/* needed by user locks, see below */
448450
{
449451
inti;
450-
booldeadlock_checked= false;
451452
PROC*proc;
453+
booldeadlock_checked= false;
454+
structitimervaltimeval,
455+
dummy;
452456

453457
/*
454458
* If the first entries in the waitQueue have a greater priority than
@@ -512,28 +516,27 @@ ProcSleep(PROC_QUEUE *waitQueue,/* lock->waitProcs */
512516
SpinRelease(spinlock);
513517

514518
/* --------------
515-
* We set this so we can wake upafter one second to check for a deadlock.
519+
* We set this so we can wake upperiodically and check for a deadlock.
516520
* If a deadlock is detected, the handler releases the processes
517521
* semaphore and aborts the current transaction.
522+
*
523+
* Need to zero out struct to set the interval and the micro seconds fields
524+
* to 0.
518525
* --------------
519526
*/
527+
MemSet(&timeval,0,sizeof(structitimerval));
528+
timeval.it_value.tv_sec= \
529+
(DeadlockCheckTimer ?DeadlockCheckTimer :DEADLOCK_CHECK_TIMER);
520530

521531
do
522532
{
523533
MyProc->errType=NO_ERROR;/* reset flag after deadlock check */
524534

525-
if (deadlock_checked== false)
526-
{
527-
if (sleep(DeadlockCheckTimer ?DeadlockCheckTimer :DEADLOCK_CHECK_TIMER)
528-
==0/* no signal interruption */ )
529-
{
530-
HandleDeadLock();
531-
deadlock_checked= true;
532-
}
533-
}
534-
else
535-
pause();
536-
535+
if (!deadlock_checked)
536+
if (setitimer(ITIMER_REAL,&timeval,&dummy))
537+
elog(FATAL,"ProcSleep: Unable to set timer for process wakeup");
538+
deadlock_checked= true;
539+
537540
/* --------------
538541
* if someone wakes us between SpinRelease and IpcSemaphoreLock,
539542
* IpcSemaphoreLock will not block. The wakeup is "saved" by
@@ -545,6 +548,14 @@ ProcSleep(PROC_QUEUE *waitQueue,/* lock->waitProcs */
545548
}while (MyProc->errType==STATUS_NOT_FOUND);/* sleep after deadlock
546549
* check */
547550

551+
/* ---------------
552+
* We were awoken before a timeout - now disable the timer
553+
* ---------------
554+
*/
555+
timeval.it_value.tv_sec=0;
556+
if (setitimer(ITIMER_REAL,&timeval,&dummy))
557+
elog(FATAL,"ProcSleep: Unable to diable timer for process wakeup");
558+
548559
/* ----------------
549560
* We were assumed to be in a critical section when we went
550561
* to sleep.
@@ -687,7 +698,7 @@ ProcAddLock(SHM_QUEUE *elem)
687698
* --------------------
688699
*/
689700
staticvoid
690-
HandleDeadLock()
701+
HandleDeadLock(intsig)
691702
{
692703
LOCK*mywaitlock;
693704

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp