Re: [HACKERS] MVCC works in serialized mode!

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: [HACKERS] MVCC works in serialized mode!
Дата
Msg-id 199812181949.OAA11139@candle.pha.pa.us
обсуждение исходный текст
Ответ на Re: [HACKERS] MVCC works in serialized mode!  (Vadim Mikheev <vadim@krs.ru>)
Ответы Q: CURSOR tuples count  ("Vazsonyi Peter[ke]" <neko@kornel.szif.hu>)
Список pgsql-hackers
> Bruce Momjian wrote:
> >
> > > 6. I'm not happy with current deadlock detection code!
> > >    It seems that backend does DeadLockCheck each time
> > >    when timer expired - shouldn't this be done _once_,
> > >    before backend is going to sleep ?!
> >
> > Not sure.  Now that I think of it, it makes sense that if I go to sleep,
> > a deadlock is not sudenly going to appear while I am asleep.  If a new
> > process causes a deadlock, the new process that causes it will see it.
> >
> > I did not check when I went to sleep because I thought it may be too
> > cpu-intensive to do checking on every sleep, but now that I remember it,
> > it may be very trivial in cpu time to do the check on every sleep.
> >
> > I recommend changing it to do it just before every sleep.  Let me know
> > if you want me to make the change.
>
> May be we could just reduce first sleep time (60 sec is too long),
> do DeadLockCheck _only once_, after first SIGALARM, and after that
> just sleep forever ?
> Why do DeadLockCheck many times ?
>
> Let's think more...
>
> And please consider when lock conflict occures:
>
> 1. One process tries update row being updated by other.
> 2. When reading/writing hashes (I hope to change btrees to
>    use new buffer context lock code, as heap access methods
>    do, - this is short term locking without deadlocks and so -
>    without using lockmanager).
>
> Vadim
>

I have applied the following patch.  It causes only one deadlock check
after a sleep of one second.  Applied only to the CURRENT tree.

--
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
Index: src/backend/parser/scan.c
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/backend/parser/scan.c,v
retrieving revision 1.31
diff -c -r1.31 scan.c
*** scan.c    1998/10/13 17:26:50    1.31
--- scan.c    1998/12/18 19:30:54
***************
*** 1,7 ****
  /* A lexical scanner generated by flex */

  /* Scanner skeleton version:
!  * $Header: /usr/local/cvsroot/pgsql/src/backend/parser/scan.c,v 1.31 1998/10/13 17:26:50 scrappy Exp $
   */

  #define FLEX_SCANNER
--- 1,7 ----
  /* A lexical scanner generated by flex */

  /* Scanner skeleton version:
!  * /master/usr.bin/lex/skel.c,v 1.3 1997/09/25 00:10:23 jch Exp
   */

  #define FLEX_SCANNER
***************
*** 556,562 ****
   *
   *
   * IDENTIFICATION
!  *      $Header: /usr/local/cvsroot/pgsql/src/backend/parser/scan.c,v 1.31 1998/10/13 17:26:50 scrappy Exp $
   *
   *-------------------------------------------------------------------------
   */
--- 556,562 ----
   *
   *
   * IDENTIFICATION
!  *      $Header: /usr/local/cvsroot/pgsql/src/backend/parser/scan.l,v 1.44 1998/10/08 18:29:51 momjian Exp $
   *
   *-------------------------------------------------------------------------
   */
Index: src/backend/storage/lmgr/proc.c
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v
retrieving revision 1.43
diff -c -r1.43 proc.c
*** proc.c    1998/09/01 04:32:02    1.43
--- proc.c    1998/12/18 19:30:59
***************
*** 77,83 ****
  #include "storage/proc.h"
  #include "utils/trace.h"

! static void HandleDeadLock(int sig);
  static PROC *ProcWakeup(PROC *proc, int errType);

  #define DeadlockCheckTimer pg_options[OPT_DEADLOCKTIMEOUT]
--- 77,83 ----
  #include "storage/proc.h"
  #include "utils/trace.h"

! static void HandleDeadLock(void);
  static PROC *ProcWakeup(PROC *proc, int errType);

  #define DeadlockCheckTimer pg_options[OPT_DEADLOCKTIMEOUT]
***************
*** 154,161 ****
       * Routine called if deadlock timer goes off. See ProcSleep()
       * ------------------
       */
-     pqsignal(SIGALRM, HandleDeadLock);
-
      SpinAcquire(ProcStructLock);

      /* attach to the free list */
--- 154,159 ----
***************
*** 449,457 ****
            TransactionId xid)    /* needed by user locks, see below */
  {
      int            i;
      PROC       *proc;
!     struct itimerval timeval,
!                 dummy;

      /*
       * If the first entries in the waitQueue have a greater priority than
--- 447,455 ----
            TransactionId xid)    /* needed by user locks, see below */
  {
      int            i;
+     bool        deadlock_checked = false;
      PROC       *proc;
!     struct timeval timeval;

      /*
       * If the first entries in the waitQueue have a greater priority than
***************
*** 523,539 ****
       * to 0.
       * --------------
       */
!     MemSet(&timeval, 0, sizeof(struct itimerval));
!     timeval.it_value.tv_sec = \
          (DeadlockCheckTimer ? DeadlockCheckTimer : DEADLOCK_CHECK_TIMER);

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

!         if (setitimer(ITIMER_REAL, &timeval, &dummy))
              elog(FATAL, "ProcSleep: Unable to set timer for process wakeup");

          /* --------------
           * if someone wakes us between SpinRelease and IpcSemaphoreLock,
           * IpcSemaphoreLock will not block.  The wakeup is "saved" by
--- 521,546 ----
       * to 0.
       * --------------
       */
!     MemSet(&timeval, 0, sizeof(struct timeval));
!     timeval.tv_sec = \
          (DeadlockCheckTimer ? DeadlockCheckTimer : DEADLOCK_CHECK_TIMER);

      do
      {
+         int expire;
+
          MyProc->errType = NO_ERROR;        /* reset flag after deadlock check */

!         if ((expire = select(0, NULL, NULL, NULL,
!             (deadlock_checked == false) ? &timeval : NULL)) == -1)
              elog(FATAL, "ProcSleep: Unable to set timer for process wakeup");

+         if (expire == 0 /* timeout reached */ && deadlock_checked == false)
+         {
+             HandleDeadLock();
+             deadlock_checked = true;
+         }
+
          /* --------------
           * if someone wakes us between SpinRelease and IpcSemaphoreLock,
           * IpcSemaphoreLock will not block.  The wakeup is "saved" by
***************
*** 545,558 ****
      } while (MyProc->errType == STATUS_NOT_FOUND);        /* sleep after deadlock
                                                           * check */

-     /* ---------------
-      * We were awoken before a timeout - now disable the timer
-      * ---------------
-      */
-     timeval.it_value.tv_sec = 0;
-     if (setitimer(ITIMER_REAL, &timeval, &dummy))
-         elog(FATAL, "ProcSleep: Unable to diable timer for process wakeup");
-
      /* ----------------
       * We were assumed to be in a critical section when we went
       * to sleep.
--- 552,557 ----
***************
*** 695,701 ****
   * --------------------
   */
  static void
! HandleDeadLock(int sig)
  {
      LOCK       *mywaitlock;

--- 694,700 ----
   * --------------------
   */
  static void
! HandleDeadLock()
  {
      LOCK       *mywaitlock;

Index: src/pl/plpgsql/src/gram.c
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/pl/plpgsql/src/gram.c,v
retrieving revision 1.1
diff -c -r1.1 gram.c
*** gram.c    1998/10/28 17:07:17    1.1
--- gram.c    1998/12/18 19:31:12
***************
*** 65,71 ****
   *              procedural language
   *
   * IDENTIFICATION
!  *    $Header: /usr/local/cvsroot/pgsql/src/pl/plpgsql/src/gram.c,v 1.1 1998/10/28 17:07:17 momjian Exp $
   *
   *    This software is copyrighted by Jan Wieck - Hamburg.
   *
--- 65,71 ----
   *              procedural language
   *
   * IDENTIFICATION
!  *    $Header: /usr/local/cvsroot/pgsql/src/pl/plpgsql/src/gram.y,v 1.1 1998/08/24 19:14:47 momjian Exp $
   *
   *    This software is copyrighted by Jan Wieck - Hamburg.
   *
Index: src/pl/plpgsql/src/scan.c
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/pl/plpgsql/src/scan.c,v
retrieving revision 1.1
diff -c -r1.1 scan.c
*** scan.c    1998/10/28 17:07:17    1.1
--- scan.c    1998/12/18 19:31:21
***************
*** 635,641 ****
   *              procedural language
   *
   * IDENTIFICATION
!  *    $Header: /usr/local/cvsroot/pgsql/src/pl/plpgsql/src/scan.c,v 1.1 1998/10/28 17:07:17 momjian Exp $
   *
   *    This software is copyrighted by Jan Wieck - Hamburg.
   *
--- 635,641 ----
   *              procedural language
   *
   * IDENTIFICATION
!  *    $Header: /usr/local/cvsroot/pgsql/src/pl/plpgsql/src/scan.l,v 1.1 1998/08/24 19:14:49 momjian Exp $
   *
   *    This software is copyrighted by Jan Wieck - Hamburg.
   *

В списке pgsql-hackers по дате отправления:

Предыдущее
От: jwieck@debis.com (Jan Wieck)
Дата:
Сообщение: Re: [HACKERS] Upgrades for 6.4.1
Следующее
От: Bruce Momjian
Дата:
Сообщение: 6.4.1 fails to compile