Skip to content

Commit f463335

Browse files
committed
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 7897e3b, but some code was apparently developed concurrently to that and not updated accordingly. Reviewed-by: Amit Kapila <amit.kapila16@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/f3501945-c591-8cc3-5ef0-b72a2e0eaa9c@enterprisedb.com
1 parent a8b88c2 commit f463335

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/backend/replication/backup_manifest.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ SendBackupManifest(backup_manifest_info *manifest)
377377
if (rc != bytes_to_read)
378378
ereport(ERROR,
379379
(errcode_for_file_access(),
380-
errmsg("could not read from temporary file: %m")));
380+
errmsg("could not read from temporary file: read only %zu of %zu bytes",
381+
rc, bytes_to_read)));
381382
pq_putmessage('d', manifestbuf, bytes_to_read);
382383
manifest_bytes_done += bytes_to_read;
383384
}

src/backend/replication/logical/worker.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ apply_handle_stream_commit(StringInfo s)
10711071
nchanges = 0;
10721072
while (true)
10731073
{
1074-
int nbytes;
1074+
size_t nbytes;
10751075
int len;
10761076

10771077
CHECK_FOR_INTERRUPTS();
@@ -1087,8 +1087,8 @@ apply_handle_stream_commit(StringInfo s)
10871087
if (nbytes != sizeof(len))
10881088
ereport(ERROR,
10891089
(errcode_for_file_access(),
1090-
errmsg("could not read from streaming transaction's changes file \"%s\": %m",
1091-
path)));
1090+
errmsg("could not read from streaming transaction's changes file \"%s\": read only %zu of %zu bytes",
1091+
path, nbytes, sizeof(len))));
10921092

10931093
if (len <= 0)
10941094
elog(ERROR, "incorrect length %d in streaming transaction's changes file \"%s\"",
@@ -1098,11 +1098,12 @@ apply_handle_stream_commit(StringInfo s)
10981098
buffer = repalloc(buffer, len);
10991099

11001100
/* and finally read the data into the buffer */
1101-
if (BufFileRead(fd, buffer, len) != len)
1101+
nbytes = BufFileRead(fd, buffer, len);
1102+
if (nbytes != len)
11021103
ereport(ERROR,
11031104
(errcode_for_file_access(),
1104-
errmsg("could not read from streaming transaction's changes file \"%s\": %m",
1105-
path)));
1105+
errmsg("could not read from streaming transaction's changes file \"%s\": read only %zu of %zu bytes",
1106+
path, nbytes, (size_t) len)));
11061107

11071108
/* copy the buffer to the stringinfo and call apply_dispatch */
11081109
resetStringInfo(&s2);
@@ -2710,6 +2711,7 @@ static void
27102711
subxact_info_read(Oid subid, TransactionId xid)
27112712
{
27122713
char path[MAXPGPATH];
2714+
size_t nread;
27132715
Size len;
27142716
BufFile *fd;
27152717
StreamXidHash *ent;
@@ -2742,13 +2744,12 @@ subxact_info_read(Oid subid, TransactionId xid)
27422744
fd = BufFileOpenShared(ent->subxact_fileset, path, O_RDONLY);
27432745

27442746
/* read number of subxact items */
2745-
if (BufFileRead(fd, &subxact_data.nsubxacts,
2746-
sizeof(subxact_data.nsubxacts)) !=
2747-
sizeof(subxact_data.nsubxacts))
2747+
nread = BufFileRead(fd, &subxact_data.nsubxacts, sizeof(subxact_data.nsubxacts));
2748+
if (nread != sizeof(subxact_data.nsubxacts))
27482749
ereport(ERROR,
27492750
(errcode_for_file_access(),
2750-
errmsg("could not read from streaming transaction's subxact file \"%s\": %m",
2751-
path)));
2751+
errmsg("could not read from streaming transaction's subxact file \"%s\": read only %zu of %zu bytes",
2752+
path, nread, sizeof(subxact_data.nsubxacts))));
27522753

27532754
len = sizeof(SubXactInfo) * subxact_data.nsubxacts;
27542755

@@ -2766,11 +2767,15 @@ subxact_info_read(Oid subid, TransactionId xid)
27662767
sizeof(SubXactInfo));
27672768
MemoryContextSwitchTo(oldctx);
27682769

2769-
if ((len > 0) && ((BufFileRead(fd, subxact_data.subxacts, len)) != len))
2770+
if (len > 0)
2771+
{
2772+
nread = BufFileRead(fd, subxact_data.subxacts, len);
2773+
if (nread != len)
27702774
ereport(ERROR,
27712775
(errcode_for_file_access(),
2772-
errmsg("could not read from streaming transaction's subxact file \"%s\": %m",
2773-
path)));
2776+
errmsg("could not read from streaming transaction's subxact file \"%s\": read only %zu of %zu bytes",
2777+
path, nread, len)));
2778+
}
27742779

27752780
BufFileClose(fd);
27762781
}

0 commit comments

Comments
 (0)