mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-25 16:17:19 +02: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
48cf9184ce
commit
95c4571812
@ -314,7 +314,8 @@ BufFileOpenShared(SharedFileSet *fileset, const char *name)
|
|||||||
if (nfiles == 0)
|
if (nfiles == 0)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(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 = makeBufFileCommon(nfiles);
|
||||||
file->files = files;
|
file->files = files;
|
||||||
@ -793,20 +794,26 @@ BufFileTellBlock(BufFile *file)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the current file size.
|
* Return the current shared BufFile size.
|
||||||
*
|
*
|
||||||
* Counts any holes left behind by BufFileAppend as part of the size.
|
* Counts any holes left behind by BufFileAppend as part of the size.
|
||||||
* Returns -1 on error.
|
* ereport()s on failure.
|
||||||
*/
|
*/
|
||||||
int64
|
int64
|
||||||
BufFileSize(BufFile *file)
|
BufFileSize(BufFile *file)
|
||||||
{
|
{
|
||||||
int64 lastFileSize;
|
int64 lastFileSize;
|
||||||
|
|
||||||
|
Assert(file->fileset != NULL);
|
||||||
|
|
||||||
/* Get the size of the last physical file by seeking to end. */
|
/* Get the size of the last physical file by seeking to end. */
|
||||||
lastFileSize = FileSeek(file->files[file->numFiles - 1], 0, SEEK_END);
|
lastFileSize = FileSeek(file->files[file->numFiles - 1], 0, SEEK_END);
|
||||||
if (lastFileSize < 0)
|
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;
|
file->offsets[file->numFiles - 1] = lastFileSize;
|
||||||
|
|
||||||
return ((file->numFiles - 1) * (int64) MAX_PHYSICAL_FILESIZE) +
|
return ((file->numFiles - 1) * (int64) MAX_PHYSICAL_FILESIZE) +
|
||||||
|
@ -433,10 +433,6 @@ ltsConcatWorkerTapes(LogicalTapeSet *lts, TapeShare *shared,
|
|||||||
pg_itoa(i, filename);
|
pg_itoa(i, filename);
|
||||||
file = BufFileOpenShared(fileset, filename);
|
file = BufFileOpenShared(fileset, filename);
|
||||||
filesize = BufFileSize(file);
|
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.
|
* Stash first BufFile, and concatenate subsequent BufFiles to that.
|
||||||
|
Loading…
Reference in New Issue
Block a user