Skip to content

Commit 5817d86

Browse files
committed
Optimize CleanupTempFiles by having a boolean flag that keeps track of whether
there are FD_XACT_TEMPORARY files to clean up at transaction end. Per performance profiling results on AWeber's huge systems. Patch by me after an idea suggested by Simon Riggs.
1 parent 9fe79c3 commit 5817d86

File tree

1 file changed

+18
-3
lines changed
  • src/backend/storage/file

1 file changed

+18
-3
lines changed

src/backend/storage/file/fd.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.144 2008/03/10 20:06:27 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.145 2008/09/19 04:57:10 alvherre Exp $
1111
*
1212
* NOTES:
1313
*
@@ -121,6 +121,12 @@ static int max_safe_fds = 32; /* default if not changed */
121121
#define FD_TEMPORARY (1 << 0) /* T = delete when closed */
122122
#define FD_XACT_TEMPORARY (1 << 1) /* T = delete at eoXact */
123123

124+
/*
125+
* Flag to tell whether it's worth scanning VfdCache looking for temp files to
126+
* close
127+
*/
128+
static bool have_xact_temporary_files = false;
129+
124130
typedef struct vfd
125131
{
126132
int fd; /* current FD, or VFD_CLOSED if none */
@@ -889,6 +895,9 @@ OpenTemporaryFile(bool interXact)
889895
{
890896
VfdCache[file].fdstate |= FD_XACT_TEMPORARY;
891897
VfdCache[file].create_subid = GetCurrentSubTransactionId();
898+
899+
/* ensure cleanup happens at eoxact */
900+
have_xact_temporary_files = true;
892901
}
893902

894903
return file;
@@ -1608,7 +1617,7 @@ AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid,
16081617
{
16091618
Index i;
16101619

1611-
if (SizeVfdCache > 0)
1620+
if (have_xact_temporary_files)
16121621
{
16131622
Assert(FileIsNotOpen(0)); /* Make sure ring not corrupted */
16141623
for (i = 1; i < SizeVfdCache; i++)
@@ -1684,7 +1693,11 @@ CleanupTempFiles(bool isProcExit)
16841693
{
16851694
Index i;
16861695

1687-
if (SizeVfdCache > 0)
1696+
/*
1697+
* Careful here: at proc_exit we need extra cleanup, not just
1698+
* xact_temporary files.
1699+
*/
1700+
if (isProcExit || have_xact_temporary_files)
16881701
{
16891702
Assert(FileIsNotOpen(0)); /* Make sure ring not corrupted */
16901703
for (i = 1; i < SizeVfdCache; i++)
@@ -1702,6 +1715,8 @@ CleanupTempFiles(bool isProcExit)
17021715
FileClose(i);
17031716
}
17041717
}
1718+
1719+
have_xact_temporary_files = false;
17051720
}
17061721

17071722
while (numAllocatedDescs > 0)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy