Skip to content

Commit e24d1dc

Browse files
Teach GetOldestXmin() about KnownAssignedXids during recovery.
Very minor issue, though this is required for a later patch. Reported by Heikki Linnakangas.
1 parent e1cc96d commit e24d1dc

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

src/backend/storage/ipc/procarray.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.73 2010/08/12 23:24:54 rhaas Exp $
40+
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.74 2010/08/30 14:16:48 sriggs Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -156,6 +156,7 @@ static int KnownAssignedXidsGet(TransactionId *xarray, TransactionId xmax);
156156
static int KnownAssignedXidsGetAndSetXmin(TransactionId *xarray,
157157
TransactionId *xmin,
158158
TransactionId xmax);
159+
static int KnownAssignedXidsGetOldestXmin(void);
159160
static void KnownAssignedXidsDisplay(int trace_level);
160161

161162
/*
@@ -1112,6 +1113,18 @@ GetOldestXmin(bool allDbs, bool ignoreVacuum)
11121113
}
11131114
}
11141115

1116+
if (RecoveryInProgress())
1117+
{
1118+
/*
1119+
* Check to see whether KnownAssignedXids contains an xid value
1120+
* older than the main procarray.
1121+
*/
1122+
TransactionId kaxmin = KnownAssignedXidsGetOldestXmin();
1123+
if (TransactionIdIsNormal(kaxmin) &&
1124+
TransactionIdPrecedes(kaxmin, result))
1125+
result = kaxmin;
1126+
}
1127+
11151128
LWLockRelease(ProcArrayLock);
11161129

11171130
/*
@@ -3015,6 +3028,33 @@ KnownAssignedXidsGetAndSetXmin(TransactionId *xarray, TransactionId *xmin,
30153028
return count;
30163029
}
30173030

3031+
static int
3032+
KnownAssignedXidsGetOldestXmin(void)
3033+
{
3034+
/* use volatile pointer to prevent code rearrangement */
3035+
volatile ProcArrayStruct *pArray = procArray;
3036+
int head,
3037+
tail;
3038+
int i;
3039+
3040+
/*
3041+
* Fetch head just once, since it may change while we loop.
3042+
*/
3043+
SpinLockAcquire(&pArray->known_assigned_xids_lck);
3044+
tail = pArray->tailKnownAssignedXids;
3045+
head = pArray->headKnownAssignedXids;
3046+
SpinLockRelease(&pArray->known_assigned_xids_lck);
3047+
3048+
for (i = tail; i < head; i++)
3049+
{
3050+
/* Skip any gaps in the array */
3051+
if (KnownAssignedXidsValid[i])
3052+
return KnownAssignedXids[i];
3053+
}
3054+
3055+
return InvalidTransactionId;
3056+
}
3057+
30183058
/*
30193059
* Display KnownAssignedXids to provide debug trail
30203060
*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy