Skip to content

Commit 6e8af37

Browse files
committed
Remove legacy multixact truncation support.
In 9.5 and master there is no need to support legacy truncation. This is just committed separately to make it easier to backpatch the WAL logged multixact truncation to 9.3 and 9.4 if we later decide to do so. I bumped master's magic from 0xD086 to 0xD088 and 9.5's from 0xD085 to 0xD087 to avoid 9.5 reusing a value that has been in use on master while keeping the numbers increasing between major versions. Discussion: 20150621192409.GA4797@alap3.anarazel.de Backpatch: 9.5
1 parent bd7c348 commit 6e8af37

File tree

5 files changed

+17
-70
lines changed

5 files changed

+17
-70
lines changed

src/backend/access/transam/multixact.c

+14-63
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,6 @@ typedef struct MultiXactStateData
220220
MultiXactOffset oldestOffset;
221221
bool oldestOffsetKnown;
222222

223-
/*
224-
* True if a multixact truncation WAL record was replayed since the last
225-
* checkpoint. This is used to trigger 'legacy truncations', i.e. truncate
226-
* by looking at the data directory during WAL replay, when the primary is
227-
* too old to generate truncation records.
228-
*/
229-
bool sawTruncationInCkptCycle;
230-
231223
/* support for anti-wraparound measures */
232224
MultiXactId multiVacLimit;
233225
MultiXactId multiWarnLimit;
@@ -2381,28 +2373,7 @@ MultiXactAdvanceOldest(MultiXactId oldestMulti, Oid oldestMultiDB)
23812373
Assert(InRecovery);
23822374

23832375
if (MultiXactIdPrecedes(MultiXactState->oldestMultiXactId, oldestMulti))
2384-
{
2385-
/*
2386-
* If there has been a truncation on the master, detected by seeing a
2387-
* moving oldestMulti, without a corresponding truncation record, we
2388-
* know that the primary is still running an older version of postgres
2389-
* that doesn't yet log multixact truncations. So perform the
2390-
* truncation ourselves.
2391-
*/
2392-
if (!MultiXactState->sawTruncationInCkptCycle)
2393-
{
2394-
ereport(LOG,
2395-
(errmsg("performing legacy multixact truncation"),
2396-
errdetail("Legacy truncations are sometimes performed when replaying WAL from an older primary."),
2397-
errhint("Upgrade the primary, it is susceptible to data corruption.")));
2398-
TruncateMultiXact(oldestMulti, oldestMultiDB, true);
2399-
}
2400-
24012376
SetMultiXactIdLimit(oldestMulti, oldestMultiDB);
2402-
}
2403-
2404-
/* only looked at in the startup process, no lock necessary */
2405-
MultiXactState->sawTruncationInCkptCycle = false;
24062377
}
24072378

24082379
/*
@@ -2747,8 +2718,7 @@ find_multixact_start(MultiXactId multi, MultiXactOffset *result)
27472718
int slotno;
27482719
MultiXactOffset *offptr;
27492720

2750-
/* XXX: Remove || AmStartupProcess() after WAL page magic bump */
2751-
Assert(MultiXactState->finishedStartup || AmStartupProcess());
2721+
Assert(MultiXactState->finishedStartup);
27522722

27532723
pageno = MultiXactIdToOffsetPage(multi);
27542724
entryno = MultiXactIdToOffsetEntry(multi);
@@ -2946,18 +2916,15 @@ PerformOffsetsTruncation(MultiXactId oldestMulti, MultiXactId newOldestMulti)
29462916
* Remove all MultiXactOffset and MultiXactMember segments before the oldest
29472917
* ones still of interest.
29482918
*
2949-
* On a primary this is called as part of vacuum (via
2950-
* vac_truncate_clog()). During recovery truncation is normally done by
2951-
* replaying truncation WAL records instead of this routine; the exception is
2952-
* when replaying records from an older primary that doesn't yet generate
2953-
* truncation WAL records. In that case truncation is triggered by
2954-
* MultiXactAdvanceOldest().
2919+
* This is only called on a primary as part of vacuum (via
2920+
* vac_truncate_clog()). During recovery truncation is done by replaying
2921+
* truncation WAL records logged here.
29552922
*
29562923
* newOldestMulti is the oldest currently required multixact, newOldestMultiDB
29572924
* is one of the databases preventing newOldestMulti from increasing.
29582925
*/
29592926
void
2960-
TruncateMultiXact(MultiXactId newOldestMulti, Oid newOldestMultiDB, bool in_recovery)
2927+
TruncateMultiXact(MultiXactId newOldestMulti, Oid newOldestMultiDB)
29612928
{
29622929
MultiXactId oldestMulti;
29632930
MultiXactId nextMulti;
@@ -2967,13 +2934,8 @@ TruncateMultiXact(MultiXactId newOldestMulti, Oid newOldestMultiDB, bool in_reco
29672934
mxtruncinfo trunc;
29682935
MultiXactId earliest;
29692936

2970-
/*
2971-
* Need to allow being called in recovery for backwards compatibility,
2972-
* when an updated standby replays WAL generated by a non-updated primary.
2973-
*/
2974-
Assert(in_recovery || !RecoveryInProgress());
2975-
Assert(!in_recovery || AmStartupProcess());
2976-
Assert(in_recovery || MultiXactState->finishedStartup);
2937+
Assert(!RecoveryInProgress());
2938+
Assert(MultiXactState->finishedStartup);
29772939

29782940
/*
29792941
* We can only allow one truncation to happen at once. Otherwise parts of
@@ -3086,22 +3048,15 @@ TruncateMultiXact(MultiXactId newOldestMulti, Oid newOldestMultiDB, bool in_reco
30863048
* Prevent checkpoints from being scheduled concurrently. This is critical
30873049
* because otherwise a truncation record might not be replayed after a
30883050
* crash/basebackup, even though the state of the data directory would
3089-
* require it. It's not possible (startup process doesn't have a PGXACT
3090-
* entry), and not needed, to do this during recovery, when performing an
3091-
* old-style truncation, though. There the entire scheduling depends on
3092-
* the replayed WAL records which be the same after a possible crash.
3051+
* require it.
30933052
*/
3094-
if (!in_recovery)
3095-
{
3096-
Assert(!MyPgXact->delayChkpt);
3097-
MyPgXact->delayChkpt = true;
3098-
}
3053+
Assert(!MyPgXact->delayChkpt);
3054+
MyPgXact->delayChkpt = true;
30993055

31003056
/* WAL log truncation */
3101-
if (!in_recovery)
3102-
WriteMTruncateXlogRec(newOldestMultiDB,
3103-
oldestMulti, newOldestMulti,
3104-
oldestOffset, newOldestOffset);
3057+
WriteMTruncateXlogRec(newOldestMultiDB,
3058+
oldestMulti, newOldestMulti,
3059+
oldestOffset, newOldestOffset);
31053060

31063061
/*
31073062
* Update in-memory limits before performing the truncation, while inside
@@ -3122,8 +3077,7 @@ TruncateMultiXact(MultiXactId newOldestMulti, Oid newOldestMultiDB, bool in_reco
31223077
/* Then offsets */
31233078
PerformOffsetsTruncation(oldestMulti, newOldestMulti);
31243079

3125-
if (!in_recovery)
3126-
MyPgXact->delayChkpt = false;
3080+
MyPgXact->delayChkpt = false;
31273081

31283082
END_CRIT_SECTION();
31293083
LWLockRelease(MultiXactTruncationLock);
@@ -3371,9 +3325,6 @@ multixact_redo(XLogReaderState *record)
33713325
PerformOffsetsTruncation(xlrec.startTruncOff, xlrec.endTruncOff);
33723326

33733327
LWLockRelease(MultiXactTruncationLock);
3374-
3375-
/* only looked at in the startup process, no lock necessary */
3376-
MultiXactState->sawTruncationInCkptCycle = true;
33773328
}
33783329
else
33793330
elog(PANIC, "multixact_redo: unknown op code %u", info);

src/backend/access/transam/xlog.c

-4
Original file line numberDiff line numberDiff line change
@@ -9233,10 +9233,6 @@ xlog_redo(XLogReaderState *record)
92339233
MultiXactSetNextMXact(checkPoint.nextMulti,
92349234
checkPoint.nextMultiOffset);
92359235

9236-
/*
9237-
* NB: This may perform multixact truncation when replaying WAL
9238-
* generated by an older primary.
9239-
*/
92409236
MultiXactAdvanceOldest(checkPoint.oldestMulti,
92419237
checkPoint.oldestMultiDB);
92429238
SetTransactionIdLimit(checkPoint.oldestXid, checkPoint.oldestXidDB);

src/backend/commands/vacuum.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ vac_truncate_clog(TransactionId frozenXID,
11411141
*/
11421142
TruncateCLOG(frozenXID);
11431143
TruncateCommitTs(frozenXID, true);
1144-
TruncateMultiXact(minMulti, minmulti_datoid, false);
1144+
TruncateMultiXact(minMulti, minmulti_datoid);
11451145

11461146
/*
11471147
* Update the wrap limit for GetNewTransactionId and creation of new

src/include/access/multixact.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ extern void MultiXactGetCheckptMulti(bool is_shutdown,
135135
Oid *oldestMultiDB);
136136
extern void CheckPointMultiXact(void);
137137
extern MultiXactId GetOldestMultiXactId(void);
138-
extern void TruncateMultiXact(MultiXactId oldestMulti, Oid oldestMultiDB, bool in_recovery);
138+
extern void TruncateMultiXact(MultiXactId oldestMulti, Oid oldestMultiDB);
139139
extern void MultiXactSetNextMXact(MultiXactId nextMulti,
140140
MultiXactOffset nextMultiOffset);
141141
extern void MultiXactAdvanceNextMXact(MultiXactId minMulti,

src/include/access/xlog_internal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/*
3232
* Each page of XLOG file has a header like this:
3333
*/
34-
#define XLOG_PAGE_MAGIC 0xD085 /* can be used as WAL version indicator */
34+
#define XLOG_PAGE_MAGIC 0xD087 /* can be used as WAL version indicator */
3535

3636
typedef struct XLogPageHeaderData
3737
{

0 commit comments

Comments
 (0)