]> granicus.if.org Git - postgresql/commitdiff
Fix incorrect initialization of ProcGlobal->startupBufferPinWaitBufId.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 2 Aug 2011 17:24:00 +0000 (13:24 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 2 Aug 2011 17:24:00 +0000 (13:24 -0400)
It was initialized in the wrong place and to the wrong value.  With bad
luck this could result in incorrect query-cancellation failures in hot
standby sessions, should a HS backend be holding pin on buffer number 1
while trying to acquire a lock.

src/backend/storage/buffer/bufmgr.c
src/backend/storage/lmgr/proc.c
src/include/storage/proc.h

index 5420dbe61a1786574f765bb8135177495a5076ed..4c7cfb0b404cb63f8f2d300397763c2cecbe97ae 100644 (file)
@@ -2449,10 +2449,11 @@ LockBufferForCleanup(Buffer buffer)
                /* Wait to be signaled by UnpinBuffer() */
                if (InHotStandby)
                {
-                       /* Share the bufid that Startup process waits on */
+                       /* Publish the bufid that Startup process waits on */
                        SetStartupBufferPinWaitBufId(buffer - 1);
                        /* Set alarm and then wait to be signaled by UnpinBuffer() */
                        ResolveRecoveryConflictWithBufferPin();
+                       /* Reset the published bufid */
                        SetStartupBufferPinWaitBufId(-1);
                }
                else
index 44399d822c6a52b0d5a250c890ed98aacb158e5b..78d1fd293435ecb06ae05691ba245d0d83c59daf 100644 (file)
@@ -180,6 +180,9 @@ InitProcGlobal(void)
         */
        ProcGlobal->freeProcs = NULL;
        ProcGlobal->autovacFreeProcs = NULL;
+       ProcGlobal->startupProc = NULL;
+       ProcGlobal->startupProcPid = 0;
+       ProcGlobal->startupBufferPinWaitBufId = -1;
 
        ProcGlobal->spins_per_delay = DEFAULT_SPINS_PER_DELAY;
 
@@ -499,7 +502,6 @@ PublishStartupProcessInformation(void)
 
        procglobal->startupProc = MyProc;
        procglobal->startupProcPid = MyProcPid;
-       procglobal->startupBufferPinWaitBufId = 0;
 
        SpinLockRelease(ProcStructLock);
 }
@@ -526,14 +528,10 @@ SetStartupBufferPinWaitBufId(int bufid)
 int
 GetStartupBufferPinWaitBufId(void)
 {
-       int                     bufid;
-
        /* use volatile pointer to prevent code rearrangement */
        volatile PROC_HDR *procglobal = ProcGlobal;
 
-       bufid = procglobal->startupBufferPinWaitBufId;
-
-       return bufid;
+       return procglobal->startupBufferPinWaitBufId;
 }
 
 /*
index 4819cb8110817dd15a818f20b3a1fa9f1d756164..af9c1292fc828ecf15095f9dc4d9733ae162887f 100644 (file)
@@ -159,7 +159,7 @@ typedef struct PROC_HDR
        /* The proc of the Startup process, since not in ProcArray */
        PGPROC     *startupProc;
        int                     startupProcPid;
-       /* Buffer id of the buffer that Startup process waits for pin on */
+       /* Buffer id of the buffer that Startup process waits for pin on, or -1 */
        int                     startupBufferPinWaitBufId;
 } PROC_HDR;