Change cancel while waiting-for-lock stuff.
authorHiroshi Inoue <inoue@tpf.co.jp>
Tue, 22 Feb 2000 09:55:26 +0000 (09:55 +0000)
committerHiroshi Inoue <inoue@tpf.co.jp>
Tue, 22 Feb 2000 09:55:26 +0000 (09:55 +0000)
src/backend/storage/lmgr/lock.c
src/backend/storage/lmgr/proc.c
src/backend/tcop/postgres.c
src/include/miscadmin.h
src/include/storage/proc.h

index 63896a9500618a5f8825e0c89a86f1ecce25e7a7..bc9a6afc9a5838ccb421900ec08ddd075790770a 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.65 2000/01/26 05:57:01 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.66 2000/02/22 09:55:20 inoue Exp $
  *
  * NOTES
  *   Outside modules can create a lock table and acquire/release
@@ -1743,6 +1743,7 @@ DeadLockCheck(void *proc, LOCK *findlock)
                                                     MyProc->xid,
                                                     NULL) == STATUS_OK)
                            {
+                               SetWaitingForLock(false);
                                GrantLock(MyProc->waitLock, MyProc->token);
                                (MyProc->waitLock->waitProcs.size)--;
                                ProcWakeup(MyProc, NO_ERROR);
index dafab7ebfd38e45b771c5c4ac57ae8c94e0828bb..4e377d6498c381f62fe2c5d5a12c2376d6a33c1a 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.68 2000/02/21 02:42:36 inoue Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.69 2000/02/22 09:55:20 inoue Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -47,7 +47,7 @@
  *     This is so that we can support more backends. (system-wide semaphore
  *     sets run out pretty fast.)                -ay 4/95
  *
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.68 2000/02/21 02:42:36 inoue Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.69 2000/02/22 09:55:20 inoue Exp $
  */
 #include <sys/time.h>
 #include <unistd.h>
@@ -74,6 +74,7 @@
 
 void HandleDeadLock(SIGNAL_ARGS);
 static void ProcFreeAllSemaphores(void);
+static bool GetOffWaitqueue(PROC *);
 
 #define DeadlockCheckTimer pg_options[OPT_DEADLOCKTIMEOUT]
 
@@ -316,9 +317,10 @@ InitProcess(IPCKey key)
  * get off the wait queue
  * -----------------------
  */
-static void
+static bool
 GetOffWaitqueue(PROC *proc)
 {
+   bool    getoffed = false;
    LockLockTable();
    if (proc->links.next != INVALID_OFFSET)
    {
@@ -334,11 +336,12 @@ GetOffWaitqueue(PROC *proc)
        if (proc->waitLock->activeHolders[lockmode] ==
            proc->waitLock->holders[lockmode])
            proc->waitLock->waitMask &= ~(1 << lockmode);
+       getoffed = true;
    }
    SHMQueueElemInit(&(proc->links));
    UnlockLockTable();
 
-   return;
+   return getoffed;
 }
 /*
  * ProcReleaseLocks() -- release all locks associated with this process
@@ -478,6 +481,23 @@ ProcQueueInit(PROC_QUEUE *queue)
 }
 
 
+static bool    lockWaiting = false;
+void   SetWaitingForLock(bool waiting)
+{
+   lockWaiting = waiting;
+}
+void   LockWaitCancel(void)
+{
+   struct itimerval timeval, dummy;
+
+   if (!lockWaiting)   return;
+   lockWaiting = false;
+   /* Deadlock timer off */
+   MemSet(&timeval, 0, sizeof(struct itimerval));
+   setitimer(ITIMER_REAL, &timeval, &dummy);
+   if (GetOffWaitqueue(MyProc))
+       elog(ERROR, "Query cancel requested while waiting lock");
+}
 
 /*
  * ProcSleep -- put a process to sleep
@@ -590,7 +610,7 @@ ins:;
    timeval.it_value.tv_sec = \
        (DeadlockCheckTimer ? DeadlockCheckTimer : DEADLOCK_CHECK_TIMER);
 
-   SetLockWaiting(true);
+   lockWaiting = true;
    do
    {
        MyProc->errType = NO_ERROR;     /* reset flag after deadlock check */
@@ -610,7 +630,7 @@ ins:;
                         IpcExclusiveLock);
    } while (MyProc->errType == STATUS_NOT_FOUND);      /* sleep after deadlock
                                                         * check */
-   SetLockWaiting(false);
+   lockWaiting = false;
 
    /* ---------------
     * We were awoken before a timeout - now disable the timer
@@ -824,6 +844,7 @@ HandleDeadLock(SIGNAL_ARGS)
     * ------------------------
     */
    Assert(mywaitlock->waitProcs.size > 0);
+   lockWaiting = false;
    --mywaitlock->waitProcs.size;
    SHMQueueDelete(&(MyProc->links));
    SHMQueueElemInit(&(MyProc->links));
index 71087295313bc78ad99c0ca3ca98c56846f64fd6..0ad386860701553031e16963daf956f0180ba26b 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.145 2000/02/21 02:42:35 inoue Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.146 2000/02/22 09:55:18 inoue Exp $
  *
  * NOTES
  *   this is the "main" module of the postgres backend and
@@ -809,22 +809,12 @@ FloatExceptionHandler(SIGNAL_ARGS)
         " or was a divide by zero");
 }
 
-
-static bool    lockWaiting = false;
-void SetLockWaiting(bool waiting)
-{
-   lockWaiting = waiting;
-}
 /* signal handler for query cancel signal from postmaster */
 static void
 QueryCancelHandler(SIGNAL_ARGS)
 {
    QueryCancel = true;
-   if (lockWaiting)
-   {
-       lockWaiting = false;
-       elog(ERROR, "Query Cancel requested while waiting lock");
-   }
+   LockWaitCancel();
 }
 
 void
@@ -1513,7 +1503,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
    if (!IsUnderPostmaster)
    {
        puts("\nPOSTGRES backend interactive interface ");
-       puts("$Revision: 1.145 $ $Date: 2000/02/21 02:42:35 $\n");
+       puts("$Revision: 1.146 $ $Date: 2000/02/22 09:55:18 $\n");
    }
 
    /*
@@ -1573,6 +1563,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
         * ----------------
         */
        QueryCancel = false;    /* forget any earlier CANCEL signal */
+       SetWaitingForLock(false);
 
        EnableNotifyInterrupt();
 
@@ -1583,7 +1574,6 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
        firstchar = ReadCommand(parser_input);
 
        QueryCancel = false;    /* forget any earlier CANCEL signal */
-       lockWaiting = false;
 
        /* ----------------
         *   (4) disable async.c's signal handler.
index c80e7608333ad6174115ca9bb11a41836d1b5b89..4b9e00345455e4ce398f48169bd551ee3a8eafc9 100644 (file)
@@ -12,7 +12,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: miscadmin.h,v 1.52 2000/02/21 02:42:37 inoue Exp $
+ * $Id: miscadmin.h,v 1.53 2000/02/22 09:55:20 inoue Exp $
  *
  * NOTES
  *   some of the information in this file will be moved to
@@ -214,7 +214,7 @@ extern ProcessingMode Mode;
 extern void IgnoreSystemIndexes(bool mode);
 extern bool IsIgnoringSystemIndexes(void);
 extern bool IsCacheInitialized(void);
-extern void SetLockWaiting(bool);
+extern void SetWaitingForLock(bool);
 
 /* 
  * "postmaster.pid" is a file containing postmaster's pid, being
index 59098912d679ba59e04a7544bc8deb72831ef988..23e657c7918f56c436edbfce219d32f7fb212f19 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: proc.h,v 1.28 2000/01/26 05:58:33 momjian Exp $
+ * $Id: proc.h,v 1.29 2000/02/22 09:55:26 inoue Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -130,5 +130,6 @@ extern int ProcLockWakeup(PROC_QUEUE *queue, LOCKMETHOD lockmethod,
               LOCK *lock);
 extern void ProcAddLock(SHM_QUEUE *elem);
 extern void ProcReleaseSpins(PROC *proc);
+extern void LockWaitCancel(void);
 
 #endif  /* PROC_H */