Repository: incubator-hawq Updated Branches: refs/heads/master c59dcd416 -> cf27070ed
HAWQ-1520. gpcheckhdfs should 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/cf27070e Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/cf27070e Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/cf27070e Branch: refs/heads/master Commit: cf27070eddd3eb5480a7d67fd171dbe82cfbef17 Parents: c59dcd4 Author: interma <[email protected]> Authored: Tue Aug 29 15:46:24 2017 +0800 Committer: rlei <[email protected]> Committed: Thu Aug 31 15:09:36 2017 +0800 ---------------------------------------------------------------------- src/bin/gpcheckhdfs/gpcheckhdfs.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cf27070e/src/bin/gpcheckhdfs/gpcheckhdfs.c ---------------------------------------------------------------------- diff --git a/src/bin/gpcheckhdfs/gpcheckhdfs.c b/src/bin/gpcheckhdfs/gpcheckhdfs.c index bf477a9..d9a1144 100644 --- a/src/bin/gpcheckhdfs/gpcheckhdfs.c +++ b/src/bin/gpcheckhdfs/gpcheckhdfs.c @@ -57,6 +57,8 @@ #define KRBLOGIN_ERR 107 #define DIRECTORY_ERR 108 +#define TRASH_DIRECTORY_NAME ".Trash" + char * conncat(const char * dfs_name, const char * dfs_url); void getHostAndPort(const char * dfs_url, char * host, char * port); @@ -271,6 +273,21 @@ int testHdfsConnect(hdfsFS * fsptr, const char * host, int iPort, return 0; } +/* + * 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; +} + int testHdfsExisted(hdfsFS fs, const char * filepath, const char * dfscompleteurl, const char * tde_keyname) { int notExisted = hdfsExists(fs, filepath); @@ -283,10 +300,13 @@ int testHdfsExisted(hdfsFS fs, const char * filepath, const char * dfscompleteur return DFSDIR_ERR; } } else { - int num; + int num = 0; hdfsFileInfo * fi = hdfsListDirectory(fs, filepath, &num); - if (NULL == fi || num != 0) { + if (NULL == fi || num > 1 || + (num == 1 && !isTrashDirectory(fi[0].mName)) /* skip Trash directory */ + ) + { fprintf(stderr, "ERROR: failed to list directory %s or it is not empty\n" "Please Check your filepath before doing HAWQ cluster initialization.\n", dfscompleteurl); return DFSDIR_ERR;
