Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a60c9e3

Browse files
author
Hiroshi Inoue
committed
fix the TODO
* Allow PQrequestCancel() to terminate when in waiting-for-lock state Changes are limited to BACKEND,however.
1 parent 320d3e0 commit a60c9e3

File tree

3 files changed

+49
-14
lines changed

3 files changed

+49
-14
lines changed

src/backend/storage/lmgr/proc.c

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.67 2000/01/26 05:57:02 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.68 2000/02/21 02:42:36 inoue Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -47,7 +47,7 @@
4747
* This is so that we can support more backends. (system-wide semaphore
4848
* sets run out pretty fast.) -ay 4/95
4949
*
50-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.67 2000/01/26 05:57:02 momjian Exp $
50+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.68 2000/02/21 02:42:36 inoue Exp $
5151
*/
5252
#include <sys/time.h>
5353
#include <unistd.h>
@@ -312,6 +312,34 @@ InitProcess(IPCKey key)
312312
on_shmem_exit(ProcKill, (caddr_t) MyProcPid);
313313
}
314314

315+
/* -----------------------
316+
* get off the wait queue
317+
* -----------------------
318+
*/
319+
static void
320+
GetOffWaitqueue(PROC *proc)
321+
{
322+
LockLockTable();
323+
if (proc->links.next != INVALID_OFFSET)
324+
{
325+
int lockmode = proc->token;
326+
Assert(proc->waitLock->waitProcs.size > 0);
327+
SHMQueueDelete(&(proc->links));
328+
--proc->waitLock->waitProcs.size;
329+
Assert(proc->waitLock->nHolding > 0);
330+
Assert(proc->waitLock->nHolding > proc->waitLock->nActive);
331+
--proc->waitLock->nHolding;
332+
Assert(proc->waitLock->holders[lockmode] > 0);
333+
--proc->waitLock->holders[lockmode];
334+
if (proc->waitLock->activeHolders[lockmode] ==
335+
proc->waitLock->holders[lockmode])
336+
proc->waitLock->waitMask &= ~(1 << lockmode);
337+
}
338+
SHMQueueElemInit(&(proc->links));
339+
UnlockLockTable();
340+
341+
return;
342+
}
315343
/*
316344
* ProcReleaseLocks() -- release all locks associated with this process
317345
*
@@ -322,6 +350,7 @@ ProcReleaseLocks()
322350
if (!MyProc)
323351
return;
324352
LockReleaseAll(1, &MyProc->lockQueue);
353+
GetOffWaitqueue(MyProc);
325354
}
326355

327356
/*
@@ -405,15 +434,7 @@ ProcKill(int exitStatus, int pid)
405434
* get off the wait queue
406435
* ----------------
407436
*/
408-
LockLockTable();
409-
if (proc->links.next != INVALID_OFFSET)
410-
{
411-
Assert(proc->waitLock->waitProcs.size > 0);
412-
SHMQueueDelete(&(proc->links));
413-
--proc->waitLock->waitProcs.size;
414-
}
415-
SHMQueueElemInit(&(proc->links));
416-
UnlockLockTable();
437+
GetOffWaitqueue(proc);
417438

418439
return;
419440
}
@@ -569,6 +590,7 @@ ins:;
569590
timeval.it_value.tv_sec = \
570591
(DeadlockCheckTimer ? DeadlockCheckTimer : DEADLOCK_CHECK_TIMER);
571592

593+
SetLockWaiting(true);
572594
do
573595
{
574596
MyProc->errType = NO_ERROR; /* reset flag after deadlock check */
@@ -588,6 +610,7 @@ ins:;
588610
IpcExclusiveLock);
589611
} while (MyProc->errType == STATUS_NOT_FOUND); /* sleep after deadlock
590612
* check */
613+
SetLockWaiting(false);
591614

592615
/* ---------------
593616
* We were awoken before a timeout - now disable the timer

src/backend/tcop/postgres.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.144 2000/02/20 04:26:35 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.145 2000/02/21 02:42:35 inoue Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -810,11 +810,21 @@ FloatExceptionHandler(SIGNAL_ARGS)
810810
}
811811

812812

813+
static bool lockWaiting = false;
814+
void SetLockWaiting(bool waiting)
815+
{
816+
lockWaiting = waiting;
817+
}
813818
/* signal handler for query cancel signal from postmaster */
814819
static void
815820
QueryCancelHandler(SIGNAL_ARGS)
816821
{
817822
QueryCancel = true;
823+
if (lockWaiting)
824+
{
825+
lockWaiting = false;
826+
elog(ERROR, "Query Cancel requested while waiting lock");
827+
}
818828
}
819829

820830
void
@@ -1503,7 +1513,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
15031513
if (!IsUnderPostmaster)
15041514
{
15051515
puts("\nPOSTGRES backend interactive interface ");
1506-
puts("$Revision: 1.144 $ $Date: 2000/02/20 04:26:35 $\n");
1516+
puts("$Revision: 1.145 $ $Date: 2000/02/21 02:42:35 $\n");
15071517
}
15081518

15091519
/*
@@ -1573,6 +1583,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
15731583
firstchar = ReadCommand(parser_input);
15741584

15751585
QueryCancel = false; /* forget any earlier CANCEL signal */
1586+
lockWaiting = false;
15761587

15771588
/* ----------------
15781589
* (4) disable async.c's signal handler.

src/include/miscadmin.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $Id: miscadmin.h,v 1.51 2000/02/18 09:29:06 inoue Exp $
15+
* $Id: miscadmin.h,v 1.52 2000/02/21 02:42:37 inoue Exp $
1616
*
1717
* NOTES
1818
* some of the information in this file will be moved to
@@ -214,6 +214,7 @@ extern ProcessingMode Mode;
214214
extern void IgnoreSystemIndexes(bool mode);
215215
extern bool IsIgnoringSystemIndexes(void);
216216
extern bool IsCacheInitialized(void);
217+
extern void SetLockWaiting(bool);
217218

218219
/*
219220
* "postmaster.pid" is a file containing postmaster's pid, being

0 commit comments

Comments
 (0)