Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2e53bd5

Browse files
committed
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.
1 parent 89df948 commit 2e53bd5

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

src/backend/storage/buffer/bufmgr.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -2449,10 +2449,11 @@ LockBufferForCleanup(Buffer buffer)
24492449
/* Wait to be signaled by UnpinBuffer() */
24502450
if (InHotStandby)
24512451
{
2452-
/* Share the bufid that Startup process waits on */
2452+
/* Publish the bufid that Startup process waits on */
24532453
SetStartupBufferPinWaitBufId(buffer - 1);
24542454
/* Set alarm and then wait to be signaled by UnpinBuffer() */
24552455
ResolveRecoveryConflictWithBufferPin();
2456+
/* Reset the published bufid */
24562457
SetStartupBufferPinWaitBufId(-1);
24572458
}
24582459
else

src/backend/storage/lmgr/proc.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ InitProcGlobal(void)
171171
ProcGlobal->spins_per_delay = DEFAULT_SPINS_PER_DELAY;
172172
ProcGlobal->freeProcs = NULL;
173173
ProcGlobal->autovacFreeProcs = NULL;
174+
ProcGlobal->startupProc = NULL;
175+
ProcGlobal->startupProcPid = 0;
176+
ProcGlobal->startupBufferPinWaitBufId = -1;
174177

175178
/*
176179
* Create and initialize all the PGPROC structures we'll need (except for
@@ -493,7 +496,6 @@ PublishStartupProcessInformation(void)
493496

494497
procglobal->startupProc = MyProc;
495498
procglobal->startupProcPid = MyProcPid;
496-
procglobal->startupBufferPinWaitBufId = 0;
497499

498500
SpinLockRelease(ProcStructLock);
499501
}
@@ -520,14 +522,10 @@ SetStartupBufferPinWaitBufId(int bufid)
520522
int
521523
GetStartupBufferPinWaitBufId(void)
522524
{
523-
int bufid;
524-
525525
/* use volatile pointer to prevent code rearrangement */
526526
volatile PROC_HDR *procglobal = ProcGlobal;
527527

528-
bufid = procglobal->startupBufferPinWaitBufId;
529-
530-
return bufid;
528+
return procglobal->startupBufferPinWaitBufId;
531529
}
532530

533531
/*

src/include/storage/proc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ typedef struct PROC_HDR
178178
/* The proc of the Startup process, since not in ProcArray */
179179
PGPROC *startupProc;
180180
int startupProcPid;
181-
/* Buffer id of the buffer that Startup process waits for pin on */
181+
/* Buffer id of the buffer that Startup process waits for pin on, or -1 */
182182
int startupBufferPinWaitBufId;
183183
} PROC_HDR;
184184

0 commit comments

Comments
 (0)