diff options
Diffstat (limited to 'src/backend/storage')
-rw-r--r-- | src/backend/storage/file/buffile.c | 10 | ||||
-rw-r--r-- | src/backend/storage/file/fd.c | 25 |
2 files changed, 24 insertions, 11 deletions
diff --git a/src/backend/storage/file/buffile.c b/src/backend/storage/file/buffile.c index 7e78793a40..90b185cd5d 100644 --- a/src/backend/storage/file/buffile.c +++ b/src/backend/storage/file/buffile.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/file/buffile.c,v 1.14 2002/09/05 00:43:07 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/file/buffile.c,v 1.15 2003/03/27 16:51:29 momjian Exp $ * * NOTES: * @@ -64,6 +64,7 @@ struct BufFile */ bool isTemp; /* can only add files if this is TRUE */ + bool isInterTxn; /* keep open over transactions? */ bool dirty; /* does buffer need to be written? */ /* @@ -118,7 +119,7 @@ extendBufFile(BufFile *file) File pfile; Assert(file->isTemp); - pfile = OpenTemporaryFile(); + pfile = OpenTemporaryFile(file->isInterTxn); Assert(pfile >= 0); file->files = (File *) repalloc(file->files, @@ -136,16 +137,17 @@ extendBufFile(BufFile *file) * written to it). */ BufFile * -BufFileCreateTemp(void) +BufFileCreateTemp(bool interTxn) { BufFile *file; File pfile; - pfile = OpenTemporaryFile(); + pfile = OpenTemporaryFile(interTxn); Assert(pfile >= 0); file = makeBufFile(pfile); file->isTemp = true; + file->isInterTxn = interTxn; return file; } diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 83c97fb755..7607d4186c 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.95 2002/09/02 06:11:42 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.96 2003/03/27 16:51:29 momjian Exp $ * * NOTES: * @@ -112,14 +112,14 @@ int max_files_per_process = 1000; #define FileUnknownPos (-1L) +/* these are the assigned bits in fdstate below: */ +#define FD_TEMPORARY (1 << 0) +#define FD_TXN_TEMPORARY (1 << 1) + typedef struct vfd { signed short fd; /* current FD, or VFD_CLOSED if none */ unsigned short fdstate; /* bitflags for VFD's state */ - -/* these are the assigned bits in fdstate: */ -#define FD_TEMPORARY (1 << 0) /* should be unlinked when closed */ - File nextFree; /* link to next free VFD, if in freelist */ File lruMoreRecently; /* doubly linked recency-of-use list */ File lruLessRecently; @@ -750,9 +750,15 @@ PathNameOpenFile(FileName fileName, int fileFlags, int fileMode) * This routine takes care of generating an appropriate tempfile name. * There's no need to pass in fileFlags or fileMode either, since only * one setting makes any sense for a temp file. + * + * keepOverTxn: if true, don't close the file at end-of-transaction. In + * most cases, you don't want temporary files to outlive the transaction + * that created them, so this should be false -- but if you need + * "somewhat" temporary storage, this might be useful. In either case, + * the file is removed when the File is explicitely closed. */ File -OpenTemporaryFile(void) +OpenTemporaryFile(bool keepOverTxn) { char tempfilepath[128]; File file; @@ -795,9 +801,13 @@ OpenTemporaryFile(void) elog(ERROR, "Failed to create temporary file %s", tempfilepath); } - /* Mark it for deletion at close or EOXact */ + /* Mark it for deletion at close */ VfdCache[file].fdstate |= FD_TEMPORARY; + /* Mark it for deletion at EOXact */ + if (!keepOverTxn) + VfdCache[file].fdstate |= FD_TXN_TEMPORARY; + return file; } @@ -1114,6 +1124,7 @@ AtEOXact_Files(void) for (i = 1; i < SizeVfdCache; i++) { if ((VfdCache[i].fdstate & FD_TEMPORARY) && + (VfdCache[i].fdstate & FD_TXN_TEMPORARY) && VfdCache[i].fileName != NULL) FileClose(i); } |