summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Geoghegan2018-11-28 22:42:52 +0000
committerPeter Geoghegan2018-11-28 22:42:52 +0000
commit95c45718126fe081e9236335a85d15ad24adc107 (patch)
treeb4e7a4f5bc32d7ddb2cc5253e96ac7d9e145ad29
parent48cf9184ce9574363b310eaf65c7c939a5d40e76 (diff)
Have BufFileSize() ereport() on FileSize() failure.
Move the responsibility for checking for and reporting a failure from the only current BufFileSize() caller, logtape.c, to BufFileSize() itself. Code within buffile.c is generally responsible for interfacing with fd.c to report irrecoverable failures. This seems like a convention that's worth sticking to. Reorganizing things this way makes it easy to make the error message raised in the event of BufFileSize() failure descriptive of the underlying problem. We're now clear on the distinction between temporary file name and BufFile name, and can show errno, confident that its value actually relates to the error being reported. In passing, an existing, similar buffile.c ereport() + errcode_for_file_access() site is changed to follow the same conventions. The API of the function BufFileSize() is changed by this commit, despite already being in a stable release (Postgres 11). This seems acceptable, since the BufFileSize() ABI was changed by commit aa551830421, which hasn't made it into a point release yet. Besides, it's difficult to imagine a third party BufFileSize() caller not just raising an error anyway, since BufFile state should be considered corrupt when BufFileSize() fails. Per complaint from Tom Lane. Discussion: https://postgr.es/m/[email protected] Backpatch: 11-, where shared BufFiles were introduced.
-rw-r--r--src/backend/storage/file/buffile.c15
-rw-r--r--src/backend/utils/sort/logtape.c4
2 files changed, 11 insertions, 8 deletions
diff --git a/src/backend/storage/file/buffile.c b/src/backend/storage/file/buffile.c
index 8c7d8bcb91..cc7307ba33 100644
--- a/src/backend/storage/file/buffile.c
+++ b/src/backend/storage/file/buffile.c
@@ -314,7 +314,8 @@ BufFileOpenShared(SharedFileSet *fileset, const char *name)
if (nfiles == 0)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not open BufFile \"%s\"", name)));
+ errmsg("could not open temporary file \"%s\" from BufFile \"%s\": %m",
+ segment_name, name)));
file = makeBufFileCommon(nfiles);
file->files = files;
@@ -793,20 +794,26 @@ BufFileTellBlock(BufFile *file)
#endif
/*
- * Return the current file size.
+ * Return the current shared BufFile size.
*
* Counts any holes left behind by BufFileAppend as part of the size.
- * Returns -1 on error.
+ * ereport()s on failure.
*/
int64
BufFileSize(BufFile *file)
{
int64 lastFileSize;
+ Assert(file->fileset != NULL);
+
/* Get the size of the last physical file by seeking to end. */
lastFileSize = FileSeek(file->files[file->numFiles - 1], 0, SEEK_END);
if (lastFileSize < 0)
- return -1;
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not determine size of temporary file \"%s\" from BufFile \"%s\": %m",
+ FilePathName(file->files[file->numFiles - 1]),
+ file->name)));
file->offsets[file->numFiles - 1] = lastFileSize;
return ((file->numFiles - 1) * (int64) MAX_PHYSICAL_FILESIZE) +
diff --git a/src/backend/utils/sort/logtape.c b/src/backend/utils/sort/logtape.c
index 269523d5f6..2358c6fe52 100644
--- a/src/backend/utils/sort/logtape.c
+++ b/src/backend/utils/sort/logtape.c
@@ -433,10 +433,6 @@ ltsConcatWorkerTapes(LogicalTapeSet *lts, TapeShare *shared,
pg_itoa(i, filename);
file = BufFileOpenShared(fileset, filename);
filesize = BufFileSize(file);
- if (filesize < 0)
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not determine size of temporary file \"%s\"", filename)));
/*
* Stash first BufFile, and concatenate subsequent BufFiles to that.