From e41d0a1090b75fed4c033c2e404643382348f88e Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Mon, 23 Jul 2018 09:37:36 +0900 Subject: Add proper errcodes to new error messages for read() failures Those would use the default ERRCODE_INTERNAL_ERROR, but for foreseeable failures an errcode ought to be set, ERRCODE_DATA_CORRUPTED making the most sense here. While on the way, fix one errcode_for_file_access missing in origin.c since the code has been created, and remove one assignment of errno to 0 before calling read(), as this was around to fit with what was present before 811b6e36 where errno would not be set when not enough bytes are read. I have noticed the first one, and Tom has pinged me about the second one. Author: Michael Paquier Reported-by: Tom Lane Discussion: https://postgr.es/m/27265.1531925836@sss.pgh.pa.us --- src/backend/access/transam/xlog.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/backend/access/transam/xlog.c') diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 9f8ae9dc756..335b4a573d8 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -3412,7 +3412,6 @@ XLogFileCopy(XLogSegNo destsegno, TimeLineID srcTLI, XLogSegNo srcsegno, if (nread > sizeof(buffer)) nread = sizeof(buffer); - errno = 0; pgstat_report_wait_start(WAIT_EVENT_WAL_COPY_READ); r = read(srcfd, buffer, nread); if (r != nread) @@ -3424,7 +3423,8 @@ XLogFileCopy(XLogSegNo destsegno, TimeLineID srcTLI, XLogSegNo srcsegno, path))); else ereport(ERROR, - (errmsg("could not read file \"%s\": read %d of %zu", + (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("could not read file \"%s\": read %d of %zu", path, r, (Size) nread))); } pgstat_report_wait_end(); @@ -4564,7 +4564,8 @@ ReadControlFile(void) XLOG_CONTROL_FILE))); else ereport(PANIC, - (errmsg("could not read file \"%s\": read %d of %zu", + (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("could not read file \"%s\": read %d of %zu", XLOG_CONTROL_FILE, r, sizeof(ControlFileData)))); } pgstat_report_wait_end(); @@ -11829,7 +11830,8 @@ retry: } else ereport(emode_for_corrupt_record(emode, targetPagePtr + reqLen), - (errmsg("could not read from log segment %s, offset %u: read %d of %zu", + (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("could not read from log segment %s, offset %u: read %d of %zu", fname, readOff, r, (Size) XLOG_BLCKSZ))); goto next_record_is_invalid; } -- cgit v1.2.3