Fix incorrect initialization of ProcGlobal->startupBufferPinWaitBufId.

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.
This commit is contained in:
Tom Lane 2011-08-02 13:23:52 -04:00
parent 89df948ec2
commit 2e53bd5517
3 changed files with 7 additions and 8 deletions

View File

@ -2449,10 +2449,11 @@ LockBufferForCleanup(Buffer buffer)
/* Wait to be signaled by UnpinBuffer() */ /* Wait to be signaled by UnpinBuffer() */
if (InHotStandby) if (InHotStandby)
{ {
/* Share the bufid that Startup process waits on */ /* Publish the bufid that Startup process waits on */
SetStartupBufferPinWaitBufId(buffer - 1); SetStartupBufferPinWaitBufId(buffer - 1);
/* Set alarm and then wait to be signaled by UnpinBuffer() */ /* Set alarm and then wait to be signaled by UnpinBuffer() */
ResolveRecoveryConflictWithBufferPin(); ResolveRecoveryConflictWithBufferPin();
/* Reset the published bufid */
SetStartupBufferPinWaitBufId(-1); SetStartupBufferPinWaitBufId(-1);
} }
else else

View File

@ -171,6 +171,9 @@ InitProcGlobal(void)
ProcGlobal->spins_per_delay = DEFAULT_SPINS_PER_DELAY; ProcGlobal->spins_per_delay = DEFAULT_SPINS_PER_DELAY;
ProcGlobal->freeProcs = NULL; ProcGlobal->freeProcs = NULL;
ProcGlobal->autovacFreeProcs = NULL; ProcGlobal->autovacFreeProcs = NULL;
ProcGlobal->startupProc = NULL;
ProcGlobal->startupProcPid = 0;
ProcGlobal->startupBufferPinWaitBufId = -1;
/* /*
* Create and initialize all the PGPROC structures we'll need (except for * Create and initialize all the PGPROC structures we'll need (except for
@ -493,7 +496,6 @@ PublishStartupProcessInformation(void)
procglobal->startupProc = MyProc; procglobal->startupProc = MyProc;
procglobal->startupProcPid = MyProcPid; procglobal->startupProcPid = MyProcPid;
procglobal->startupBufferPinWaitBufId = 0;
SpinLockRelease(ProcStructLock); SpinLockRelease(ProcStructLock);
} }
@ -520,14 +522,10 @@ SetStartupBufferPinWaitBufId(int bufid)
int int
GetStartupBufferPinWaitBufId(void) GetStartupBufferPinWaitBufId(void)
{ {
int bufid;
/* use volatile pointer to prevent code rearrangement */ /* use volatile pointer to prevent code rearrangement */
volatile PROC_HDR *procglobal = ProcGlobal; volatile PROC_HDR *procglobal = ProcGlobal;
bufid = procglobal->startupBufferPinWaitBufId; return procglobal->startupBufferPinWaitBufId;
return bufid;
} }
/* /*

View File

@ -178,7 +178,7 @@ typedef struct PROC_HDR
/* The proc of the Startup process, since not in ProcArray */ /* The proc of the Startup process, since not in ProcArray */
PGPROC *startupProc; PGPROC *startupProc;
int startupProcPid; 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; int startupBufferPinWaitBufId;
} PROC_HDR; } PROC_HDR;