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

Commit69e7235

Browse files
committed
Fix commit timestamp initialization
This module needs explicit initialization in order to replay WAL recordsin recovery, but we had broken this recently following changes to makeother (stranger) scenarios work correctly. To fix, rework theinitialization sequence so that it always takes place before WAL replaycommences for both master and standby.I could have gone for a more localized fix that just added a "startup"call for the master server, but it seemed better to restructure theexisting callers as well so that the whole thing made more sense. As adrawback, there is more control logic in xlog.c now than previously, butdoing otherwise meant passing down the ControlFile flag, which seemeduglier as a whole.This also meant adding a check to not re-execute ActivateCommitTs if ithad already been called.Reported by Fujii Masao.Backpatch to 9.5.
1 parenta351705 commit69e7235

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

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

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -545,19 +545,11 @@ ZeroCommitTsPage(int pageno, bool writeXlog)
545545
/*
546546
* This must be called ONCE during postmaster or standalone-backend startup,
547547
* after StartupXLOG has initialized ShmemVariableCache->nextXid.
548-
*
549-
* Caller may choose to enable the feature even when it is turned off in the
550-
* configuration.
551548
*/
552549
void
553-
StartupCommitTs(boolenabled)
550+
StartupCommitTs(void)
554551
{
555-
/*
556-
* If the module is not enabled, there's nothing to do here. The module
557-
* could still be activated from elsewhere.
558-
*/
559-
if (enabled)
560-
ActivateCommitTs();
552+
ActivateCommitTs();
561553
}
562554

563555
/*
@@ -570,9 +562,17 @@ CompleteCommitTsInitialization(void)
570562
/*
571563
* If the feature is not enabled, turn it off for good. This also removes
572564
* any leftover data.
565+
*
566+
* Conversely, we activate the module if the feature is enabled. This is
567+
* not necessary in a master system because we already did it earlier, but
568+
* if we're in a standby server that got promoted which had the feature
569+
* enabled and was following a master that had the feature disabled, this
570+
* is where we turn it on locally.
573571
*/
574572
if (!track_commit_timestamp)
575573
DeactivateCommitTs();
574+
else
575+
ActivateCommitTs();
576576
}
577577

578578
/*
@@ -591,6 +591,9 @@ CommitTsParameterChange(bool newvalue, bool oldvalue)
591591
*
592592
* If the module is disabled in the master, disable it here too, unless
593593
* the module is enabled locally.
594+
*
595+
* Note this only runs in the recovery process, so an unlocked read is
596+
* fine.
594597
*/
595598
if (newvalue)
596599
{
@@ -620,8 +623,20 @@ CommitTsParameterChange(bool newvalue, bool oldvalue)
620623
staticvoid
621624
ActivateCommitTs(void)
622625
{
623-
TransactionIdxid=ShmemVariableCache->nextXid;
624-
intpageno=TransactionIdToCTsPage(xid);
626+
TransactionIdxid;
627+
intpageno;
628+
629+
/* If we've done this already, there's nothing to do */
630+
LWLockAcquire(CommitTsLock,LW_EXCLUSIVE);
631+
if (commitTsShared->commitTsActive)
632+
{
633+
LWLockRelease(CommitTsLock);
634+
return;
635+
}
636+
LWLockRelease(CommitTsLock);
637+
638+
xid=ShmemVariableCache->nextXid;
639+
pageno=TransactionIdToCTsPage(xid);
625640

626641
/*
627642
* Re-Initialize our idea of the latest page number.

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6338,6 +6338,14 @@ StartupXLOG(void)
63386338
*/
63396339
StartupMultiXact();
63406340

6341+
/*
6342+
* Ditto commit timestamps. In a standby, we do it if setting is enabled
6343+
* in ControlFile; in a master we base the decision on the GUC itself.
6344+
*/
6345+
if (ArchiveRecoveryRequested ?
6346+
ControlFile->track_commit_timestamp :track_commit_timestamp)
6347+
StartupCommitTs();
6348+
63416349
/*
63426350
* Recover knowledge about replay progress of known replication partners.
63436351
*/
@@ -6565,16 +6573,11 @@ StartupXLOG(void)
65656573
ProcArrayInitRecovery(ShmemVariableCache->nextXid);
65666574

65676575
/*
6568-
* Startup commit log, commit timestampand subtrans only.
6569-
*MultiXact has already been started up and other SLRUs are not
6576+
* Startup commit logand subtrans only. MultiXact and commit
6577+
*timestamp have already been started up and other SLRUs are not
65706578
* maintained during recovery and need not be started yet.
6571-
*
6572-
* For commit timestamps, we do this based on the control file
6573-
* info: in a standby, we want to drive it off the state of the
6574-
* master, not local configuration.
65756579
*/
65766580
StartupCLOG();
6577-
StartupCommitTs(ControlFile->track_commit_timestamp);
65786581
StartupSUBTRANS(oldestActiveXID);
65796582

65806583
/*
@@ -7337,13 +7340,12 @@ StartupXLOG(void)
73377340
LWLockRelease(ProcArrayLock);
73387341

73397342
/*
7340-
* Start up the commit log, commit timestampand subtrans, if not already
7341-
*done for hot standby.
7343+
* Start up the commit logand subtrans, if not already done for hot
7344+
*standby. (commit timestamps are started below, if necessary.)
73427345
*/
73437346
if (standbyState==STANDBY_DISABLED)
73447347
{
73457348
StartupCLOG();
7346-
StartupCommitTs(track_commit_timestamp);
73477349
StartupSUBTRANS(oldestActiveXID);
73487350
}
73497351

‎src/include/access/commit_ts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern Size CommitTsShmemBuffers(void);
3434
externSizeCommitTsShmemSize(void);
3535
externvoidCommitTsShmemInit(void);
3636
externvoidBootStrapCommitTs(void);
37-
externvoidStartupCommitTs(boolenabled);
37+
externvoidStartupCommitTs(void);
3838
externvoidCommitTsParameterChange(boolxlrecvalue,boolpgcontrolvalue);
3939
externvoidCompleteCommitTsInitialization(void);
4040
externvoidShutdownCommitTs(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp