diff options
author | Michael Paquier <michael@paquier.xyz> | 2018-07-18 08:01:23 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2018-07-18 08:01:23 +0900 |
commit | 811b6e36a9e21a4d9eb78410976c88ce601cea0c (patch) | |
tree | 84eaedfcf651899f0140274b515cc6b2658e8b6c /src/backend/access/transam/twophase.c | |
parent | c6736ff76046521f56c50deb31da218bc1b29533 (diff) | |
download | postgresql-811b6e36a9e21a4d9eb78410976c88ce601cea0c.tar.gz postgresql-811b6e36a9e21a4d9eb78410976c88ce601cea0c.zip |
Rework error messages around file handling
Some error messages related to file handling are using the code path
context to define their state. For example, 2PC-related errors are
referring to "two-phase status files", or "relation mapping file" is
used for catalog-to-filenode mapping, however those prove to be
difficult to translate, and are not more helpful than just referring to
the path of the file being worked on. So simplify all those error
messages by just referring to files with their path used. In some
cases, like the manipulation of WAL segments, the context is actually
helpful so those are kept.
Calls to the system function read() have also been rather inconsistent
with their error handling sometimes not reporting the number of bytes
read, and some other code paths trying to use an errno which has not
been set. The in-core functions are using a more consistent pattern
with this patch, which checks for both errno if set or if an
inconsistent read is happening.
So as to care about pluralization when reading an unexpected number of
byte(s), "could not read: read %d of %zu" is used as error message, with
%d field being the output result of read() and %zu the expected size.
This simplifies the work of translators with less variations of the same
message.
Author: Michael Paquier
Reviewed-by: Álvaro Herrera
Discussion: https://postgr.es/m/20180520000522.GB1603@paquier.xyz
Diffstat (limited to 'src/backend/access/transam/twophase.c')
-rw-r--r-- | src/backend/access/transam/twophase.c | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index e8d4e37fe30..0c99b336641 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -1219,6 +1219,7 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings) uint32 crc_offset; pg_crc32c calc_crc, file_crc; + int r; TwoPhaseFilePath(path, xid); @@ -1228,8 +1229,7 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings) if (give_warnings) ereport(WARNING, (errcode_for_file_access(), - errmsg("could not open two-phase state file \"%s\": %m", - path))); + errmsg("could not open file \"%s\": %m", path))); return NULL; } @@ -1249,8 +1249,7 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings) errno = save_errno; ereport(WARNING, (errcode_for_file_access(), - errmsg("could not stat two-phase state file \"%s\": %m", - path))); + errmsg("could not stat file \"%s\": %m", path))); } return NULL; } @@ -1277,7 +1276,8 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings) buf = (char *) palloc(stat.st_size); pgstat_report_wait_start(WAIT_EVENT_TWOPHASE_FILE_READ); - if (read(fd, buf, stat.st_size) != stat.st_size) + r = read(fd, buf, stat.st_size); + if (r != stat.st_size) { int save_errno = errno; @@ -1285,11 +1285,17 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings) CloseTransientFile(fd); if (give_warnings) { - errno = save_errno; - ereport(WARNING, - (errcode_for_file_access(), - errmsg("could not read two-phase state file \"%s\": %m", - path))); + if (r < 0) + { + errno = save_errno; + ereport(WARNING, + (errcode_for_file_access(), + errmsg("could not read file \"%s\": %m", path))); + } + else + ereport(WARNING, + (errmsg("could not read file \"%s\": read %d of %zu", + path, r, stat.st_size))); } pfree(buf); return NULL; @@ -1632,8 +1638,7 @@ RemoveTwoPhaseFile(TransactionId xid, bool giveWarning) if (errno != ENOENT || giveWarning) ereport(WARNING, (errcode_for_file_access(), - errmsg("could not remove two-phase state file \"%s\": %m", - path))); + errmsg("could not remove file \"%s\": %m", path))); } /* @@ -1661,8 +1666,7 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len) if (fd < 0) ereport(ERROR, (errcode_for_file_access(), - errmsg("could not recreate two-phase state file \"%s\": %m", - path))); + errmsg("could not recreate file \"%s\": %m", path))); /* Write content and CRC */ pgstat_report_wait_start(WAIT_EVENT_TWOPHASE_FILE_WRITE); @@ -1677,7 +1681,7 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len) errno = save_errno ? save_errno : ENOSPC; ereport(ERROR, (errcode_for_file_access(), - errmsg("could not write two-phase state file: %m"))); + errmsg("could not write file \"%s\": %m", path))); } if (write(fd, &statefile_crc, sizeof(pg_crc32c)) != sizeof(pg_crc32c)) { @@ -1690,7 +1694,7 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len) errno = save_errno ? save_errno : ENOSPC; ereport(ERROR, (errcode_for_file_access(), - errmsg("could not write two-phase state file: %m"))); + errmsg("could not write file \"%s\": %m", path))); } pgstat_report_wait_end(); @@ -1707,14 +1711,14 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len) errno = save_errno; ereport(ERROR, (errcode_for_file_access(), - errmsg("could not fsync two-phase state file: %m"))); + errmsg("could not fsync file \"%s\": %m", path))); } pgstat_report_wait_end(); if (CloseTransientFile(fd) != 0) ereport(ERROR, (errcode_for_file_access(), - errmsg("could not close two-phase state file: %m"))); + errmsg("could not close file \"%s\": %m", path))); } /* |