From fca7c4724e2dd4cd3edd1e59275e6b6ca2448bb3 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 6 Jan 2023 11:57:35 +0100 Subject: [PATCH v2 1/2] Fix some BufFileRead() error reporting Remove "%m" from error messages where errno would be bogus. Add short read byte counts where appropriate. This is equivalent to what was done in 7897e3bb902c557412645b82120f4d95f7474906, but some code was apparently developed concurrently to that and not updated accordingly. --- src/backend/backup/backup_manifest.c | 3 ++- src/backend/replication/logical/worker.c | 33 ++++++++++++++---------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/backend/backup/backup_manifest.c b/src/backend/backup/backup_manifest.c index 21ca2941dc..d325ef047a 100644 --- a/src/backend/backup/backup_manifest.c +++ b/src/backend/backup/backup_manifest.c @@ -371,7 +371,8 @@ SendBackupManifest(backup_manifest_info *manifest, bbsink *sink) if (rc != bytes_to_read) ereport(ERROR, (errcode_for_file_access(), - errmsg("could not read from temporary file: %m"))); + errmsg("could not read from temporary file: read only %zu of %zu bytes", + rc, bytes_to_read))); bbsink_manifest_contents(sink, bytes_to_read); manifest_bytes_done += bytes_to_read; } diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index f8e8cf71eb..64ce93e725 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -1426,7 +1426,7 @@ apply_spooled_messages(TransactionId xid, XLogRecPtr lsn) nchanges = 0; while (true) { - int nbytes; + size_t nbytes; int len; CHECK_FOR_INTERRUPTS(); @@ -1442,8 +1442,8 @@ apply_spooled_messages(TransactionId xid, XLogRecPtr lsn) if (nbytes != sizeof(len)) ereport(ERROR, (errcode_for_file_access(), - errmsg("could not read from streaming transaction's changes file \"%s\": %m", - path))); + errmsg("could not read from streaming transaction's changes file \"%s\": read only %zu of %zu bytes", + path, nbytes, sizeof(len)))); if (len <= 0) elog(ERROR, "incorrect length %d in streaming transaction's changes file \"%s\"", @@ -1453,11 +1453,12 @@ apply_spooled_messages(TransactionId xid, XLogRecPtr lsn) buffer = repalloc(buffer, len); /* and finally read the data into the buffer */ - if (BufFileRead(fd, buffer, len) != len) + nbytes = BufFileRead(fd, buffer, len); + if (nbytes != len) ereport(ERROR, (errcode_for_file_access(), - errmsg("could not read from streaming transaction's changes file \"%s\": %m", - path))); + errmsg("could not read from streaming transaction's changes file \"%s\": read only %zu of %zu bytes", + path, nbytes, (size_t) len))); /* copy the buffer to the stringinfo and call apply_dispatch */ resetStringInfo(&s2); @@ -3221,6 +3222,7 @@ static void subxact_info_read(Oid subid, TransactionId xid) { char path[MAXPGPATH]; + size_t nread; Size len; BufFile *fd; MemoryContext oldctx; @@ -3240,13 +3242,12 @@ subxact_info_read(Oid subid, TransactionId xid) return; /* read number of subxact items */ - if (BufFileRead(fd, &subxact_data.nsubxacts, - sizeof(subxact_data.nsubxacts)) != - sizeof(subxact_data.nsubxacts)) + nread = BufFileRead(fd, &subxact_data.nsubxacts, sizeof(subxact_data.nsubxacts)); + if (nread != sizeof(subxact_data.nsubxacts)) ereport(ERROR, (errcode_for_file_access(), - errmsg("could not read from streaming transaction's subxact file \"%s\": %m", - path))); + errmsg("could not read from streaming transaction's subxact file \"%s\": read only %zu of %zu bytes", + path, nread, sizeof(subxact_data.nsubxacts)))); len = sizeof(SubXactInfo) * subxact_data.nsubxacts; @@ -3264,11 +3265,15 @@ subxact_info_read(Oid subid, TransactionId xid) sizeof(SubXactInfo)); MemoryContextSwitchTo(oldctx); - if ((len > 0) && ((BufFileRead(fd, subxact_data.subxacts, len)) != len)) + if (len > 0) + { + nread = BufFileRead(fd, subxact_data.subxacts, len); + if (nread != len) ereport(ERROR, (errcode_for_file_access(), - errmsg("could not read from streaming transaction's subxact file \"%s\": %m", - path))); + errmsg("could not read from streaming transaction's subxact file \"%s\": read only %zu of %zu bytes", + path, nread, len))); + } BufFileClose(fd); } base-commit: 72aea955d49712a17c08748aa9abcbcf98c32fc5 -- 2.39.0