aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/cache
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2018-07-18 08:01:23 +0900
committerMichael Paquier <michael@paquier.xyz>2018-07-18 08:01:23 +0900
commit811b6e36a9e21a4d9eb78410976c88ce601cea0c (patch)
tree84eaedfcf651899f0140274b515cc6b2658e8b6c /src/backend/utils/cache
parentc6736ff76046521f56c50deb31da218bc1b29533 (diff)
downloadpostgresql-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/utils/cache')
-rw-r--r--src/backend/utils/cache/relmapper.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/backend/utils/cache/relmapper.c b/src/backend/utils/cache/relmapper.c
index 99d095f2df3..2d31f9f912a 100644
--- a/src/backend/utils/cache/relmapper.c
+++ b/src/backend/utils/cache/relmapper.c
@@ -629,6 +629,7 @@ load_relmap_file(bool shared)
char mapfilename[MAXPGPATH];
pg_crc32c crc;
int fd;
+ int r;
if (shared)
{
@@ -648,7 +649,7 @@ load_relmap_file(bool shared)
if (fd < 0)
ereport(FATAL,
(errcode_for_file_access(),
- errmsg("could not open relation mapping file \"%s\": %m",
+ errmsg("could not open file \"%s\": %m",
mapfilename)));
/*
@@ -659,11 +660,18 @@ load_relmap_file(bool shared)
* are able to access any relation that's affected by the change.
*/
pgstat_report_wait_start(WAIT_EVENT_RELATION_MAP_READ);
- if (read(fd, map, sizeof(RelMapFile)) != sizeof(RelMapFile))
- ereport(FATAL,
- (errcode_for_file_access(),
- errmsg("could not read relation mapping file \"%s\": %m",
- mapfilename)));
+ r = read(fd, map, sizeof(RelMapFile));
+ if (r != sizeof(RelMapFile))
+ {
+ if (r < 0)
+ ereport(FATAL,
+ (errcode_for_file_access(),
+ errmsg("could not read file \"%s\": %m", mapfilename)));
+ else
+ ereport(FATAL,
+ (errmsg("could not read file \"%s\": read %d of %zu",
+ mapfilename, r, sizeof(RelMapFile))));
+ }
pgstat_report_wait_end();
CloseTransientFile(fd);
@@ -748,7 +756,7 @@ write_relmap_file(bool shared, RelMapFile *newmap,
if (fd < 0)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not open relation mapping file \"%s\": %m",
+ errmsg("could not open file \"%s\": %m",
mapfilename)));
if (write_wal)
@@ -782,7 +790,7 @@ write_relmap_file(bool shared, RelMapFile *newmap,
errno = ENOSPC;
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not write to relation mapping file \"%s\": %m",
+ errmsg("could not write file \"%s\": %m",
mapfilename)));
}
pgstat_report_wait_end();
@@ -797,14 +805,14 @@ write_relmap_file(bool shared, RelMapFile *newmap,
if (pg_fsync(fd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not fsync relation mapping file \"%s\": %m",
+ errmsg("could not fsync file \"%s\": %m",
mapfilename)));
pgstat_report_wait_end();
if (CloseTransientFile(fd))
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not close relation mapping file \"%s\": %m",
+ errmsg("could not close file \"%s\": %m",
mapfilename)));
/*