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

Commit 3725570

Browse files
Fix bug in early startup of Hot Standby with subtransactions.
When HS startup is deferred because of overflowed subtransactions, ensure that we re-initialize KnownAssignedXids for when both existing and incoming snapshots have non-zero qualifying xids. Fixes bug #6661 reported by Valentine Gogichashvili. Analysis and fix by Andres Freund
1 parent 3b5548a commit 3725570

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/backend/storage/ipc/procarray.c

+31-1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ static int KnownAssignedXidsGetAndSetXmin(TransactionId *xarray,
160160
TransactionId xmax);
161161
static TransactionId KnownAssignedXidsGetOldestXmin(void);
162162
static void KnownAssignedXidsDisplay(int trace_level);
163+
static void KnownAssignedXidsReset(void);
163164

164165
/*
165166
* Report shared-memory space needed by CreateSharedProcArray.
@@ -526,6 +527,11 @@ ProcArrayApplyRecoveryInfo(RunningTransactions running)
526527
*/
527528
if (!running->subxid_overflow || running->xcnt == 0)
528529
{
530+
/*
531+
* If we have already collected known assigned xids, we need to
532+
* throw them away before we apply the recovery snapshot.
533+
*/
534+
KnownAssignedXidsReset();
529535
standbyState = STANDBY_INITIALIZED;
530536
}
531537
else
@@ -569,7 +575,6 @@ ProcArrayApplyRecoveryInfo(RunningTransactions running)
569575
* xids to subtrans. If RunningXacts is overflowed then we don't have
570576
* enough information to correctly update subtrans anyway.
571577
*/
572-
Assert(procArray->numKnownAssignedXids == 0);
573578

574579
/*
575580
* Allocate a temporary array to avoid modifying the array passed as
@@ -599,6 +604,12 @@ ProcArrayApplyRecoveryInfo(RunningTransactions running)
599604

600605
if (nxids > 0)
601606
{
607+
if (procArray->numKnownAssignedXids != 0)
608+
{
609+
LWLockRelease(ProcArrayLock);
610+
elog(ERROR, "KnownAssignedXids is not empty");
611+
}
612+
602613
/*
603614
* Sort the array so that we can add them safely into
604615
* KnownAssignedXids.
@@ -3340,3 +3351,22 @@ KnownAssignedXidsDisplay(int trace_level)
33403351

33413352
pfree(buf.data);
33423353
}
3354+
3355+
/*
3356+
* KnownAssignedXidsReset
3357+
* Resets KnownAssignedXids to be empty
3358+
*/
3359+
static void
3360+
KnownAssignedXidsReset(void)
3361+
{
3362+
/* use volatile pointer to prevent code rearrangement */
3363+
volatile ProcArrayStruct *pArray = procArray;
3364+
3365+
LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
3366+
3367+
pArray->numKnownAssignedXids = 0;
3368+
pArray->tailKnownAssignedXids = 0;
3369+
pArray->headKnownAssignedXids = 0;
3370+
3371+
LWLockRelease(ProcArrayLock);
3372+
}

0 commit comments

Comments
 (0)