Tune GetSnapshotData() during Hot Standby by avoiding loop

through normal backends. Makes code clearer also, since we
avoid various Assert()s. Performance of snapshots taken
during recovery no longer depends upon number of read-only
backends.
This commit is contained in:
Simon Riggs 2010-04-18 18:06:07 +00:00
parent 7b130fbc50
commit 21d6a6a128
3 changed files with 79 additions and 71 deletions

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.397 2010/04/16 08:58:16 heikki Exp $
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.398 2010/04/18 18:05:51 sriggs Exp $
*
*-------------------------------------------------------------------------
*/
@ -6454,6 +6454,12 @@ CheckRecoveryConsistency(void)
}
}
bool
XLogConsistentState(void)
{
return reachedMinRecoveryPoint;
}
/*
* Is the system still in recovery?
*

View File

@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.62 2010/04/06 10:50:57 sriggs Exp $
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.63 2010/04/18 18:05:55 sriggs Exp $
*
*-------------------------------------------------------------------------
*/
@ -1090,10 +1090,18 @@ GetSnapshotData(Snapshot snapshot)
/* initialize xmin calculation with xmax */
globalxmin = xmin = xmax;
/*
* If in recovery get any known assigned xids.
*/
if (!snapshot->takenDuringRecovery)
{
/*
* Spin over procArray checking xid, xmin, and subxids. The goal is to
* gather all active xids, find the lowest xmin, and try to record
* subxids.
* subxids. During recovery no xids will be assigned, so all normal
* backends can be ignored, nor are there any VACUUMs running. All
* prepared transaction xids are held in KnownAssignedXids, so these
* will be seen without needing to loop through procs here.
*/
for (index = 0; index < arrayP->numProcs; index++)
{
@ -1124,7 +1132,6 @@ GetSnapshotData(Snapshot snapshot)
*/
if (TransactionIdIsNormal(xid))
{
Assert(!snapshot->takenDuringRecovery);
if (TransactionIdFollowsOrEquals(xid, xmax))
continue;
if (proc != MyProc)
@ -1157,7 +1164,6 @@ GetSnapshotData(Snapshot snapshot)
if (nxids > 0)
{
Assert(!snapshot->takenDuringRecovery);
memcpy(snapshot->subxip + subcount,
(void *) proc->subxids.xids,
nxids * sizeof(TransactionId));
@ -1166,14 +1172,9 @@ GetSnapshotData(Snapshot snapshot)
}
}
}
/*
* If in recovery get any known assigned xids.
*/
if (snapshot->takenDuringRecovery)
}
else
{
Assert(count == 0);
/*
* We store all xids directly into subxip[]. Here's why:
*

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.106 2010/04/12 09:52:29 heikki Exp $
* $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.107 2010/04/18 18:06:07 sriggs Exp $
*/
#ifndef XLOG_H
#define XLOG_H
@ -278,6 +278,7 @@ extern void xlog_desc(StringInfo buf, uint8 xl_info, char *rec);
extern void issue_xlog_fsync(int fd, uint32 log, uint32 seg);
extern bool XLogConsistentState(void);
extern bool RecoveryInProgress(void);
extern bool XLogInsertAllowed(void);
extern TimestampTz GetLatestXLogTime(void);