Skip to content

Commit eeb3c2d

Browse files
committed
Back off chattiness in RemovePgTempFiles().
In commit 561885d, as part of normalizing RemovePgTempFiles's error handling, I removed its behavior of silently ignoring ENOENT failures during directory opens. Thomas Munro points out that this is a bad idea at the top level, because we don't create pgsql_tmp directories until needed. Thus this coding could produce LOG messages in perfectly normal situations, which isn't what I intended. Restore the suppression of ENOENT logging, but only at top level --- it would still be unexpected for a nested temp directory to disappear between seeing it in the parent directory and opening it. Discussion: https://postgr.es/m/CAEepm=2y06SehAkTnd5sU_eVqdv5P-=Srt1y5vYNQk6yVDVaPw@mail.gmail.com
1 parent 6271fce commit eeb3c2d

File tree

1 file changed

+20
-8
lines changed
  • src/backend/storage/file

1 file changed

+20
-8
lines changed

src/backend/storage/file/fd.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ static int FreeDesc(AllocateDesc *desc);
321321

322322
static void AtProcExit_Files(int code, Datum arg);
323323
static void CleanupTempFiles(bool isProcExit);
324-
static void RemovePgTempFilesInDir(const char *tmpdirname, bool unlink_all);
324+
static void RemovePgTempFilesInDir(const char *tmpdirname, bool missing_ok,
325+
bool unlink_all);
325326
static void RemovePgTempRelationFiles(const char *tsdirname);
326327
static void RemovePgTempRelationFilesInDbspace(const char *dbspacedirname);
327328
static bool looks_like_temp_rel_name(const char *name);
@@ -3010,7 +3011,7 @@ RemovePgTempFiles(void)
30103011
* First process temp files in pg_default ($PGDATA/base)
30113012
*/
30123013
snprintf(temp_path, sizeof(temp_path), "base/%s", PG_TEMP_FILES_DIR);
3013-
RemovePgTempFilesInDir(temp_path, false);
3014+
RemovePgTempFilesInDir(temp_path, true, false);
30143015
RemovePgTempRelationFiles("base");
30153016

30163017
/*
@@ -3026,7 +3027,7 @@ RemovePgTempFiles(void)
30263027

30273028
snprintf(temp_path, sizeof(temp_path), "pg_tblspc/%s/%s/%s",
30283029
spc_de->d_name, TABLESPACE_VERSION_DIRECTORY, PG_TEMP_FILES_DIR);
3029-
RemovePgTempFilesInDir(temp_path, false);
3030+
RemovePgTempFilesInDir(temp_path, true, false);
30303031

30313032
snprintf(temp_path, sizeof(temp_path), "pg_tblspc/%s/%s",
30323033
spc_de->d_name, TABLESPACE_VERSION_DIRECTORY);
@@ -3040,26 +3041,37 @@ RemovePgTempFiles(void)
30403041
* DataDir as well.
30413042
*/
30423043
#ifdef EXEC_BACKEND
3043-
RemovePgTempFilesInDir(PG_TEMP_FILES_DIR, false);
3044+
RemovePgTempFilesInDir(PG_TEMP_FILES_DIR, true, false);
30443045
#endif
30453046
}
30463047

30473048
/*
3048-
* Process one pgsql_tmp directory for RemovePgTempFiles. At the top level in
3049-
* each tablespace, this should be called with unlink_all = false, so that
3049+
* Process one pgsql_tmp directory for RemovePgTempFiles.
3050+
*
3051+
* If missing_ok is true, it's all right for the named directory to not exist.
3052+
* Any other problem results in a LOG message. (missing_ok should be true at
3053+
* the top level, since pgsql_tmp directories are not created until needed.)
3054+
*
3055+
* At the top level, this should be called with unlink_all = false, so that
30503056
* only files matching the temporary name prefix will be unlinked. When
30513057
* recursing it will be called with unlink_all = true to unlink everything
30523058
* under a top-level temporary directory.
3059+
*
3060+
* (These two flags could be replaced by one, but it seems clearer to keep
3061+
* them separate.)
30533062
*/
30543063
static void
3055-
RemovePgTempFilesInDir(const char *tmpdirname, bool unlink_all)
3064+
RemovePgTempFilesInDir(const char *tmpdirname, bool missing_ok, bool unlink_all)
30563065
{
30573066
DIR *temp_dir;
30583067
struct dirent *temp_de;
30593068
char rm_path[MAXPGPATH * 2];
30603069

30613070
temp_dir = AllocateDir(tmpdirname);
30623071

3072+
if (temp_dir == NULL && errno == ENOENT && missing_ok)
3073+
return;
3074+
30633075
while ((temp_de = ReadDirExtended(temp_dir, tmpdirname, LOG)) != NULL)
30643076
{
30653077
if (strcmp(temp_de->d_name, ".") == 0 ||
@@ -3087,7 +3099,7 @@ RemovePgTempFilesInDir(const char *tmpdirname, bool unlink_all)
30873099
if (S_ISDIR(statbuf.st_mode))
30883100
{
30893101
/* recursively remove contents, then directory itself */
3090-
RemovePgTempFilesInDir(rm_path, true);
3102+
RemovePgTempFilesInDir(rm_path, false, true);
30913103

30923104
if (rmdir(rm_path) < 0)
30933105
ereport(LOG,

0 commit comments

Comments
 (0)