Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8431e29

Browse files
Cleanup initialization of Hot Standby. Clarify working with reanalysis
of requirements and documentation on LogStandbySnapshot(). Fixestwo minor bugs reported by Tom Lane that would lead to an incorrectsnapshot after transaction wraparound. Also fix two other problemsdiscovered that would give incorrect snapshots in certain cases.ProcArrayApplyRecoveryInfo() substantially rewritten. Some minorrefactoring of xact_redo_apply() and ExpireTreeKnownAssignedTransactionIds().
1 parentc2e7f78 commit8431e29

File tree

6 files changed

+252
-120
lines changed

6 files changed

+252
-120
lines changed

‎src/backend/access/transam/xact.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.289 2010/02/26 02:00:34 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.290 2010/05/13 11:15:38 sriggs Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -4378,7 +4378,7 @@ xact_redo_commit(xl_xact_commit *xlrec, TransactionId xid, XLogRecPtr lsn)
43784378
LWLockRelease(XidGenLock);
43794379
}
43804380

4381-
if (!InHotStandby)
4381+
if (standbyState==STANDBY_DISABLED)
43824382
{
43834383
/*
43844384
* Mark the transaction committed in pg_clog.
@@ -4412,12 +4412,12 @@ xact_redo_commit(xl_xact_commit *xlrec, TransactionId xid, XLogRecPtr lsn)
44124412
/*
44134413
* We must mark clog before we update the ProcArray.
44144414
*/
4415-
ExpireTreeKnownAssignedTransactionIds(xid,xlrec->nsubxacts,sub_xids);
4415+
ExpireTreeKnownAssignedTransactionIds(xid,xlrec->nsubxacts,sub_xids,max_xid);
44164416

44174417
/*
44184418
* Send any cache invalidations attached to the commit. We must
44194419
* maintain the same order of invalidation then release locks as
4420-
* occurs in.
4420+
* occurs in CommitTransaction().
44214421
*/
44224422
ProcessCommittedInvalidationMessages(inval_msgs,xlrec->nmsgs,
44234423
XactCompletionRelcacheInitFileInval(xlrec),
@@ -4499,7 +4499,12 @@ xact_redo_abort(xl_xact_abort *xlrec, TransactionId xid)
44994499
LWLockRelease(XidGenLock);
45004500
}
45014501

4502-
if (InHotStandby)
4502+
if (standbyState==STANDBY_DISABLED)
4503+
{
4504+
/* Mark the transaction aborted in pg_clog, no need for async stuff */
4505+
TransactionIdAbortTree(xid,xlrec->nsubxacts,sub_xids);
4506+
}
4507+
else
45034508
{
45044509
/*
45054510
* If a transaction completion record arrives that has as-yet
@@ -4511,17 +4516,14 @@ xact_redo_abort(xl_xact_abort *xlrec, TransactionId xid)
45114516
* already. Leave it in.
45124517
*/
45134518
RecordKnownAssignedTransactionIds(max_xid);
4514-
}
45154519

4516-
/* Mark the transaction aborted in pg_clog, no need for async stuff */
4517-
TransactionIdAbortTree(xid,xlrec->nsubxacts,sub_xids);
4520+
/* Mark the transaction aborted in pg_clog, no need for async stuff */
4521+
TransactionIdAbortTree(xid,xlrec->nsubxacts,sub_xids);
45184522

4519-
if (InHotStandby)
4520-
{
45214523
/*
4522-
* We mustmark clog beforeweupdate the ProcArray.
4524+
* We mustupdate the ProcArray afterwehave marked clog.
45234525
*/
4524-
ExpireTreeKnownAssignedTransactionIds(xid,xlrec->nsubxacts,sub_xids);
4526+
ExpireTreeKnownAssignedTransactionIds(xid,xlrec->nsubxacts,sub_xids,max_xid);
45254527

45264528
/*
45274529
* There are no flat files that need updating, nor invalidation
@@ -4596,7 +4598,7 @@ xact_redo(XLogRecPtr lsn, XLogRecord *record)
45964598
{
45974599
xl_xact_assignment*xlrec= (xl_xact_assignment*)XLogRecGetData(record);
45984600

4599-
if (InHotStandby)
4601+
if (standbyState >=STANDBY_INITIALIZED)
46004602
ProcArrayApplyXidAssignment(xlrec->xtop,
46014603
xlrec->nsubxacts,xlrec->xsub);
46024604
}

‎src/backend/access/transam/xlog.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.409 2010/05/03 11:17:52 heikki Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.410 2010/05/13 11:15:38 sriggs Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -5995,6 +5995,7 @@ StartupXLOG(void)
59955995
if (wasShutdown)
59965996
{
59975997
RunningTransactionsDatarunning;
5998+
TransactionIdlatestCompletedXid;
59985999

59996000
/*
60006001
* Construct a RunningTransactions snapshot representing a shut
@@ -6006,6 +6007,9 @@ StartupXLOG(void)
60066007
running.subxid_overflow= false;
60076008
running.nextXid=checkPoint.nextXid;
60086009
running.oldestRunningXid=oldestActiveXID;
6010+
latestCompletedXid=checkPoint.nextXid;
6011+
TransactionIdRetreat(latestCompletedXid);
6012+
running.latestCompletedXid=latestCompletedXid;
60096013
running.xids=xids;
60106014

60116015
ProcArrayApplyRecoveryInfo(&running);
@@ -6154,8 +6158,9 @@ StartupXLOG(void)
61546158
xlogctl->recoveryLastXTime=recoveryLastXTime;
61556159
SpinLockRelease(&xlogctl->info_lck);
61566160

6157-
/* In Hot Standby mode, keep track of XIDs we've seen */
6158-
if (InHotStandby&&TransactionIdIsValid(record->xl_xid))
6161+
/* If we are attempting to enter Hot Standby mode, process XIDs we see */
6162+
if (standbyState >=STANDBY_INITIALIZED&&
6163+
TransactionIdIsValid(record->xl_xid))
61596164
RecordKnownAssignedTransactionIds(record->xl_xid);
61606165

61616166
RmgrTable[record->xl_rmid].rm_redo(EndRecPtr,record);
@@ -7803,6 +7808,7 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record)
78037808
TransactionId*xids;
78047809
intnxids;
78057810
TransactionIdoldestActiveXID;
7811+
TransactionIdlatestCompletedXid;
78067812
RunningTransactionsDatarunning;
78077813

78087814
oldestActiveXID=PrescanPreparedTransactions(&xids,&nxids);
@@ -7817,6 +7823,9 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record)
78177823
running.subxid_overflow= false;
78187824
running.nextXid=checkPoint.nextXid;
78197825
running.oldestRunningXid=oldestActiveXID;
7826+
latestCompletedXid=checkPoint.nextXid;
7827+
TransactionIdRetreat(latestCompletedXid);
7828+
running.latestCompletedXid=latestCompletedXid;
78207829
running.xids=xids;
78217830

78227831
ProcArrayApplyRecoveryInfo(&running);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp