Skip to content

Commit ac01fa6

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 db9127c commit ac01fa6

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/backend/backup/backup_manifest.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ SendBackupManifest(backup_manifest_info *manifest, bbsink *sink)
371371
if (rc != bytes_to_read)
372372
ereport(ERROR,
373373
(errcode_for_file_access(),
374-
errmsg("could not read from temporary file: %m")));
374+
errmsg("could not read from temporary file: read only %zu of %zu bytes",
375+
rc, bytes_to_read)));
375376
bbsink_manifest_contents(sink, bytes_to_read);
376377
manifest_bytes_done += bytes_to_read;
377378
}

src/backend/replication/logical/worker.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ apply_spooled_messages(TransactionId xid, XLogRecPtr lsn)
13981398
nchanges = 0;
13991399
while (true)
14001400
{
1401-
int nbytes;
1401+
size_t nbytes;
14021402
int len;
14031403

14041404
CHECK_FOR_INTERRUPTS();
@@ -1414,8 +1414,8 @@ apply_spooled_messages(TransactionId xid, XLogRecPtr lsn)
14141414
if (nbytes != sizeof(len))
14151415
ereport(ERROR,
14161416
(errcode_for_file_access(),
1417-
errmsg("could not read from streaming transaction's changes file \"%s\": %m",
1418-
path)));
1417+
errmsg("could not read from streaming transaction's changes file \"%s\": read only %zu of %zu bytes",
1418+
path, nbytes, sizeof(len))));
14191419

14201420
if (len <= 0)
14211421
elog(ERROR, "incorrect length %d in streaming transaction's changes file \"%s\"",
@@ -1425,11 +1425,12 @@ apply_spooled_messages(TransactionId xid, XLogRecPtr lsn)
14251425
buffer = repalloc(buffer, len);
14261426

14271427
/* and finally read the data into the buffer */
1428-
if (BufFileRead(fd, buffer, len) != len)
1428+
nbytes = BufFileRead(fd, buffer, len);
1429+
if (nbytes != len)
14291430
ereport(ERROR,
14301431
(errcode_for_file_access(),
1431-
errmsg("could not read from streaming transaction's changes file \"%s\": %m",
1432-
path)));
1432+
errmsg("could not read from streaming transaction's changes file \"%s\": read only %zu of %zu bytes",
1433+
path, nbytes, (size_t) len)));
14331434

14341435
/* copy the buffer to the stringinfo and call apply_dispatch */
14351436
resetStringInfo(&s2);
@@ -3192,6 +3193,7 @@ static void
31923193
subxact_info_read(Oid subid, TransactionId xid)
31933194
{
31943195
char path[MAXPGPATH];
3196+
size_t nread;
31953197
Size len;
31963198
BufFile *fd;
31973199
MemoryContext oldctx;
@@ -3211,13 +3213,12 @@ subxact_info_read(Oid subid, TransactionId xid)
32113213
return;
32123214

32133215
/* read number of subxact items */
3214-
if (BufFileRead(fd, &subxact_data.nsubxacts,
3215-
sizeof(subxact_data.nsubxacts)) !=
3216-
sizeof(subxact_data.nsubxacts))
3216+
nread = BufFileRead(fd, &subxact_data.nsubxacts, sizeof(subxact_data.nsubxacts));
3217+
if (nread != sizeof(subxact_data.nsubxacts))
32173218
ereport(ERROR,
32183219
(errcode_for_file_access(),
3219-
errmsg("could not read from streaming transaction's subxact file \"%s\": %m",
3220-
path)));
3220+
errmsg("could not read from streaming transaction's subxact file \"%s\": read only %zu of %zu bytes",
3221+
path, nread, sizeof(subxact_data.nsubxacts))));
32213222

32223223
len = sizeof(SubXactInfo) * subxact_data.nsubxacts;
32233224

@@ -3235,11 +3236,15 @@ subxact_info_read(Oid subid, TransactionId xid)
32353236
sizeof(SubXactInfo));
32363237
MemoryContextSwitchTo(oldctx);
32373238

3238-
if ((len > 0) && ((BufFileRead(fd, subxact_data.subxacts, len)) != len))
3239+
if (len > 0)
3240+
{
3241+
nread = BufFileRead(fd, subxact_data.subxacts, len);
3242+
if (nread != len)
32393243
ereport(ERROR,
32403244
(errcode_for_file_access(),
3241-
errmsg("could not read from streaming transaction's subxact file \"%s\": %m",
3242-
path)));
3245+
errmsg("could not read from streaming transaction's subxact file \"%s\": read only %zu of %zu bytes",
3246+
path, nread, len)));
3247+
}
32433248

32443249
BufFileClose(fd);
32453250
}

0 commit comments

Comments
 (0)