aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2019-02-12 01:12:52 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2019-02-12 01:12:52 -0500
commit2a0edae47af453ef27ef7ff013beb7201f8549d8 (patch)
tree05df1ef6a821411757528fc9304935fad6c07e42
parenta093e1444955d6ee1d7cfda68932c19d5613d87a (diff)
downloadpostgresql-2a0edae47af453ef27ef7ff013beb7201f8549d8.tar.gz
postgresql-2a0edae47af453ef27ef7ff013beb7201f8549d8.zip
Fix erroneous error reports in snapbuild.c.
It's pretty unhelpful to report the wrong file name in a complaint about syscall failure, but SnapBuildSerialize managed to do that twice in a span of 50 lines. Also fix half a dozen missing or poorly-chosen errcode assignments; that's mostly cosmetic, but still wrong. Noted while studying recent failures on buildfarm member nightjar. I'm not sure whether those reports are actually giving the wrong filename, because there are two places here with identically spelled error messages. The other one is specifically coded not to report ENOENT, but if it's this one, how could we be getting ENOENT from open() with O_CREAT? Need to sit back and await results. However, these ereports are clearly broken from birth, so back-patch.
-rw-r--r--src/backend/replication/logical/snapbuild.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c
index 67e939883bc..df820057802 100644
--- a/src/backend/replication/logical/snapbuild.c
+++ b/src/backend/replication/logical/snapbuild.c
@@ -1522,7 +1522,8 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
if (ret != 0 && errno != ENOENT)
ereport(ERROR,
- (errmsg("could not stat file \"%s\": %m", path)));
+ (errcode_for_file_access(),
+ errmsg("could not stat file \"%s\": %m", path)));
else if (ret == 0)
{
@@ -1564,7 +1565,7 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
if (unlink(tmppath) != 0 && errno != ENOENT)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not remove file \"%s\": %m", path)));
+ errmsg("could not remove file \"%s\": %m", tmppath)));
needed_length = sizeof(SnapBuildOnDisk) +
sizeof(TransactionId) * builder->committed.xcnt;
@@ -1608,7 +1609,8 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
S_IRUSR | S_IWUSR);
if (fd < 0)
ereport(ERROR,
- (errmsg("could not open file \"%s\": %m", path)));
+ (errcode_for_file_access(),
+ errmsg("could not open file \"%s\": %m", tmppath)));
errno = 0;
pgstat_report_wait_start(WAIT_EVENT_SNAPBUILD_WRITE);
@@ -1740,12 +1742,14 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
if (ondisk.magic != SNAPBUILD_MAGIC)
ereport(ERROR,
- (errmsg("snapbuild state file \"%s\" has wrong magic number: %u instead of %u",
+ (errcode(ERRCODE_DATA_CORRUPTED),
+ errmsg("snapbuild state file \"%s\" has wrong magic number: %u instead of %u",
path, ondisk.magic, SNAPBUILD_MAGIC)));
if (ondisk.version != SNAPBUILD_VERSION)
ereport(ERROR,
- (errmsg("snapbuild state file \"%s\" has unsupported version: %u instead of %u",
+ (errcode(ERRCODE_DATA_CORRUPTED),
+ errmsg("snapbuild state file \"%s\" has unsupported version: %u instead of %u",
path, ondisk.version, SNAPBUILD_VERSION)));
INIT_CRC32C(checksum);
@@ -1816,7 +1820,7 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
/* verify checksum of what we've read */
if (!EQ_CRC32C(checksum, ondisk.checksum))
ereport(ERROR,
- (errcode_for_file_access(),
+ (errcode(ERRCODE_DATA_CORRUPTED),
errmsg("checksum mismatch for snapbuild state file \"%s\": is %u, should be %u",
path, checksum, ondisk.checksum)));