提交 d2d3c8ac 编写于 作者: H Heikki Linnakangas

Don't print WARNING for every temporary file being deleted at recovery.

Before this, you would get warnings like this in the log at crash
recovery, for every temporary file that's deleted:

2019-01-28 20:20:45.702848 EET,,,p7513,th-1570674304,,,,0,,,seg1,,,,,"WARNING","01000","could not open directory ""base/pgsql_tmp/pgsql_tmpslice1_tuplestore5876.0"": No such file or directory",,,,,,,,"pgfnames","pgfnames.c",43,

To fix, backport changes PostgreSQL v11, which added the support for
removing temporary directories in upstream. That is, commit dc6c4c9d,
and the follow up commits 561885db and eeb3c2df.
Reviewed-by: NAshwin Agrawal <aagrawal@pivotal.io>
上级 379fceda
......@@ -312,7 +312,8 @@ static int FreeDesc(AllocateDesc *desc);
static void AtProcExit_Files(int code, Datum arg);
static void CleanupTempFiles(bool isProcExit);
static void RemovePgTempFilesInDir(const char *tmpdirname);
static void RemovePgTempFilesInDir(const char *tmpdirname, bool missing_ok,
bool unlink_all);
static void RemovePgTempRelationFiles(const char *tsdirname);
static void RemovePgTempRelationFilesInDbspace(const char *dbspacedirname);
static bool looks_like_temp_rel_name(const char *name);
......@@ -2742,7 +2743,7 @@ RemovePgTempFiles(void)
* First process temp files in pg_default ($PGDATA/base)
*/
snprintf(temp_path, sizeof(temp_path), "base/%s", PG_TEMP_FILES_DIR);
RemovePgTempFilesInDir(temp_path);
RemovePgTempFilesInDir(temp_path, true, false);
RemovePgTempRelationFiles("base");
/*
......@@ -2758,7 +2759,7 @@ RemovePgTempFiles(void)
snprintf(temp_path, sizeof(temp_path), "pg_tblspc/%s/%s/%s",
spc_de->d_name, tablespace_version_directory(), PG_TEMP_FILES_DIR);
RemovePgTempFilesInDir(temp_path);
RemovePgTempFilesInDir(temp_path, true, false);
snprintf(temp_path, sizeof(temp_path), "pg_tblspc/%s/%s",
spc_de->d_name, tablespace_version_directory());
......@@ -2772,30 +2773,38 @@ RemovePgTempFiles(void)
* DataDir as well.
*/
#ifdef EXEC_BACKEND
RemovePgTempFilesInDir(PG_TEMP_FILES_DIR);
RemovePgTempFilesInDir(PG_TEMP_FILES_DIR, true, false);
#endif
}
/* Process one pgsql_tmp directory for RemovePgTempFiles */
/*
* Process one pgsql_tmp directory for RemovePgTempFiles.
*
* If missing_ok is true, it's all right for the named directory to not exist.
* Any other problem results in a LOG message. (missing_ok should be true at
* the top level, since pgsql_tmp directories are not created until needed.)
*
* At the top level, this should be called with unlink_all = false, so that
* only files matching the temporary name prefix will be unlinked. When
* recursing it will be called with unlink_all = true to unlink everything
* under a top-level temporary directory.
*
* (These two flags could be replaced by one, but it seems clearer to keep
* them separate.)
*/
static void
RemovePgTempFilesInDir(const char *tmpdirname)
RemovePgTempFilesInDir(const char *tmpdirname, bool missing_ok, bool unlink_all)
{
DIR *temp_dir;
struct dirent *temp_de;
char rm_path[MAXPGPATH * 2];
temp_dir = AllocateDir(tmpdirname);
if (temp_dir == NULL)
{
/* anything except ENOENT is fishy */
if (errno != ENOENT)
elog(LOG,
"could not open temporary-files directory \"%s\": %m",
tmpdirname);
if (temp_dir == NULL && errno == ENOENT && missing_ok)
return;
}
while ((temp_de = ReadDir(temp_dir, tmpdirname)) != NULL)
while ((temp_de = ReadDirExtended(temp_dir, tmpdirname, LOG)) != NULL)
{
if (strcmp(temp_de->d_name, ".") == 0 ||
strcmp(temp_de->d_name, "..") == 0)
......@@ -2804,23 +2813,45 @@ RemovePgTempFilesInDir(const char *tmpdirname)
snprintf(rm_path, sizeof(rm_path), "%s/%s",
tmpdirname, temp_de->d_name);
if (strncmp(temp_de->d_name,
if (unlink_all ||
strncmp(temp_de->d_name,
PG_TEMP_FILE_PREFIX,
strlen(PG_TEMP_FILE_PREFIX)) == 0)
{
/*
* It can be a file or a directory, so try to delete both ways
* We ignore errors.
*/
unlink(rm_path);
rmtree(rm_path, true);
struct stat statbuf;
if (lstat(rm_path, &statbuf) < 0)
{
ereport(LOG,
(errcode_for_file_access(),
errmsg("could not stat file \"%s\": %m", rm_path)));
continue;
}
if (S_ISDIR(statbuf.st_mode))
{
/* recursively remove contents, then directory itself */
RemovePgTempFilesInDir(rm_path, false, true);
if (rmdir(rm_path) < 0)
ereport(LOG,
(errcode_for_file_access(),
errmsg("could not remove directory \"%s\": %m",
rm_path)));
}
else
{
if (unlink(rm_path) < 0)
ereport(LOG,
(errcode_for_file_access(),
errmsg("could not remove file \"%s\": %m",
rm_path)));
}
}
else
{
elog(LOG,
"unexpected file found in temporary-files directory: \"%s\"",
rm_path);
}
ereport(LOG,
(errmsg("unexpected file found in temporary-files directory: \"%s\"",
rm_path)));
}
FreeDir(temp_dir);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册