Skip to content

Commit 11e2645

Browse files
committed
Remove BufFile's isTemp flag.
The isTemp flag controls whether buffile.c chops BufFile data up into 1GB segments on disk. Since it was badly named and always true, get rid of it. Author: Thomas Munro (based on suggestion by Peter Geoghegan) Reviewed-By: Peter Geoghegan, Andres Freund Discussion: https://postgr.es/m/CAH2-Wz%3D%2B9Rfqh5UdvdW9rGezdhrMGGH-JL1X9FXXVZdeeGeOJA%40mail.gmail.com
1 parent 7082e61 commit 11e2645

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

src/backend/storage/file/buffile.c

+18-25
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ struct BufFile
6868
* avoid making redundant FileSeek calls.
6969
*/
7070

71-
bool isTemp; /* can only add files if this is true */
7271
bool isInterXact; /* keep open over transactions? */
7372
bool dirty; /* does buffer need to be written? */
7473

@@ -99,7 +98,7 @@ static int BufFileFlush(BufFile *file);
9998

10099
/*
101100
* Create a BufFile given the first underlying physical file.
102-
* NOTE: caller must set isTemp and isInterXact if appropriate.
101+
* NOTE: caller must set isInterXact if appropriate.
103102
*/
104103
static BufFile *
105104
makeBufFile(File firstfile)
@@ -111,7 +110,6 @@ makeBufFile(File firstfile)
111110
file->files[0] = firstfile;
112111
file->offsets = (off_t *) palloc(sizeof(off_t));
113112
file->offsets[0] = 0L;
114-
file->isTemp = false;
115113
file->isInterXact = false;
116114
file->dirty = false;
117115
file->resowner = CurrentResourceOwner;
@@ -136,7 +134,6 @@ extendBufFile(BufFile *file)
136134
oldowner = CurrentResourceOwner;
137135
CurrentResourceOwner = file->resowner;
138136

139-
Assert(file->isTemp);
140137
pfile = OpenTemporaryFile(file->isInterXact);
141138
Assert(pfile >= 0);
142139

@@ -173,7 +170,6 @@ BufFileCreateTemp(bool interXact)
173170
Assert(pfile >= 0);
174171

175172
file = makeBufFile(pfile);
176-
file->isTemp = true;
177173
file->isInterXact = interXact;
178174

179175
return file;
@@ -288,10 +284,12 @@ BufFileDumpBuffer(BufFile *file)
288284
*/
289285
while (wpos < file->nbytes)
290286
{
287+
off_t availbytes;
288+
291289
/*
292290
* Advance to next component file if necessary and possible.
293291
*/
294-
if (file->curOffset >= MAX_PHYSICAL_FILESIZE && file->isTemp)
292+
if (file->curOffset >= MAX_PHYSICAL_FILESIZE)
295293
{
296294
while (file->curFile + 1 >= file->numFiles)
297295
extendBufFile(file);
@@ -304,13 +302,10 @@ BufFileDumpBuffer(BufFile *file)
304302
* write as much as asked...
305303
*/
306304
bytestowrite = file->nbytes - wpos;
307-
if (file->isTemp)
308-
{
309-
off_t availbytes = MAX_PHYSICAL_FILESIZE - file->curOffset;
305+
availbytes = MAX_PHYSICAL_FILESIZE - file->curOffset;
310306

311-
if ((off_t) bytestowrite > availbytes)
312-
bytestowrite = (int) availbytes;
313-
}
307+
if ((off_t) bytestowrite > availbytes)
308+
bytestowrite = (int) availbytes;
314309

315310
/*
316311
* May need to reposition physical file.
@@ -543,20 +538,18 @@ BufFileSeek(BufFile *file, int fileno, off_t offset, int whence)
543538
* above flush could have created a new segment, so checking sooner would
544539
* not work (at least not with this code).
545540
*/
546-
if (file->isTemp)
541+
542+
/* convert seek to "start of next seg" to "end of last seg" */
543+
if (newFile == file->numFiles && newOffset == 0)
547544
{
548-
/* convert seek to "start of next seg" to "end of last seg" */
549-
if (newFile == file->numFiles && newOffset == 0)
550-
{
551-
newFile--;
552-
newOffset = MAX_PHYSICAL_FILESIZE;
553-
}
554-
while (newOffset > MAX_PHYSICAL_FILESIZE)
555-
{
556-
if (++newFile >= file->numFiles)
557-
return EOF;
558-
newOffset -= MAX_PHYSICAL_FILESIZE;
559-
}
545+
newFile--;
546+
newOffset = MAX_PHYSICAL_FILESIZE;
547+
}
548+
while (newOffset > MAX_PHYSICAL_FILESIZE)
549+
{
550+
if (++newFile >= file->numFiles)
551+
return EOF;
552+
newOffset -= MAX_PHYSICAL_FILESIZE;
560553
}
561554
if (newFile >= file->numFiles)
562555
return EOF;

0 commit comments

Comments
 (0)