Back-patch fix for 'can't wait without a PROC structure' failures:
authorTom Lane <[email protected]>
Mon, 30 Sep 2002 20:18:59 +0000 (20:18 +0000)
committerTom Lane <[email protected]>
Mon, 30 Sep 2002 20:18:59 +0000 (20:18 +0000)
remove separate ShutdownBufferPoolAccess exit callback, and do the
work in ProcKill instead, before we delete MyProc.

src/backend/bootstrap/bootstrap.c
src/backend/storage/buffer/buf_init.c
src/backend/storage/lmgr/lwlock.c
src/backend/storage/lmgr/proc.c

index 2f7638fbb1cebdfec2e708b19e6ccf36c3fc227e..5dc419929f5dd294f4bed8b6c225d657e5b37e52 100644 (file)
@@ -359,6 +359,9 @@ BootstrapMain(int argc, char *argv[])
 
        BaseInit();
 
+       if (IsUnderPostmaster)
+               InitDummyProcess();             /* needed to get LWLocks */
+
        /*
         * XLOG operations
         */
@@ -376,8 +379,6 @@ BootstrapMain(int argc, char *argv[])
                        break;
 
                case BS_XLOG_CHECKPOINT:
-                       if (IsUnderPostmaster)
-                               InitDummyProcess();             /* needed to get LWLocks */
                        CreateDummyCaches();
                        CreateCheckPoint(false, false);
                        SetSavedRedoRecPtr(); /* pass redo ptr back to postmaster */
index 42e6daba18fc95f7dd7867bdeb274870ee65372b..76e4e38d7a723c7210cd716ae803df3f2d810360 100644 (file)
@@ -36,8 +36,6 @@
 #include "utils/memutils.h"
 
 
-static void ShutdownBufferPoolAccess(void);
-
 /*
  *     if BMTRACE is defined, we trace the last 200 buffer allocations and
  *     deallocations in a circular buffer in shared memory.
@@ -244,27 +242,6 @@ InitBufferPoolAccess(void)
         */
        for (i = 0; i < NBuffers; i++)
                BufferBlockPointers[i] = (Block) MAKE_PTR(BufferDescriptors[i].data);
-
-       /*
-        * Now that buffer access is initialized, set up a callback to shut it
-        * down again at backend exit.
-        */
-       on_shmem_exit(ShutdownBufferPoolAccess, 0);
-}
-
-/*
- * Shut down buffer manager at backend exit.
- *
- * This is needed mainly to ensure that we don't leave any buffer reference
- * counts set during an error exit.
- */
-static void
-ShutdownBufferPoolAccess(void)
-{
-       /* Release any buffer context locks we are holding */
-       UnlockBuffers();
-       /* Release any buffer reference counts we are holding */
-       ResetBufferPool(false);
 }
 
 /* -----------------------------------------------------
index 06d82b38cbbdc0bfa6ed40bc0a0c2b8b59d75306..8b7d21343d8ee250954c837118b3cb92e8098843 100644 (file)
@@ -204,6 +204,13 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
 
        PRINT_LWDEBUG("LWLockAcquire", lockid, lock);
 
+       /*
+        * We can't wait if we haven't got a PROC.  This should only occur
+        * during bootstrap or shared memory initialization.  Put an Assert
+        * here to catch unsafe coding practices.
+        */
+       Assert(!(proc == NULL && IsUnderPostmaster));
+
        /*
         * Lock out cancel/die interrupts until we exit the code section
         * protected by the LWLock.  This ensures that interrupts will not
index d93598943f63d0bf0f191103c606a4dd445392fd..30537d41c43568e9c2451d2b1671ae09a2632611 100644 (file)
@@ -449,6 +449,10 @@ ProcKill(void)
 
        /* Abort any buffer I/O in progress */
        AbortBufferIO();
+       /* Release any buffer context locks we are holding */
+       UnlockBuffers();
+       /* Release any buffer reference counts we are holding */
+       ResetBufferPool(false);
 
        /* Get off any wait queue I might be on */
        LockWaitCancel();
@@ -492,6 +496,10 @@ DummyProcKill(void)
 
        /* Abort any buffer I/O in progress */
        AbortBufferIO();
+       /* Release any buffer context locks we are holding */
+       UnlockBuffers();
+       /* Release any buffer reference counts we are holding */
+       ResetBufferPool(false);
 
        /* I can't be on regular lock queues, so needn't check */