@@ -126,8 +126,6 @@ int max_safe_fds = 32; /* default if not changed */
126
126
/* these are the assigned bits in fdstate below: */
127
127
#define FD_TEMPORARY (1 << 0) /* T = delete when closed */
128
128
#define FD_XACT_TEMPORARY (1 << 1) /* T = delete at eoXact */
129
- #define FD_XACT_TRANSIENT (1 << 2) /* T = close (not delete) at aoXact,
130
- * but keep VFD */
131
129
132
130
typedef struct vfd
133
131
{
@@ -158,8 +156,11 @@ static Size SizeVfdCache = 0;
158
156
*/
159
157
static int nfile = 0 ;
160
158
161
- /* True if there are files to close/delete at end of transaction */
162
- static bool have_pending_fd_cleanup = false;
159
+ /*
160
+ * Flag to tell whether it's worth scanning VfdCache looking for temp files
161
+ * to close
162
+ */
163
+ static bool have_xact_temporary_files = false;
163
164
164
165
/*
165
166
* Tracks the total size of all temporary files. Note: when temp_file_limit
@@ -600,7 +601,6 @@ LruDelete(File file)
600
601
Vfd * vfdP ;
601
602
602
603
Assert (file != 0 );
603
- Assert (!FileIsNotOpen (file ));
604
604
605
605
DO_DB (elog (LOG , "LruDelete %d (%s)" ,
606
606
file , VfdCache [file ].fileName ));
@@ -964,7 +964,7 @@ OpenTemporaryFile(bool interXact)
964
964
VfdCache [file ].resowner = CurrentResourceOwner ;
965
965
966
966
/* ensure cleanup happens at eoxact */
967
- have_pending_fd_cleanup = true;
967
+ have_xact_temporary_files = true;
968
968
}
969
969
970
970
return file ;
@@ -1037,25 +1037,6 @@ OpenTemporaryFileInTablespace(Oid tblspcOid, bool rejectError)
1037
1037
return file ;
1038
1038
}
1039
1039
1040
- /*
1041
- * Set the transient flag on a file
1042
- *
1043
- * This flag tells CleanupTempFiles to close the kernel-level file descriptor
1044
- * (but not the VFD itself) at end of transaction.
1045
- */
1046
- void
1047
- FileSetTransient (File file )
1048
- {
1049
- Vfd * vfdP ;
1050
-
1051
- Assert (FileIsValid (file ));
1052
-
1053
- vfdP = & VfdCache [file ];
1054
- vfdP -> fdstate |= FD_XACT_TRANSIENT ;
1055
-
1056
- have_pending_fd_cleanup = true;
1057
- }
1058
-
1059
1040
/*
1060
1041
* close a file when done with it
1061
1042
*/
@@ -1856,9 +1837,8 @@ AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid,
1856
1837
* particularly care which). All still-open per-transaction temporary file
1857
1838
* VFDs are closed, which also causes the underlying files to be deleted
1858
1839
* (although they should've been closed already by the ResourceOwner
1859
- * cleanup). Transient files have their kernel file descriptors closed.
1860
- * Furthermore, all "allocated" stdio files are closed. We also forget any
1861
- * transaction-local temp tablespace list.
1840
+ * cleanup). Furthermore, all "allocated" stdio files are closed. We also
1841
+ * forget any transaction-local temp tablespace list.
1862
1842
*/
1863
1843
void
1864
1844
AtEOXact_Files (void )
@@ -1881,10 +1861,7 @@ AtProcExit_Files(int code, Datum arg)
1881
1861
}
1882
1862
1883
1863
/*
1884
- * General cleanup routine for fd.c.
1885
- *
1886
- * Temporary files are closed, and their underlying files deleted.
1887
- * Transient files are closed.
1864
+ * Close temporary files and delete their underlying files.
1888
1865
*
1889
1866
* isProcExit: if true, this is being called as the backend process is
1890
1867
* exiting. If that's the case, we should remove all temporary files; if
@@ -1901,51 +1878,35 @@ CleanupTempFiles(bool isProcExit)
1901
1878
* Careful here: at proc_exit we need extra cleanup, not just
1902
1879
* xact_temporary files.
1903
1880
*/
1904
- if (isProcExit || have_pending_fd_cleanup )
1881
+ if (isProcExit || have_xact_temporary_files )
1905
1882
{
1906
1883
Assert (FileIsNotOpen (0 )); /* Make sure ring not corrupted */
1907
1884
for (i = 1 ; i < SizeVfdCache ; i ++ )
1908
1885
{
1909
1886
unsigned short fdstate = VfdCache [i ].fdstate ;
1910
1887
1911
- if (VfdCache [i ].fileName != NULL )
1888
+ if (( fdstate & FD_TEMPORARY ) && VfdCache [i ].fileName != NULL )
1912
1889
{
1913
- if (fdstate & FD_TEMPORARY )
1914
- {
1915
- /*
1916
- * If we're in the process of exiting a backend process,
1917
- * close all temporary files. Otherwise, only close
1918
- * temporary files local to the current transaction. They
1919
- * should be closed by the ResourceOwner mechanism
1920
- * already, so this is just a debugging cross-check.
1921
- */
1922
- if (isProcExit )
1923
- FileClose (i );
1924
- else if (fdstate & FD_XACT_TEMPORARY )
1925
- {
1926
- elog (WARNING ,
1927
- "temporary file %s not closed at end-of-transaction" ,
1928
- VfdCache [i ].fileName );
1929
- FileClose (i );
1930
- }
1931
- }
1932
- else if (fdstate & FD_XACT_TRANSIENT )
1890
+ /*
1891
+ * If we're in the process of exiting a backend process, close
1892
+ * all temporary files. Otherwise, only close temporary files
1893
+ * local to the current transaction. They should be closed by
1894
+ * the ResourceOwner mechanism already, so this is just a
1895
+ * debugging cross-check.
1896
+ */
1897
+ if (isProcExit )
1898
+ FileClose (i );
1899
+ else if (fdstate & FD_XACT_TEMPORARY )
1933
1900
{
1934
- /*
1935
- * Close the FD, and remove the entry from the LRU ring,
1936
- * but also remove the flag from the VFD. This is to
1937
- * ensure that if the VFD is reused in the future for
1938
- * non-transient access, we don't close it inappropriately
1939
- * then.
1940
- */
1941
- if (!FileIsNotOpen (i ))
1942
- LruDelete (i );
1943
- VfdCache [i ].fdstate &= ~FD_XACT_TRANSIENT ;
1901
+ elog (WARNING ,
1902
+ "temporary file %s not closed at end-of-transaction" ,
1903
+ VfdCache [i ].fileName );
1904
+ FileClose (i );
1944
1905
}
1945
1906
}
1946
1907
}
1947
1908
1948
- have_pending_fd_cleanup = false;
1909
+ have_xact_temporary_files = false;
1949
1910
}
1950
1911
1951
1912
/* Clean up "allocated" stdio files and dirs. */
0 commit comments