@@ -125,11 +125,12 @@ static int max_safe_fds = 32; /* default if not changed */
125
125
/* these are the assigned bits in fdstate below: */
126
126
#define FD_TEMPORARY (1 << 0) /* T = delete when closed */
127
127
#define FD_XACT_TEMPORARY (1 << 1) /* T = delete at eoXact */
128
- #define FD_XACT_TRANSIENT (1 << 2) /* T = close (not delete) at aoXact,
129
- * but keep VFD */
130
128
131
- /* Flag to tell whether there are files to close/delete at end of transaction */
132
- static bool have_pending_fd_cleanup = false;
129
+ /*
130
+ * Flag to tell whether it's worth scanning VfdCache looking for temp files to
131
+ * close
132
+ */
133
+ static bool have_xact_temporary_files = false;
133
134
134
135
typedef struct vfd
135
136
{
@@ -590,7 +591,6 @@ LruDelete(File file)
590
591
Vfd * vfdP ;
591
592
592
593
Assert (file != 0 );
593
- Assert (!FileIsNotOpen (file ));
594
594
595
595
DO_DB (elog (LOG , "LruDelete %d (%s)" ,
596
596
file , VfdCache [file ].fileName ));
@@ -953,7 +953,7 @@ OpenTemporaryFile(bool interXact)
953
953
VfdCache [file ].resowner = CurrentResourceOwner ;
954
954
955
955
/* ensure cleanup happens at eoxact */
956
- have_pending_fd_cleanup = true;
956
+ have_xact_temporary_files = true;
957
957
}
958
958
959
959
return file ;
@@ -1026,25 +1026,6 @@ OpenTemporaryFileInTablespace(Oid tblspcOid, bool rejectError)
1026
1026
return file ;
1027
1027
}
1028
1028
1029
- /*
1030
- * Set the transient flag on a file
1031
- *
1032
- * This flag tells CleanupTempFiles to close the kernel-level file descriptor
1033
- * (but not the VFD itself) at end of transaction.
1034
- */
1035
- void
1036
- FileSetTransient (File file )
1037
- {
1038
- Vfd * vfdP ;
1039
-
1040
- Assert (FileIsValid (file ));
1041
-
1042
- vfdP = & VfdCache [file ];
1043
- vfdP -> fdstate |= FD_XACT_TRANSIENT ;
1044
-
1045
- have_pending_fd_cleanup = true;
1046
- }
1047
-
1048
1029
/*
1049
1030
* close a file when done with it
1050
1031
*/
@@ -1797,9 +1778,8 @@ AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid,
1797
1778
* particularly care which). All still-open per-transaction temporary file
1798
1779
* VFDs are closed, which also causes the underlying files to be deleted
1799
1780
* (although they should've been closed already by the ResourceOwner
1800
- * cleanup). Transient files have their kernel file descriptors closed.
1801
- * Furthermore, all "allocated" stdio files are closed. We also forget any
1802
- * transaction-local temp tablespace list.
1781
+ * cleanup). Furthermore, all "allocated" stdio files are closed. We also
1782
+ * forget any transaction-local temp tablespace list.
1803
1783
*/
1804
1784
void
1805
1785
AtEOXact_Files (void )
@@ -1822,10 +1802,7 @@ AtProcExit_Files(int code, Datum arg)
1822
1802
}
1823
1803
1824
1804
/*
1825
- * General cleanup routine for fd.c.
1826
- *
1827
- * Temporary files are closed, and their underlying files deleted.
1828
- * Transient files are closed.
1805
+ * Close temporary files and delete their underlying files.
1829
1806
*
1830
1807
* isProcExit: if true, this is being called as the backend process is
1831
1808
* exiting. If that's the case, we should remove all temporary files; if
@@ -1842,51 +1819,35 @@ CleanupTempFiles(bool isProcExit)
1842
1819
* Careful here: at proc_exit we need extra cleanup, not just
1843
1820
* xact_temporary files.
1844
1821
*/
1845
- if (isProcExit || have_pending_fd_cleanup )
1822
+ if (isProcExit || have_xact_temporary_files )
1846
1823
{
1847
1824
Assert (FileIsNotOpen (0 )); /* Make sure ring not corrupted */
1848
1825
for (i = 1 ; i < SizeVfdCache ; i ++ )
1849
1826
{
1850
1827
unsigned short fdstate = VfdCache [i ].fdstate ;
1851
1828
1852
- if (VfdCache [i ].fileName != NULL )
1829
+ if (( fdstate & FD_TEMPORARY ) && VfdCache [i ].fileName != NULL )
1853
1830
{
1854
- if (fdstate & FD_TEMPORARY )
1855
- {
1856
- /*
1857
- * If we're in the process of exiting a backend process, close
1858
- * all temporary files. Otherwise, only close temporary files
1859
- * local to the current transaction. They should be closed by
1860
- * the ResourceOwner mechanism already, so this is just a
1861
- * debugging cross-check.
1862
- */
1863
- if (isProcExit )
1864
- FileClose (i );
1865
- else if (fdstate & FD_XACT_TEMPORARY )
1866
- {
1867
- elog (WARNING ,
1868
- "temporary file %s not closed at end-of-transaction" ,
1869
- VfdCache [i ].fileName );
1870
- FileClose (i );
1871
- }
1872
- }
1873
- else if (fdstate & FD_XACT_TRANSIENT )
1831
+ /*
1832
+ * If we're in the process of exiting a backend process, close
1833
+ * all temporary files. Otherwise, only close temporary files
1834
+ * local to the current transaction. They should be closed by
1835
+ * the ResourceOwner mechanism already, so this is just a
1836
+ * debugging cross-check.
1837
+ */
1838
+ if (isProcExit )
1839
+ FileClose (i );
1840
+ else if (fdstate & FD_XACT_TEMPORARY )
1874
1841
{
1875
- /*
1876
- * Close the FD, and remove the entry from the LRU ring,
1877
- * but also remove the flag from the VFD. This is to
1878
- * ensure that if the VFD is reused in the future for
1879
- * non-transient access, we don't close it inappropriately
1880
- * then.
1881
- */
1882
- if (!FileIsNotOpen (i ))
1883
- LruDelete (i );
1884
- VfdCache [i ].fdstate &= ~FD_XACT_TRANSIENT ;
1842
+ elog (WARNING ,
1843
+ "temporary file %s not closed at end-of-transaction" ,
1844
+ VfdCache [i ].fileName );
1845
+ FileClose (i );
1885
1846
}
1886
1847
}
1887
1848
}
1888
1849
1889
- have_pending_fd_cleanup = false;
1850
+ have_xact_temporary_files = false;
1890
1851
}
1891
1852
1892
1853
/* Clean up "allocated" stdio files and dirs. */
0 commit comments