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

Commit 1561612

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 9a740f8 commit 1561612

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/backend/backup/backup_manifest.c

+2-1
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

+19-14
Original file line numberDiff line numberDiff line change
@@ -2063,7 +2063,7 @@ apply_spooled_messages(FileSet *stream_fileset, TransactionId xid,
20632063
nchanges = 0;
20642064
while (true)
20652065
{
2066-
int nbytes;
2066+
size_t nbytes;
20672067
int len;
20682068

20692069
CHECK_FOR_INTERRUPTS();
@@ -2079,8 +2079,8 @@ apply_spooled_messages(FileSet *stream_fileset, TransactionId xid,
20792079
if (nbytes != sizeof(len))
20802080
ereport(ERROR,
20812081
(errcode_for_file_access(),
2082-
errmsg("could not read from streaming transaction's changes file \"%s\": %m",
2083-
path)));
2082+
errmsg("could not read from streaming transaction's changes file \"%s\": read only %zu of %zu bytes",
2083+
path, nbytes, sizeof(len))));
20842084

20852085
if (len <= 0)
20862086
elog(ERROR, "incorrect length %d in streaming transaction's changes file \"%s\"",
@@ -2090,11 +2090,12 @@ apply_spooled_messages(FileSet *stream_fileset, TransactionId xid,
20902090
buffer = repalloc(buffer, len);
20912091

20922092
/* and finally read the data into the buffer */
2093-
if (BufFileRead(stream_fd, buffer, len) != len)
2093+
nbytes = BufFileRead(stream_fd, buffer, len);
2094+
if (nbytes != len)
20942095
ereport(ERROR,
20952096
(errcode_for_file_access(),
2096-
errmsg("could not read from streaming transaction's changes file \"%s\": %m",
2097-
path)));
2097+
errmsg("could not read from streaming transaction's changes file \"%s\": read only %zu of %zu bytes",
2098+
path, nbytes, (size_t) len)));
20982099

20992100
BufFileTell(stream_fd, &fileno, &offset);
21002101

@@ -3992,6 +3993,7 @@ static void
39923993
subxact_info_read(Oid subid, TransactionId xid)
39933994
{
39943995
char path[MAXPGPATH];
3996+
size_t nread;
39953997
Size len;
39963998
BufFile *fd;
39973999
MemoryContext oldctx;
@@ -4011,13 +4013,12 @@ subxact_info_read(Oid subid, TransactionId xid)
40114013
return;
40124014

40134015
/* read number of subxact items */
4014-
if (BufFileRead(fd, &subxact_data.nsubxacts,
4015-
sizeof(subxact_data.nsubxacts)) !=
4016-
sizeof(subxact_data.nsubxacts))
4016+
nread = BufFileRead(fd, &subxact_data.nsubxacts, sizeof(subxact_data.nsubxacts));
4017+
if (nread != sizeof(subxact_data.nsubxacts))
40174018
ereport(ERROR,
40184019
(errcode_for_file_access(),
4019-
errmsg("could not read from streaming transaction's subxact file \"%s\": %m",
4020-
path)));
4020+
errmsg("could not read from streaming transaction's subxact file \"%s\": read only %zu of %zu bytes",
4021+
path, nread, sizeof(subxact_data.nsubxacts))));
40214022

40224023
len = sizeof(SubXactInfo) * subxact_data.nsubxacts;
40234024

@@ -4035,11 +4036,15 @@ subxact_info_read(Oid subid, TransactionId xid)
40354036
sizeof(SubXactInfo));
40364037
MemoryContextSwitchTo(oldctx);
40374038

4038-
if ((len > 0) && ((BufFileRead(fd, subxact_data.subxacts, len)) != len))
4039+
if (len > 0)
4040+
{
4041+
nread = BufFileRead(fd, subxact_data.subxacts, len);
4042+
if (nread != len)
40394043
ereport(ERROR,
40404044
(errcode_for_file_access(),
4041-
errmsg("could not read from streaming transaction's subxact file \"%s\": %m",
4042-
path)));
4045+
errmsg("could not read from streaming transaction's subxact file \"%s\": read only %zu of %zu bytes",
4046+
path, nread, len)));
4047+
}
40434048

40444049
BufFileClose(fd);
40454050
}

0 commit comments

Comments
 (0)