Skip to content

Add error codes to PANIC/FATAL error reports. #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 34 additions & 23 deletions src/backend/access/transam/xlogrecovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,21 +630,19 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
if (!ReadRecord(xlogprefetcher, LOG, false,
checkPoint.ThisTimeLineID))
ereport(FATAL,
(errmsg("could not find redo location referenced by checkpoint record"),
errhint("If you are restoring from a backup, touch \"%s/recovery.signal\" or \"%s/standby.signal\" and add required recovery options.\n"
"If you are not restoring from a backup, try removing the file \"%s/backup_label\".\n"
"Be careful: removing \"%s/backup_label\" will result in a corrupt cluster if restoring from a backup.",
DataDir, DataDir, DataDir, DataDir)));
(errcode(ERRCODE_CLUSTER_CORRUPTED),
errmsg("could not find redo location referenced by checkpoint record"),
errhint("If not found, touch \"%s/recovery.signal\" or \"%s/standby.signal\" and add required recovery options.\n",
DataDir, DataDir)));
}
}
else
{
ereport(FATAL,
(errmsg("could not locate required checkpoint record"),
errhint("If you are restoring from a backup, touch \"%s/recovery.signal\" or \"%s/standby.signal\" and add required recovery options.\n"
"If you are not restoring from a backup, try removing the file \"%s/backup_label\".\n"
"Be careful: removing \"%s/backup_label\" will result in a corrupt cluster if restoring from a backup.",
DataDir, DataDir, DataDir, DataDir)));
(errcode(ERRCODE_CLUSTER_CORRUPTED),
errmsg("could not locate required checkpoint record"),
errhint("If not found, touch \"%s/recovery.signal\" or \"%s/standby.signal\" and add required recovery options.\n",
DataDir, DataDir)));
wasShutdown = false; /* keep compiler quiet */
}

Expand Down Expand Up @@ -764,7 +762,8 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
* simplify processing around checkpoints.
*/
ereport(PANIC,
(errmsg("could not locate a valid checkpoint record")));
(errcode(ERRCODE_CLUSTER_CORRUPTED),
errmsg("could not locate a valid checkpoint record")));
}
memcpy(&checkPoint, XLogRecGetData(xlogreader), sizeof(CheckPoint));
wasShutdown = ((record->xl_info & ~XLR_INFO_MASK) == XLOG_CHECKPOINT_SHUTDOWN);
Expand Down Expand Up @@ -817,7 +816,8 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
*/
switchpoint = tliSwitchPoint(ControlFile->checkPointCopy.ThisTimeLineID, expectedTLEs, NULL);
ereport(FATAL,
(errmsg("requested timeline %u is not a child of this server's history",
(errcode(ERRCODE_TIMELINE_INCONSISTENT),
errmsg("requested timeline %u is not a child of this server's history",
recoveryTargetTLI),
errdetail("Latest checkpoint is at %X/%X on timeline %u, but in the history of the requested timeline, the server forked off from that timeline at %X/%X.",
LSN_FORMAT_ARGS(ControlFile->checkPoint),
Expand All @@ -833,7 +833,8 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
tliOfPointInHistory(ControlFile->minRecoveryPoint - 1, expectedTLEs) !=
ControlFile->minRecoveryPointTLI)
ereport(FATAL,
(errmsg("requested timeline %u does not contain minimum recovery point %X/%X on timeline %u",
(errcode(ERRCODE_TIMELINE_INCONSISTENT),
errmsg("requested timeline %u does not contain minimum recovery point %X/%X on timeline %u",
recoveryTargetTLI,
LSN_FORMAT_ARGS(ControlFile->minRecoveryPoint),
ControlFile->minRecoveryPointTLI)));
Expand Down Expand Up @@ -861,12 +862,14 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
checkPoint.newestCommitTsXid)));
if (!TransactionIdIsNormal(XidFromFullTransactionId(checkPoint.nextXid)))
ereport(PANIC,
(errmsg("invalid next transaction ID")));
(errcode(ERRCODE_CLUSTER_CORRUPTED),
errmsg("invalid next transaction ID")));

/* sanity check */
if (checkPoint.redo > CheckPointLoc)
ereport(PANIC,
(errmsg("invalid redo in checkpoint record")));
(errcode(ERRCODE_CLUSTER_CORRUPTED),
errmsg("invalid redo in checkpoint record")));

/*
* Check whether we need to force recovery from WAL. If it appears to
Expand All @@ -877,7 +880,8 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
{
if (wasShutdown)
ereport(PANIC,
(errmsg("invalid redo record in shutdown checkpoint")));
(errcode(ERRCODE_CLUSTER_CORRUPTED),
errmsg("invalid redo record in shutdown checkpoint")));
InRecovery = true;
}
else if (ControlFile->state != DB_SHUTDOWNED)
Expand Down Expand Up @@ -953,7 +957,8 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
if (dbstate_at_startup != DB_IN_ARCHIVE_RECOVERY &&
dbstate_at_startup != DB_SHUTDOWNED_IN_RECOVERY)
ereport(FATAL,
(errmsg("backup_label contains data inconsistent with control file"),
(errcode(ERRCODE_CLUSTER_CORRUPTED),
errmsg("backup_label contains data inconsistent with control file"),
errhint("This means that the backup is corrupted and you will "
"have to use another backup for recovery.")));
ControlFile->backupEndPoint = ControlFile->minRecoveryPoint;
Expand Down Expand Up @@ -1664,7 +1669,8 @@ PerformWalRecovery(void)
if (record->xl_rmid != RM_XLOG_ID ||
(record->xl_info & ~XLR_INFO_MASK) != XLOG_CHECKPOINT_REDO)
ereport(FATAL,
(errmsg("unexpected record type found at redo point %X/%X",
(errcode(ERRCODE_CLUSTER_CORRUPTED),
errmsg("unexpected record type found at redo point %X/%X",
LSN_FORMAT_ARGS(xlogreader->ReadRecPtr))));
}
else
Expand Down Expand Up @@ -1792,7 +1798,8 @@ PerformWalRecovery(void)
{
if (!reachedConsistency)
ereport(FATAL,
(errmsg("requested recovery stop point is before consistent recovery point")));
(errcode(ERRCODE_DATA_CORRUPTED),
errmsg("requested recovery stop point is before consistent recovery point")));

/*
* This is the last point where we can restart recovery with a new
Expand Down Expand Up @@ -1850,7 +1857,8 @@ PerformWalRecovery(void)
recoveryTarget != RECOVERY_TARGET_UNSET &&
!reachedRecoveryTarget)
ereport(FATAL,
(errmsg("recovery ended before configured recovery target was reached")));
(errcode(ERRCODE_DATA_CORRUPTED),
errmsg("recovery ended before configured recovery target was reached")));
}

/*
Expand Down Expand Up @@ -2324,7 +2332,8 @@ checkTimeLineSwitch(XLogRecPtr lsn, TimeLineID newTLI, TimeLineID prevTLI,
/* Check that the record agrees on what the current (old) timeline is */
if (prevTLI != replayTLI)
ereport(PANIC,
(errmsg("unexpected previous timeline ID %u (current timeline ID %u) in checkpoint record",
(errcode(ERRCODE_CLUSTER_CORRUPTED),
errmsg("unexpected previous timeline ID %u (current timeline ID %u) in checkpoint record",
prevTLI, replayTLI)));

/*
Expand All @@ -2333,7 +2342,8 @@ checkTimeLineSwitch(XLogRecPtr lsn, TimeLineID newTLI, TimeLineID prevTLI,
*/
if (newTLI < replayTLI || !tliInHistory(newTLI, expectedTLEs))
ereport(PANIC,
(errmsg("unexpected timeline ID %u (after %u) in checkpoint record",
(errcode(ERRCODE_CLUSTER_CORRUPTED),
errmsg("unexpected timeline ID %u (after %u) in checkpoint record",
newTLI, replayTLI)));

/*
Expand All @@ -2349,7 +2359,8 @@ checkTimeLineSwitch(XLogRecPtr lsn, TimeLineID newTLI, TimeLineID prevTLI,
lsn < minRecoveryPoint &&
newTLI > minRecoveryPointTLI)
ereport(PANIC,
(errmsg("unexpected timeline ID %u in checkpoint record, before reaching minimum recovery point %X/%X on timeline %u",
(errcode(ERRCODE_CLUSTER_CORRUPTED),
errmsg("unexpected timeline ID %u in checkpoint record, before reaching minimum recovery point %X/%X on timeline %u",
newTLI,
LSN_FORMAT_ARGS(minRecoveryPoint),
minRecoveryPointTLI)));
Expand Down
2 changes: 2 additions & 0 deletions src/backend/utils/errcodes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,12 @@ P0001 E ERRCODE_RAISE_EXCEPTION rai
P0002 E ERRCODE_NO_DATA_FOUND no_data_found
P0003 E ERRCODE_TOO_MANY_ROWS too_many_rows
P0004 E ERRCODE_ASSERT_FAILURE assert_failure
P0005 E ERRCODE_TIMELINE_INCONSISTENT timeline_inconsistent

Section: Class XX - Internal Error

# this is for "can't-happen" conditions and software bugs (PostgreSQL-specific error class)
XX000 E ERRCODE_INTERNAL_ERROR internal_error
XX001 E ERRCODE_DATA_CORRUPTED data_corrupted
XX002 E ERRCODE_INDEX_CORRUPTED index_corrupted
XX003 E ERRCODE_CLUSTER_CORRUPTED cluster_corrupted
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy