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

Commit9cb7db3

Browse files
committed
In AtEOXact_Files, complain if any files remain unclosed at commit.
This change makes this module act more like most of our other low-levelresource management modules. It's a caller error if something is notexplicitly closed by the end of a successful transaction, so issuea WARNING about it. This would not actually have caught the file leakbug fixed in commit231bcd0, because that was in a transaction-abortpath; but it still seems like a good, and pretty cheap, cross-check.Discussion:https://postgr.es/m/152056616579.4966.583293218357089052@wrigleys.postgresql.org
1 parentcfffe83 commit9cb7db3

File tree

7 files changed

+29
-19
lines changed

7 files changed

+29
-19
lines changed

‎src/backend/access/transam/xact.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,7 +2123,7 @@ CommitTransaction(void)
21232123
AtEOXact_on_commit_actions(true);
21242124
AtEOXact_Namespace(true,is_parallel_worker);
21252125
AtEOXact_SMgr();
2126-
AtEOXact_Files();
2126+
AtEOXact_Files(true);
21272127
AtEOXact_ComboCid();
21282128
AtEOXact_HashTables(true);
21292129
AtEOXact_PgStat(true);
@@ -2401,7 +2401,7 @@ PrepareTransaction(void)
24012401
AtEOXact_on_commit_actions(true);
24022402
AtEOXact_Namespace(true, false);
24032403
AtEOXact_SMgr();
2404-
AtEOXact_Files();
2404+
AtEOXact_Files(true);
24052405
AtEOXact_ComboCid();
24062406
AtEOXact_HashTables(true);
24072407
/* don't call AtEOXact_PgStat here; we fixed pgstat state above */
@@ -2603,7 +2603,7 @@ AbortTransaction(void)
26032603
AtEOXact_on_commit_actions(false);
26042604
AtEOXact_Namespace(false,is_parallel_worker);
26052605
AtEOXact_SMgr();
2606-
AtEOXact_Files();
2606+
AtEOXact_Files(false);
26072607
AtEOXact_ComboCid();
26082608
AtEOXact_HashTables(false);
26092609
AtEOXact_PgStat(false);

‎src/backend/postmaster/autovacuum.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ AutoVacLauncherMain(int argc, char *argv[])
531531
}
532532
AtEOXact_Buffers(false);
533533
AtEOXact_SMgr();
534-
AtEOXact_Files();
534+
AtEOXact_Files(false);
535535
AtEOXact_HashTables(false);
536536

537537
/*

‎src/backend/postmaster/bgwriter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ BackgroundWriterMain(void)
198198
/* we needn't bother with the other ResourceOwnerRelease phases */
199199
AtEOXact_Buffers(false);
200200
AtEOXact_SMgr();
201-
AtEOXact_Files();
201+
AtEOXact_Files(false);
202202
AtEOXact_HashTables(false);
203203

204204
/*

‎src/backend/postmaster/checkpointer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ CheckpointerMain(void)
282282
/* we needn't bother with the other ResourceOwnerRelease phases */
283283
AtEOXact_Buffers(false);
284284
AtEOXact_SMgr();
285-
AtEOXact_Files();
285+
AtEOXact_Files(false);
286286
AtEOXact_HashTables(false);
287287

288288
/* Warn any waiting backends that the checkpoint failed. */

‎src/backend/postmaster/walwriter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ WalWriterMain(void)
179179
/* we needn't bother with the other ResourceOwnerRelease phases */
180180
AtEOXact_Buffers(false);
181181
AtEOXact_SMgr();
182-
AtEOXact_Files();
182+
AtEOXact_Files(false);
183183
AtEOXact_HashTables(false);
184184

185185
/*

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ static bool reserveAllocatedDesc(void);
314314
staticintFreeDesc(AllocateDesc*desc);
315315

316316
staticvoidAtProcExit_Files(intcode,Datumarg);
317-
staticvoidCleanupTempFiles(boolisProcExit);
317+
staticvoidCleanupTempFiles(boolisCommit,boolisProcExit);
318318
staticvoidRemovePgTempFilesInDir(constchar*tmpdirname,boolmissing_ok,
319319
boolunlink_all);
320320
staticvoidRemovePgTempRelationFiles(constchar*tsdirname);
@@ -2902,17 +2902,19 @@ AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid,
29022902
/*
29032903
* AtEOXact_Files
29042904
*
2905-
* This routine is called during transaction commit or abort (it doesn't
2906-
* particularly care which). All still-open per-transaction temporary file
2907-
* VFDs are closed, which also causes the underlying files to be deleted
2908-
* (although they should've been closed already by the ResourceOwner
2909-
* cleanup). Furthermore, all "allocated" stdio files are closed. We also
2910-
* forget any transaction-local temp tablespace list.
2905+
* This routine is called during transaction commit or abort. All still-open
2906+
* per-transaction temporary file VFDs are closed, which also causes the
2907+
* underlying files to be deleted (although they should've been closed already
2908+
* by the ResourceOwner cleanup). Furthermore, all "allocated" stdio files are
2909+
* closed. We also forget any transaction-local temp tablespace list.
2910+
*
2911+
* The isCommit flag is used only to decide whether to emit warnings about
2912+
* unclosed files.
29112913
*/
29122914
void
2913-
AtEOXact_Files(void)
2915+
AtEOXact_Files(boolisCommit)
29142916
{
2915-
CleanupTempFiles(false);
2917+
CleanupTempFiles(isCommit,false);
29162918
tempTableSpaces=NULL;
29172919
numTempTableSpaces=-1;
29182920
}
@@ -2926,20 +2928,23 @@ AtEOXact_Files(void)
29262928
staticvoid
29272929
AtProcExit_Files(intcode,Datumarg)
29282930
{
2929-
CleanupTempFiles(true);
2931+
CleanupTempFiles(false,true);
29302932
}
29312933

29322934
/*
29332935
* Close temporary files and delete their underlying files.
29342936
*
2937+
* isCommit: if true, this is normal transaction commit, and we don't
2938+
* expect any remaining files; warn if there are some.
2939+
*
29352940
* isProcExit: if true, this is being called as the backend process is
29362941
* exiting. If that's the case, we should remove all temporary files; if
29372942
* that's not the case, we are being called for transaction commit/abort
29382943
* and should only remove transaction-local temp files. In either case,
29392944
* also clean up "allocated" stdio files, dirs and fds.
29402945
*/
29412946
staticvoid
2942-
CleanupTempFiles(boolisProcExit)
2947+
CleanupTempFiles(boolisCommit,boolisProcExit)
29432948
{
29442949
Indexi;
29452950

@@ -2979,6 +2984,11 @@ CleanupTempFiles(bool isProcExit)
29792984
have_xact_temporary_files= false;
29802985
}
29812986

2987+
/* Complain if any allocated files remain open at commit. */
2988+
if (isCommit&&numAllocatedDescs>0)
2989+
elog(WARNING,"%d temporary files and directories not closed at end-of-transaction",
2990+
numAllocatedDescs);
2991+
29822992
/* Clean up "allocated" stdio files, dirs and fds. */
29832993
while (numAllocatedDescs>0)
29842994
FreeDesc(&allocatedDescs[0]);

‎src/include/storage/fd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ extern void SetTempTablespaces(Oid *tableSpaces, int numSpaces);
123123
externboolTempTablespacesAreSet(void);
124124
externintGetTempTablespaces(Oid*tableSpaces,intnumSpaces);
125125
externOidGetNextTempTableSpace(void);
126-
externvoidAtEOXact_Files(void);
126+
externvoidAtEOXact_Files(boolisCommit);
127127
externvoidAtEOSubXact_Files(boolisCommit,SubTransactionIdmySubid,
128128
SubTransactionIdparentSubid);
129129
externvoidRemovePgTempFiles(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp