Allow_TLI_Increment_without_Checkpoint_20120618.patch
text/x-patch
Filename: Allow_TLI_Increment_without_Checkpoint_20120618.patch
Type: text/x-patch
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/backend/access/transam/xlog.c | 9 | 10 |
| src/bin/pg_controldata/pg_controldata.c | 2 | 0 |
| src/include/catalog/pg_control.h | 2 | 1 |
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 0d68760..70b4972 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -5276,6 +5276,7 @@ BootStrapXLOG(void)
ControlFile->system_identifier = sysidentifier;
ControlFile->state = DB_SHUTDOWNED;
ControlFile->time = checkPoint.time;
+ ControlFile->latestTLI = ThisTimeLineID;
ControlFile->checkPoint = checkPoint.redo;
ControlFile->checkPointCopy = checkPoint;
@@ -6083,7 +6084,7 @@ StartupXLOG(void)
* Initialize on the assumption we want to recover to the same timeline
* that's active according to pg_control.
*/
- recoveryTargetTLI = ControlFile->checkPointCopy.ThisTimeLineID;
+ recoveryTargetTLI = ControlFile->latestTLI;
/*
* Check for recovery control file, and if so set up state for offline
@@ -6100,11 +6101,11 @@ StartupXLOG(void)
* timeline.
*/
if (!list_member_int(expectedTLIs,
- (int) ControlFile->checkPointCopy.ThisTimeLineID))
+ (int) ControlFile->latestTLI))
ereport(FATAL,
(errmsg("requested timeline %u is not a child of database system timeline %u",
recoveryTargetTLI,
- ControlFile->checkPointCopy.ThisTimeLineID)));
+ ControlFile->latestTLI)));
/*
* Save the selected recovery target timeline ID and
@@ -6791,9 +6792,12 @@ StartupXLOG(void)
*
* In a normal crash recovery, we can just extend the timeline we were in.
*/
+
+ ThisTimeLineID = findNewestTimeLine(recoveryTargetTLI);
+
if (InArchiveRecovery)
{
- ThisTimeLineID = findNewestTimeLine(recoveryTargetTLI) + 1;
+ ThisTimeLineID++;
ereport(LOG,
(errmsg("selected new timeline ID: %u", ThisTimeLineID)));
writeTimeLineHistory(ThisTimeLineID, recoveryTargetTLI,
@@ -6946,6 +6950,7 @@ StartupXLOG(void)
LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
ControlFile->state = DB_IN_PRODUCTION;
ControlFile->time = (pg_time_t) time(NULL);
+ ControlFile->latestTLI = ThisTimeLineID;
UpdateControlFile();
LWLockRelease(ControlFileLock);
@@ -8710,12 +8715,6 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record)
SpinLockRelease(&xlogctl->info_lck);
}
- /* TLI should not change in an on-line checkpoint */
- if (checkPoint.ThisTimeLineID != ThisTimeLineID)
- ereport(PANIC,
- (errmsg("unexpected timeline ID %u (should be %u) in checkpoint record",
- checkPoint.ThisTimeLineID, ThisTimeLineID)));
-
RecoveryRestartPoint(&checkPoint);
}
else if (info == XLOG_NOOP)
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 38c263c..7f2cdb8 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -192,6 +192,8 @@ main(int argc, char *argv[])
dbState(ControlFile.state));
printf(_("pg_control last modified: %s\n"),
pgctime_str);
+ printf(_("Latest timeline ID: %d\n"),
+ ControlFile.latestTLI);
printf(_("Latest checkpoint location: %X/%X\n"),
ControlFile.checkPoint.xlogid,
ControlFile.checkPoint.xrecoff);
diff --git a/src/include/catalog/pg_control.h b/src/include/catalog/pg_control.h
index 5cff396..c78d483 100644
--- a/src/include/catalog/pg_control.h
+++ b/src/include/catalog/pg_control.h
@@ -21,7 +21,7 @@
/* Version identifier for this pg_control format */
-#define PG_CONTROL_VERSION 922
+#define PG_CONTROL_VERSION 923
/*
* Body of CheckPoint XLOG records. This is declared here because we keep
@@ -116,6 +116,7 @@ typedef struct ControlFileData
*/
DBState state; /* see enum above */
pg_time_t time; /* time stamp of last pg_control update */
+ TimeLineID latestTLI; /* latest TLI we reached */
XLogRecPtr checkPoint; /* last check point record ptr */
XLogRecPtr prevCheckPoint; /* previous check point record ptr */