Repository: incubator-hawq Updated Branches: refs/heads/master e20e16b72 -> c8501c652
HAWQ-1520. Create filespace should also skip hdfs trash directory Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/c8501c65 Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/c8501c65 Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/c8501c65 Branch: refs/heads/master Commit: c8501c6523b3a57d79fdd0480382bf040e6abb4c Parents: e20e16b Author: interma <[email protected]> Authored: Fri Sep 1 15:57:34 2017 +0800 Committer: rlei <[email protected]> Committed: Mon Sep 4 16:01:19 2017 +0800 ---------------------------------------------------------------------- src/backend/commands/filespace.c | 3 +-- src/backend/storage/file/fd.c | 23 +++++++++++++++++++++-- src/include/storage/fd.h | 6 +++++- 3 files changed, 27 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/c8501c65/src/backend/commands/filespace.c ---------------------------------------------------------------------- diff --git a/src/backend/commands/filespace.c b/src/backend/commands/filespace.c index 2bda12b..69578a4 100644 --- a/src/backend/commands/filespace.c +++ b/src/backend/commands/filespace.c @@ -318,11 +318,10 @@ CreateFileSpace(CreateFileSpaceStmt *stmt) encoded = EncodeFileLocations(stmt->fsysname, fsrep, stmt->location); bool existed; - if (HdfsPathExistAndNonEmpty(encoded, &existed)) + if (HdfsPathExistAndNonEmpty(encoded, &existed, true)) /* skip hdfs trash directory */ ereport(ERROR, (errcode_for_file_access(), errmsg("%s: File exists and non empty", encoded))); - add_catalog_filespace_entry(rel, fsoid, 0, encoded); heap_close(rel, RowExclusiveLock); http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/c8501c65/src/backend/storage/file/fd.c ---------------------------------------------------------------------- diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 2366318..cceb645 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -3448,8 +3448,25 @@ HdfsPathExist(char *path) return 0 == hdfsExists(fs, relative_path); } +/* + * check path is a trash directory + * path, e.g: /hawq_default/.Trash + */ +static int +isTrashDirectory(const char *path) +{ + if (path == NULL) + return 0; + size_t len = strlen(TRASH_DIRECTORY_NAME); + size_t path_len = strlen(path); + if (path_len <= len) + return 0; + + return strncmp(path+path_len-len, TRASH_DIRECTORY_NAME, len+1) == 0; +} + bool -HdfsPathExistAndNonEmpty(char *path, bool *existed) +HdfsPathExistAndNonEmpty(char *path, bool *existed, bool skip_trash) { char relative_path[MAXPGPATH + 1]; char *protocol; @@ -3480,7 +3497,9 @@ HdfsPathExistAndNonEmpty(char *path, bool *existed) int num; hdfsFileInfo *fi = hdfsListDirectory(fs, relative_path, &num); *existed = true; - if (NULL == fi || 0 != num) + if (NULL == fi || num > 1 || + (skip_trash && num == 1 && !isTrashDirectory(fi[0].mName)) /* skip Trash directory */ + ) { return true; } http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/c8501c65/src/include/storage/fd.h ---------------------------------------------------------------------- diff --git a/src/include/storage/fd.h b/src/include/storage/fd.h index dde0c69..923e129 100644 --- a/src/include/storage/fd.h +++ b/src/include/storage/fd.h @@ -184,7 +184,11 @@ extern size_t GetTempFilePrefix(char * buf, size_t buflen, const char * fileName extern bool TestFileValid(File file); extern bool HdfsPathExist(char *path); -extern bool HdfsPathExistAndNonEmpty(char *path, bool *existed); + +/* hdfs trash direcotry name */ +#define TRASH_DIRECTORY_NAME ".Trash" + +extern bool HdfsPathExistAndNonEmpty(char *path, bool *existed, bool skip_trash); extern int64 HdfsPathSize(const char *path);
