diff options
Diffstat (limited to 'src/backend/replication')
-rw-r--r-- | src/backend/replication/logical/origin.c | 13 | ||||
-rw-r--r-- | src/backend/replication/logical/snapbuild.c | 68 | ||||
-rw-r--r-- | src/backend/replication/slot.c | 26 | ||||
-rw-r--r-- | src/backend/replication/walsender.c | 20 |
4 files changed, 91 insertions, 36 deletions
diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c index 3d3f6dff1b0..841e24c03da 100644 --- a/src/backend/replication/logical/origin.c +++ b/src/backend/replication/logical/origin.c @@ -712,9 +712,16 @@ StartupReplicationOrigin(void) /* verify magic, that is written even if nothing was active */ readBytes = read(fd, &magic, sizeof(magic)); if (readBytes != sizeof(magic)) - ereport(PANIC, - (errmsg("could not read file \"%s\": %m", - path))); + { + if (readBytes < 0) + ereport(PANIC, + (errmsg("could not read file \"%s\": %m", + path))); + else + ereport(PANIC, + (errmsg("could not read file \"%s\": read %d of %zu", + path, readBytes, sizeof(magic)))); + } COMP_CRC32C(crc, &magic, sizeof(magic)); if (magic != REPLICATION_STATE_MAGIC) diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c index e975faeb8c9..61bc9e8f147 100644 --- a/src/backend/replication/logical/snapbuild.c +++ b/src/backend/replication/logical/snapbuild.c @@ -1726,11 +1726,18 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn) int save_errno = errno; CloseTransientFile(fd); - errno = save_errno; - ereport(ERROR, - (errcode_for_file_access(), - errmsg("could not read file \"%s\", read %d of %d: %m", - path, readBytes, (int) SnapBuildOnDiskConstantSize))); + + if (readBytes < 0) + { + errno = save_errno; + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not read file \"%s\": %m", path))); + } + else + ereport(ERROR, + (errmsg("could not read file \"%s\": read %d of %zu", + path, readBytes, SnapBuildOnDiskConstantSize))); } if (ondisk.magic != SNAPBUILD_MAGIC) @@ -1757,11 +1764,18 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn) int save_errno = errno; CloseTransientFile(fd); - errno = save_errno; - ereport(ERROR, - (errcode_for_file_access(), - errmsg("could not read file \"%s\", read %d of %d: %m", - path, readBytes, (int) sizeof(SnapBuild)))); + + if (readBytes < 0) + { + errno = save_errno; + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not read file \"%s\": %m", path))); + } + else + ereport(ERROR, + (errmsg("could not read file \"%s\": read %d of %zu", + path, readBytes, sizeof(SnapBuild)))); } COMP_CRC32C(checksum, &ondisk.builder, sizeof(SnapBuild)); @@ -1777,11 +1791,18 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn) int save_errno = errno; CloseTransientFile(fd); - errno = save_errno; - ereport(ERROR, - (errcode_for_file_access(), - errmsg("could not read file \"%s\", read %d of %d: %m", - path, readBytes, (int) sz))); + + if (readBytes < 0) + { + errno = save_errno; + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not read file \"%s\": %m", path))); + } + else + ereport(ERROR, + (errmsg("could not read file \"%s\": read %d of %zu", + path, readBytes, sz))); } COMP_CRC32C(checksum, ondisk.builder.was_running.was_xip, sz); @@ -1796,11 +1817,18 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn) int save_errno = errno; CloseTransientFile(fd); - errno = save_errno; - ereport(ERROR, - (errcode_for_file_access(), - errmsg("could not read file \"%s\", read %d of %d: %m", - path, readBytes, (int) sz))); + + if (readBytes < 0) + { + errno = save_errno; + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not read file \"%s\": %m", path))); + } + else + ereport(ERROR, + (errmsg("could not read file \"%s\": read %d of %zu", + path, readBytes, sz))); } COMP_CRC32C(checksum, ondisk.builder.committed.xip, sz); diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index fb95b44ed82..afbaf8c80d8 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -1414,11 +1414,15 @@ RestoreSlotFromDisk(const char *name) CloseTransientFile(fd); errno = saved_errno; - ereport(PANIC, - (errcode_for_file_access(), - errmsg("could not read file \"%s\", read %d of %u: %m", - path, readBytes, - (uint32) ReplicationSlotOnDiskConstantSize))); + if (readBytes < 0) + ereport(PANIC, + (errcode_for_file_access(), + errmsg("could not read file \"%s\": %m", path))); + else + ereport(PANIC, + (errmsg("could not read file \"%s\": read %d of %zu", + path, readBytes, + ReplicationSlotOnDiskConstantSize))); } /* verify magic */ @@ -1454,10 +1458,14 @@ RestoreSlotFromDisk(const char *name) CloseTransientFile(fd); errno = saved_errno; - ereport(PANIC, - (errcode_for_file_access(), - errmsg("could not read file \"%s\", read %d of %u: %m", - path, readBytes, cp.length))); + if (readBytes < 0) + ereport(PANIC, + (errcode_for_file_access(), + errmsg("could not read file \"%s\": %m", path))); + else + ereport(PANIC, + (errmsg("could not read file \"%s\": read %d of %zu", + path, readBytes, (Size) cp.length))); } CloseTransientFile(fd); diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 3a0106bc933..e3df5495c33 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -501,11 +501,16 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd) pgstat_report_wait_start(WAIT_EVENT_WALSENDER_TIMELINE_HISTORY_READ); nread = read(fd, rbuf, sizeof(rbuf)); pgstat_report_wait_end(); - if (nread <= 0) + if (nread < 0) ereport(ERROR, (errcode_for_file_access(), errmsg("could not read file \"%s\": %m", path))); + else if (nread == 0) + ereport(ERROR, + (errmsg("could not read file \"%s\": read %d of %zu", + path, nread, bytesleft))); + pq_sendbytes(&buf, rbuf, nread); bytesleft -= nread; } @@ -2425,13 +2430,20 @@ retry: pgstat_report_wait_start(WAIT_EVENT_WAL_READ); readbytes = read(sendFile, p, segbytes); pgstat_report_wait_end(); - if (readbytes <= 0) + if (readbytes < 0) { ereport(ERROR, (errcode_for_file_access(), - errmsg("could not read from log segment %s, offset %u, length %lu: %m", + errmsg("could not read from log segment %s, offset %u, length %zu: %m", + XLogFileNameP(curFileTimeLine, sendSegNo), + sendOff, (Size) segbytes))); + } + else if (readbytes == 0) + { + ereport(ERROR, + (errmsg("could not read from log segment %s, offset %u: read %d of %zu", XLogFileNameP(curFileTimeLine, sendSegNo), - sendOff, (unsigned long) segbytes))); + sendOff, readbytes, (Size) segbytes))); } /* Update state for read */ |