aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-08-02 13:23:52 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2011-08-02 13:23:52 -0400
commit2e53bd5517431637e495c7614761e5aae46b4eba (patch)
tree6bcf76fe5760fe05b91e92ca6e6681b1cc39d93e /src
parent89df948ec26679e09f71baf6bbb9b06f9d329712 (diff)
downloadpostgresql-2e53bd5517431637e495c7614761e5aae46b4eba.tar.gz
postgresql-2e53bd5517431637e495c7614761e5aae46b4eba.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/buffer/bufmgr.c3
-rw-r--r--src/backend/storage/lmgr/proc.c10
-rw-r--r--src/include/storage/proc.h2
3 files changed, 7 insertions, 8 deletions
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 5420dbe61a1..4c7cfb0b404 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -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
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c
index f9b3028cfea..106625d87af 100644
--- a/src/backend/storage/lmgr/proc.c
+++ b/src/backend/storage/lmgr/proc.c
@@ -171,6 +171,9 @@ InitProcGlobal(void)
ProcGlobal->spins_per_delay = DEFAULT_SPINS_PER_DELAY;
ProcGlobal->freeProcs = 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
@@ -493,7 +496,6 @@ PublishStartupProcessInformation(void)
procglobal->startupProc = MyProc;
procglobal->startupProcPid = MyProcPid;
- procglobal->startupBufferPinWaitBufId = 0;
SpinLockRelease(ProcStructLock);
}
@@ -520,14 +522,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;
}
/*
diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h
index 09ac3cf967b..92b3b19f2d6 100644
--- a/src/include/storage/proc.h
+++ b/src/include/storage/proc.h
@@ -178,7 +178,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;