mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-27 08:39:28 +08:00
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 aa55183042
, 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/26974.1540826748@sss.pgh.pa.us
Backpatch: 11-, where shared BufFiles were introduced.
This commit is contained in:
parent
f2cbffc7a6
commit
1a990b207b
@ -304,7 +304,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;
|
||||
@ -763,20 +764,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. */
|
||||
lastFileSize = FileSize(file->files[file->numFiles - 1]);
|
||||
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)));
|
||||
|
||||
return ((file->numFiles - 1) * (int64) MAX_PHYSICAL_FILESIZE) +
|
||||
lastFileSize;
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user