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

Commit 232a8e2

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 b7ec820 commit 232a8e2

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/backend/replication/logical/snapbuild.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,8 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
15211521

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

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

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

16111613
errno = 0;
16121614
pgstat_report_wait_start(WAIT_EVENT_SNAPBUILD_WRITE);
@@ -1747,12 +1749,14 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
17471749

17481750
if (ondisk.magic != SNAPBUILD_MAGIC)
17491751
ereport(ERROR,
1750-
(errmsg("snapbuild state file \"%s\" has wrong magic number: %u instead of %u",
1752+
(errcode(ERRCODE_DATA_CORRUPTED),
1753+
errmsg("snapbuild state file \"%s\" has wrong magic number: %u instead of %u",
17511754
path, ondisk.magic, SNAPBUILD_MAGIC)));
17521755

17531756
if (ondisk.version != SNAPBUILD_VERSION)
17541757
ereport(ERROR,
1755-
(errmsg("snapbuild state file \"%s\" has unsupported version: %u instead of %u",
1758+
(errcode(ERRCODE_DATA_CORRUPTED),
1759+
errmsg("snapbuild state file \"%s\" has unsupported version: %u instead of %u",
17561760
path, ondisk.version, SNAPBUILD_VERSION)));
17571761

17581762
INIT_CRC32C(checksum);
@@ -1847,7 +1851,7 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
18471851
/* verify checksum of what we've read */
18481852
if (!EQ_CRC32C(checksum, ondisk.checksum))
18491853
ereport(ERROR,
1850-
(errcode_for_file_access(),
1854+
(errcode(ERRCODE_DATA_CORRUPTED),
18511855
errmsg("checksum mismatch for snapbuild state file \"%s\": is %u, should be %u",
18521856
path, checksum, ondisk.checksum)));
18531857

0 commit comments

Comments
 (0)