Commit a60c9e33 authored by Hiroshi Inoue's avatar Hiroshi Inoue

fix the TODO

* Allow PQrequestCancel() to terminate when in waiting-for-lock state
Changes are limited to BACKEND,however.
parent 320d3e06
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.67 2000/01/26 05:57:02 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.68 2000/02/21 02:42:36 inoue Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
* This is so that we can support more backends. (system-wide semaphore * This is so that we can support more backends. (system-wide semaphore
* sets run out pretty fast.) -ay 4/95 * sets run out pretty fast.) -ay 4/95
* *
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.67 2000/01/26 05:57:02 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.68 2000/02/21 02:42:36 inoue Exp $
*/ */
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
...@@ -312,6 +312,34 @@ InitProcess(IPCKey key) ...@@ -312,6 +312,34 @@ InitProcess(IPCKey key)
on_shmem_exit(ProcKill, (caddr_t) MyProcPid); on_shmem_exit(ProcKill, (caddr_t) MyProcPid);
} }
/* -----------------------
* get off the wait queue
* -----------------------
*/
static void
GetOffWaitqueue(PROC *proc)
{
LockLockTable();
if (proc->links.next != INVALID_OFFSET)
{
int lockmode = proc->token;
Assert(proc->waitLock->waitProcs.size > 0);
SHMQueueDelete(&(proc->links));
--proc->waitLock->waitProcs.size;
Assert(proc->waitLock->nHolding > 0);
Assert(proc->waitLock->nHolding > proc->waitLock->nActive);
--proc->waitLock->nHolding;
Assert(proc->waitLock->holders[lockmode] > 0);
--proc->waitLock->holders[lockmode];
if (proc->waitLock->activeHolders[lockmode] ==
proc->waitLock->holders[lockmode])
proc->waitLock->waitMask &= ~(1 << lockmode);
}
SHMQueueElemInit(&(proc->links));
UnlockLockTable();
return;
}
/* /*
* ProcReleaseLocks() -- release all locks associated with this process * ProcReleaseLocks() -- release all locks associated with this process
* *
...@@ -322,6 +350,7 @@ ProcReleaseLocks() ...@@ -322,6 +350,7 @@ ProcReleaseLocks()
if (!MyProc) if (!MyProc)
return; return;
LockReleaseAll(1, &MyProc->lockQueue); LockReleaseAll(1, &MyProc->lockQueue);
GetOffWaitqueue(MyProc);
} }
/* /*
...@@ -405,15 +434,7 @@ ProcKill(int exitStatus, int pid) ...@@ -405,15 +434,7 @@ ProcKill(int exitStatus, int pid)
* get off the wait queue * get off the wait queue
* ---------------- * ----------------
*/ */
LockLockTable(); GetOffWaitqueue(proc);
if (proc->links.next != INVALID_OFFSET)
{
Assert(proc->waitLock->waitProcs.size > 0);
SHMQueueDelete(&(proc->links));
--proc->waitLock->waitProcs.size;
}
SHMQueueElemInit(&(proc->links));
UnlockLockTable();
return; return;
} }
...@@ -569,6 +590,7 @@ ins:; ...@@ -569,6 +590,7 @@ ins:;
timeval.it_value.tv_sec = \ timeval.it_value.tv_sec = \
(DeadlockCheckTimer ? DeadlockCheckTimer : DEADLOCK_CHECK_TIMER); (DeadlockCheckTimer ? DeadlockCheckTimer : DEADLOCK_CHECK_TIMER);
SetLockWaiting(true);
do do
{ {
MyProc->errType = NO_ERROR; /* reset flag after deadlock check */ MyProc->errType = NO_ERROR; /* reset flag after deadlock check */
...@@ -588,6 +610,7 @@ ins:; ...@@ -588,6 +610,7 @@ ins:;
IpcExclusiveLock); IpcExclusiveLock);
} while (MyProc->errType == STATUS_NOT_FOUND); /* sleep after deadlock } while (MyProc->errType == STATUS_NOT_FOUND); /* sleep after deadlock
* check */ * check */
SetLockWaiting(false);
/* --------------- /* ---------------
* We were awoken before a timeout - now disable the timer * We were awoken before a timeout - now disable the timer
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.144 2000/02/20 04:26:35 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.145 2000/02/21 02:42:35 inoue Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -810,11 +810,21 @@ FloatExceptionHandler(SIGNAL_ARGS) ...@@ -810,11 +810,21 @@ FloatExceptionHandler(SIGNAL_ARGS)
} }
static bool lockWaiting = false;
void SetLockWaiting(bool waiting)
{
lockWaiting = waiting;
}
/* signal handler for query cancel signal from postmaster */ /* signal handler for query cancel signal from postmaster */
static void static void
QueryCancelHandler(SIGNAL_ARGS) QueryCancelHandler(SIGNAL_ARGS)
{ {
QueryCancel = true; QueryCancel = true;
if (lockWaiting)
{
lockWaiting = false;
elog(ERROR, "Query Cancel requested while waiting lock");
}
} }
void void
...@@ -1503,7 +1513,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -1503,7 +1513,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {
puts("\nPOSTGRES backend interactive interface "); puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.144 $ $Date: 2000/02/20 04:26:35 $\n"); puts("$Revision: 1.145 $ $Date: 2000/02/21 02:42:35 $\n");
} }
/* /*
...@@ -1573,6 +1583,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -1573,6 +1583,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
firstchar = ReadCommand(parser_input); firstchar = ReadCommand(parser_input);
QueryCancel = false; /* forget any earlier CANCEL signal */ QueryCancel = false; /* forget any earlier CANCEL signal */
lockWaiting = false;
/* ---------------- /* ----------------
* (4) disable async.c's signal handler. * (4) disable async.c's signal handler.
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: miscadmin.h,v 1.51 2000/02/18 09:29:06 inoue Exp $ * $Id: miscadmin.h,v 1.52 2000/02/21 02:42:37 inoue Exp $
* *
* NOTES * NOTES
* some of the information in this file will be moved to * some of the information in this file will be moved to
...@@ -214,6 +214,7 @@ extern ProcessingMode Mode; ...@@ -214,6 +214,7 @@ extern ProcessingMode Mode;
extern void IgnoreSystemIndexes(bool mode); extern void IgnoreSystemIndexes(bool mode);
extern bool IsIgnoringSystemIndexes(void); extern bool IsIgnoringSystemIndexes(void);
extern bool IsCacheInitialized(void); extern bool IsCacheInitialized(void);
extern void SetLockWaiting(bool);
/* /*
* "postmaster.pid" is a file containing postmaster's pid, being * "postmaster.pid" is a file containing postmaster's pid, being
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment