Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a4c6a73

Browse files
committed
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.
1 parent 6af8c79 commit a4c6a73

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/backend/replication/logical/snapbuild.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,8 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
15221522

15231523
if (ret != 0 && errno != ENOENT)
15241524
ereport(ERROR,
1525-
(errmsg("could not stat file \"%s\": %m", path)));
1525+
(errcode_for_file_access(),
1526+
errmsg("could not stat file \"%s\": %m", path)));
15261527

15271528
else if (ret == 0)
15281529
{
@@ -1564,7 +1565,7 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
15641565
if (unlink(tmppath) != 0 && errno != ENOENT)
15651566
ereport(ERROR,
15661567
(errcode_for_file_access(),
1567-
errmsg("could not remove file \"%s\": %m", path)));
1568+
errmsg("could not remove file \"%s\": %m", tmppath)));
15681569

15691570
needed_length = sizeof(SnapBuildOnDisk) +
15701571
sizeof(TransactionId) * builder->committed.xcnt;
@@ -1607,7 +1608,8 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
16071608
O_CREAT | O_EXCL | O_WRONLY | PG_BINARY);
16081609
if (fd < 0)
16091610
ereport(ERROR,
1610-
(errmsg("could not open file \"%s\": %m", path)));
1611+
(errcode_for_file_access(),
1612+
errmsg("could not open file \"%s\": %m", tmppath)));
16111613

16121614
errno = 0;
16131615
pgstat_report_wait_start(WAIT_EVENT_SNAPBUILD_WRITE);
@@ -1739,12 +1741,14 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
17391741

17401742
if (ondisk.magic != SNAPBUILD_MAGIC)
17411743
ereport(ERROR,
1742-
(errmsg("snapbuild state file \"%s\" has wrong magic number: %u instead of %u",
1744+
(errcode(ERRCODE_DATA_CORRUPTED),
1745+
errmsg("snapbuild state file \"%s\" has wrong magic number: %u instead of %u",
17431746
path, ondisk.magic, SNAPBUILD_MAGIC)));
17441747

17451748
if (ondisk.version != SNAPBUILD_VERSION)
17461749
ereport(ERROR,
1747-
(errmsg("snapbuild state file \"%s\" has unsupported version: %u instead of %u",
1750+
(errcode(ERRCODE_DATA_CORRUPTED),
1751+
errmsg("snapbuild state file \"%s\" has unsupported version: %u instead of %u",
17481752
path, ondisk.version, SNAPBUILD_VERSION)));
17491753

17501754
INIT_CRC32C(checksum);
@@ -1815,7 +1819,7 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
18151819
/* verify checksum of what we've read */
18161820
if (!EQ_CRC32C(checksum, ondisk.checksum))
18171821
ereport(ERROR,
1818-
(errcode_for_file_access(),
1822+
(errcode(ERRCODE_DATA_CORRUPTED),
18191823
errmsg("checksum mismatch for snapbuild state file \"%s\": is %u, should be %u",
18201824
path, checksum, ondisk.checksum)));
18211825

0 commit comments

Comments
 (0)