Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita1f064f

Browse files
committed
Revert "Use "transient" files for blind writes, take 2".
This reverts commitfba105b.That approach had problems with the smgr-level state not tracking whatwe really want to happen, and with the VFD-level state not tracking thesmgr-level state very well either. In consequence, it was still possibleto hold kernel file descriptors open for long-gone tables (as in recentreport from Tore Halset), and yet there were also cases of FDs being closedundesirably soon. A replacement implementation will follow.
1 parent4be1d01 commita1f064f

File tree

6 files changed

+28
-102
lines changed

6 files changed

+28
-102
lines changed

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,10 +1882,7 @@ BufferGetTag(Buffer buffer, RelFileNode *rnode, ForkNumber *forknum,
18821882
* written.)
18831883
*
18841884
* If the caller has an smgr reference for the buffer's relation, pass it
1885-
* as the second parameter. If not, pass NULL. In the latter case, the
1886-
* relation will be marked as "transient" so that the corresponding
1887-
* kernel-level file descriptors are closed when the current transaction ends,
1888-
* if any.
1885+
* as the second parameter. If not, pass NULL.
18891886
*/
18901887
staticvoid
18911888
FlushBuffer(volatileBufferDesc*buf,SMgrRelationreln)
@@ -1909,12 +1906,9 @@ FlushBuffer(volatile BufferDesc *buf, SMgrRelation reln)
19091906
errcontext.previous=error_context_stack;
19101907
error_context_stack=&errcontext;
19111908

1912-
/* Find smgr relation for buffer, and mark it as transient */
1909+
/* Find smgr relation for buffer */
19131910
if (reln==NULL)
1914-
{
19151911
reln=smgropen(buf->tag.rnode,InvalidBackendId);
1916-
smgrsettransient(reln);
1917-
}
19181912

19191913
TRACE_POSTGRESQL_BUFFER_FLUSH_START(buf->tag.forkNum,
19201914
buf->tag.blockNum,

‎src/backend/storage/file/fd.c

Lines changed: 26 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ intmax_safe_fds = 32;/* default if not changed */
126126
/* these are the assigned bits in fdstate below: */
127127
#defineFD_TEMPORARY(1 << 0)/* T = delete when closed */
128128
#defineFD_XACT_TEMPORARY(1 << 1)/* T = delete at eoXact */
129-
#defineFD_XACT_TRANSIENT(1 << 2)/* T = close (not delete) at aoXact,
130-
* but keep VFD */
131129

132130
typedefstructvfd
133131
{
@@ -158,8 +156,11 @@ static Size SizeVfdCache = 0;
158156
*/
159157
staticintnfile=0;
160158

161-
/* True if there are files to close/delete at end of transaction */
162-
staticboolhave_pending_fd_cleanup= false;
159+
/*
160+
* Flag to tell whether it's worth scanning VfdCache looking for temp files
161+
* to close
162+
*/
163+
staticboolhave_xact_temporary_files= false;
163164

164165
/*
165166
* Tracks the total size of all temporary files. Note: when temp_file_limit
@@ -600,7 +601,6 @@ LruDelete(File file)
600601
Vfd*vfdP;
601602

602603
Assert(file!=0);
603-
Assert(!FileIsNotOpen(file));
604604

605605
DO_DB(elog(LOG,"LruDelete %d (%s)",
606606
file,VfdCache[file].fileName));
@@ -964,7 +964,7 @@ OpenTemporaryFile(bool interXact)
964964
VfdCache[file].resowner=CurrentResourceOwner;
965965

966966
/* ensure cleanup happens at eoxact */
967-
have_pending_fd_cleanup= true;
967+
have_xact_temporary_files= true;
968968
}
969969

970970
returnfile;
@@ -1037,25 +1037,6 @@ OpenTemporaryFileInTablespace(Oid tblspcOid, bool rejectError)
10371037
returnfile;
10381038
}
10391039

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(Filefile)
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-
10591040
/*
10601041
* close a file when done with it
10611042
*/
@@ -1856,9 +1837,8 @@ AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid,
18561837
* particularly care which). All still-open per-transaction temporary file
18571838
* VFDs are closed, which also causes the underlying files to be deleted
18581839
* (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.
18621842
*/
18631843
void
18641844
AtEOXact_Files(void)
@@ -1881,10 +1861,7 @@ AtProcExit_Files(int code, Datum arg)
18811861
}
18821862

18831863
/*
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.
18881865
*
18891866
* isProcExit: if true, this is being called as the backend process is
18901867
* exiting. If that's the case, we should remove all temporary files; if
@@ -1901,51 +1878,35 @@ CleanupTempFiles(bool isProcExit)
19011878
* Careful here: at proc_exit we need extra cleanup, not just
19021879
* xact_temporary files.
19031880
*/
1904-
if (isProcExit||have_pending_fd_cleanup)
1881+
if (isProcExit||have_xact_temporary_files)
19051882
{
19061883
Assert(FileIsNotOpen(0));/* Make sure ring not corrupted */
19071884
for (i=1;i<SizeVfdCache;i++)
19081885
{
19091886
unsigned shortfdstate=VfdCache[i].fdstate;
19101887

1911-
if (VfdCache[i].fileName!=NULL)
1888+
if ((fdstate&FD_TEMPORARY)&&VfdCache[i].fileName!=NULL)
19121889
{
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-
elseif (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-
elseif (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+
elseif (fdstate&FD_XACT_TEMPORARY)
19331900
{
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);
19441905
}
19451906
}
19461907
}
19471908

1948-
have_pending_fd_cleanup= false;
1909+
have_xact_temporary_files= false;
19491910
}
19501911

19511912
/* Clean up "allocated" stdio files and dirs. */

‎src/backend/storage/smgr/md.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,6 @@ mdcreate(SMgrRelation reln, ForkNumber forkNum, bool isRedo)
300300

301301
pfree(path);
302302

303-
if (reln->smgr_transient)
304-
FileSetTransient(fd);
305-
306303
reln->md_fd[forkNum]=_fdvec_alloc();
307304

308305
reln->md_fd[forkNum]->mdfd_vfd=fd;
@@ -585,9 +582,6 @@ mdopen(SMgrRelation reln, ForkNumber forknum, ExtensionBehavior behavior)
585582

586583
pfree(path);
587584

588-
if (reln->smgr_transient)
589-
FileSetTransient(fd);
590-
591585
reln->md_fd[forknum]=mdfd=_fdvec_alloc();
592586

593587
mdfd->mdfd_vfd=fd;
@@ -1680,9 +1674,6 @@ _mdfd_openseg(SMgrRelation reln, ForkNumber forknum, BlockNumber segno,
16801674
if (fd<0)
16811675
returnNULL;
16821676

1683-
if (reln->smgr_transient)
1684-
FileSetTransient(fd);
1685-
16861677
/* allocate an mdfdvec entry for it */
16871678
v=_fdvec_alloc();
16881679

‎src/backend/storage/smgr/smgr.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163,33 +163,16 @@ smgropen(RelFileNode rnode, BackendId backend)
163163
reln->smgr_targblock=InvalidBlockNumber;
164164
reln->smgr_fsm_nblocks=InvalidBlockNumber;
165165
reln->smgr_vm_nblocks=InvalidBlockNumber;
166-
reln->smgr_transient= false;
167166
reln->smgr_which=0;/* we only have md.c at present */
168167

169168
/* mark it not open */
170169
for (forknum=0;forknum <=MAX_FORKNUM;forknum++)
171170
reln->md_fd[forknum]=NULL;
172171
}
173-
else
174-
/* if it was transient before, it no longer is */
175-
reln->smgr_transient= false;
176172

177173
returnreln;
178174
}
179175

180-
/*
181-
* smgrsettransient() -- mark an SMgrRelation object as transaction-bound
182-
*
183-
* The main effect of this is that all opened files are marked to be
184-
* kernel-level closed (but not necessarily VFD-closed) when the current
185-
* transaction ends.
186-
*/
187-
void
188-
smgrsettransient(SMgrRelationreln)
189-
{
190-
reln->smgr_transient= true;
191-
}
192-
193176
/*
194177
* smgrsetowner() -- Establish a long-lived reference to an SMgrRelation object
195178
*

‎src/include/storage/fd.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ extern intmax_safe_fds;
6666
/* Operations on virtual Files --- equivalent to Unix kernel file ops */
6767
externFilePathNameOpenFile(FileNamefileName,intfileFlags,intfileMode);
6868
externFileOpenTemporaryFile(boolinterXact);
69-
externvoidFileSetTransient(Filefile);
7069
externvoidFileClose(Filefile);
7170
externintFilePrefetch(Filefile,off_toffset,intamount);
7271
externintFileRead(Filefile,char*buffer,intamount);

‎src/include/storage/smgr.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ typedef struct SMgrRelationData
6060
* submodules.Do not touch them from elsewhere.
6161
*/
6262
intsmgr_which;/* storage manager selector */
63-
boolsmgr_transient;/* T if files are to be closed at EOXact */
6463

6564
/* for md.c; NULL for forks that are not open */
6665
struct_MdfdVec*md_fd[MAX_FORKNUM+1];
@@ -73,7 +72,6 @@ typedef SMgrRelationData *SMgrRelation;
7372

7473
externvoidsmgrinit(void);
7574
externSMgrRelationsmgropen(RelFileNodernode,BackendIdbackend);
76-
externvoidsmgrsettransient(SMgrRelationreln);
7775
externboolsmgrexists(SMgrRelationreln,ForkNumberforknum);
7876
externvoidsmgrsetowner(SMgrRelation*owner,SMgrRelationreln);
7977
externvoidsmgrclose(SMgrRelationreln);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp