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
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)
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();
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();
}
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;
}
{
if (readBytes < 0)
ereport(PANIC,
- (errmsg("could not read file \"%s\": %m",
+ (errcode_for_file_access(),
+ errmsg("could not read file \"%s\": %m",
path)));
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",
path, readBytes, sizeof(magic))));
}
COMP_CRC32C(crc, &magic, sizeof(magic));
}
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, readBytes,
(Size) SnapBuildOnDiskConstantSize)));
}
}
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, readBytes, sizeof(SnapBuild))));
}
COMP_CRC32C(checksum, &ondisk.builder, sizeof(SnapBuild));
}
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, readBytes, sz)));
}
COMP_CRC32C(checksum, ondisk.builder.was_running.was_xip, sz);
}
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, readBytes, sz)));
}
COMP_CRC32C(checksum, ondisk.builder.committed.xip, sz);
errmsg("could not read file \"%s\": %m", path)));
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",
path, readBytes,
(Size) ReplicationSlotOnDiskConstantSize)));
}
errmsg("could not read file \"%s\": %m", path)));
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",
path, readBytes, (Size) cp.length)));
}
path)));
else if (nread == 0)
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, nread, (Size) bytesleft)));
pq_sendbytes(&buf, rbuf, nread);
else if (readbytes == 0)
{
ereport(ERROR,
- (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",
XLogFileNameP(curFileTimeLine, sendSegNo),
sendOff, readbytes, (Size) segbytes)));
}
errmsg("could not read file \"%s\": %m", mapfilename)));
else
ereport(FATAL,
- (errmsg("could not read file \"%s\": read %d of %zu",
+ (errcode(ERRCODE_DATA_CORRUPTED),
+ errmsg("could not read file \"%s\": read %d of %zu",
mapfilename, r, sizeof(RelMapFile))));
}
pgstat_report_wait_end();
else
#ifndef FRONTEND
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",
ControlFilePath, r, sizeof(ControlFileData))));
#else
{