From: Tom Lane Date: Mon, 30 Sep 2002 20:18:59 +0000 (+0000) Subject: Back-patch fix for 'can't wait without a PROC structure' failures: X-Git-Tag: REL7_2_3~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c9e3806e57589570a746e875a69a95fe5149ba53;p=postgresql Back-patch fix for 'can't wait without a PROC structure' failures: remove separate ShutdownBufferPoolAccess exit callback, and do the work in ProcKill instead, before we delete MyProc. --- diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c index f3b6f1f955..420f19499b 100644 --- a/src/backend/bootstrap/bootstrap.c +++ b/src/backend/bootstrap/bootstrap.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.120.2.2 2002/09/30 19:55:08 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.120.2.3 2002/09/30 20:18:59 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -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 */ diff --git a/src/backend/storage/buffer/buf_init.c b/src/backend/storage/buffer/buf_init.c index 37570e6b11..eca2548ab5 100644 --- a/src/backend/storage/buffer/buf_init.c +++ b/src/backend/storage/buffer/buf_init.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.47 2001/11/05 17:46:27 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.47.2.1 2002/09/30 20:18:59 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -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); } /* ----------------------------------------------------- diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index 4f82016c59..c3e361c1d1 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -15,7 +15,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lwlock.c,v 1.8 2002/01/07 16:33:00 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lwlock.c,v 1.8.2.1 2002/09/30 20:18:59 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -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 diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index b1be68a881..7fcd7325f9 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.117 2001/12/28 18:16:43 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.117.2.1 2002/09/30 20:18:59 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -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 */