未验证 提交 b1b99c43 编写于 作者: J Jinbao Chen 提交者: GitHub

Check whether the directory exists when deleting the tablespace (#10305)

If the directory of tablespace does not exist, we should got a
error on commit transaction. But error on commit transaction will
cause a panic. So the directory of tablespace should be checked
so that we can avoid panic.
上级 e52dd032
......@@ -1062,7 +1062,7 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
/* remove empty directory */
if (rmdir(subfile) < 0)
ereport(redo ? LOG : ERROR,
ereport(redo ? LOG : WARNING,
(errcode_for_file_access(),
errmsg("could not remove directory \"%s\": %m",
subfile)));
......@@ -1075,7 +1075,7 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
/* remove version directory */
if (rmdir(linkloc_with_version_dir) < 0)
{
ereport(redo ? LOG : ERROR,
ereport(redo ? LOG : WARNING,
(errcode_for_file_access(),
errmsg("could not remove directory \"%s\": %m",
linkloc_with_version_dir)));
......@@ -1104,14 +1104,14 @@ remove_symlink:
rllen = readlink(linkloc, link_target_dir, sizeof(link_target_dir));
if(rllen < 0)
{
ereport(redo ? LOG : ERROR,
ereport(redo ? LOG : WARNING,
(errcode_for_file_access(),
errmsg("could not read symbolic link \"%s\": %m",
linkloc)));
}
else if(rllen >= sizeof(link_target_dir))
{
ereport(redo ? LOG : ERROR,
ereport(redo ? LOG : WARNING,
(errcode_for_file_access(),
errmsg("symbolic link \"%s\" target is too long",
linkloc)));
......@@ -1119,11 +1119,21 @@ remove_symlink:
else
{
link_target_dir[rllen] = '\0';
if(directory_is_empty(link_target_dir) && rmdir(link_target_dir) < 0)
ereport(redo ? LOG : ERROR,
(errcode_for_file_access(),
errmsg("could not remove directory \"%s\": %m",
link_target_dir)));
if (access(link_target_dir, F_OK) != 0)
{
ereport(WARNING,
(errcode_for_file_access(),
errmsg("could not open directory \"%s\": %m",
link_target_dir)));
}
else
{
if(directory_is_empty(link_target_dir) && rmdir(link_target_dir) < 0)
ereport(redo ? LOG : WARNING,
(errcode_for_file_access(),
errmsg("could not remove directory \"%s\": %m",
link_target_dir)));
}
}
......@@ -1131,7 +1141,7 @@ remove_symlink:
{
int saved_errno = errno;
ereport(redo ? LOG : (saved_errno == ENOENT ? WARNING : ERROR),
ereport(redo ? LOG : WARNING,
(errcode_for_file_access(),
errmsg("could not stat file \"%s\": %m",
linkloc)));
......@@ -1142,7 +1152,7 @@ remove_symlink:
{
int saved_errno = errno;
ereport(redo ? LOG : (saved_errno == ENOENT ? WARNING : ERROR),
ereport(redo ? LOG : WARNING,
(errcode_for_file_access(),
errmsg("could not remove directory \"%s\": %m",
linkloc)));
......@@ -1155,7 +1165,7 @@ remove_symlink:
{
int saved_errno = errno;
ereport(redo ? LOG : (saved_errno == ENOENT ? WARNING : ERROR),
ereport(redo ? LOG : WARNING,
(errcode_for_file_access(),
errmsg("could not remove symbolic link \"%s\": %m",
linkloc)));
......@@ -1165,7 +1175,7 @@ remove_symlink:
else
{
/* Refuse to remove anything that's not a directory or symlink */
ereport(redo ? LOG : ERROR,
ereport(redo ? LOG : WARNING,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("\"%s\" is not a directory or symbolic link",
linkloc)));
......
......@@ -205,3 +205,9 @@ SELECT COUNT(*) FROM tblspc_otherloc_heap;
DROP TABLE tblspc_otherloc_heap;
DROP TABLESPACE testspace_otherloc;
CREATE TABLESPACE testspace_dir_empty LOCATION '@testtablespace@';
CREATE TABLE t_dir_empty(a int);
\! rm -rf @testtablespace@/*;
DROP TABLE IF EXISTS t_dir_empty;
DROP TABLESPACE testspace_dir_empty;
......@@ -380,3 +380,12 @@ SELECT COUNT(*) FROM tblspc_otherloc_heap;
DROP TABLE tblspc_otherloc_heap;
DROP TABLESPACE testspace_otherloc;
CREATE TABLESPACE testspace_dir_empty LOCATION '@testtablespace@';
CREATE TABLE t_dir_empty(a int);
\! rm -rf @testtablespace@/*;
DROP TABLE IF EXISTS t_dir_empty;
DROP TABLESPACE testspace_dir_empty;
WARNING: could not open directory "@testtablespace@/2": No such file or directory (seg0 127.0.0.1:7002 pid=3000)
WARNING: could not open directory "@testtablespace@/3": No such file or directory (seg1 127.0.0.1:7003 pid=3001)
WARNING: could not open directory "@testtablespace@/4": No such file or directory (seg2 127.0.0.1:7004 pid=3002)
WARNING: could not open directory "@testtablespace@/1": No such file or directory
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册