Skip to content
Permalink
Browse files
HAWQ-1520. Create filespace should also skip hdfs trash directory
  • Loading branch information
interma authored and radarwave committed Sep 4, 2017
1 parent e20e16b commit c8501c6523b3a57d79fdd0480382bf040e6abb4c
Showing 3 changed files with 27 additions and 5 deletions.
@@ -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);
@@ -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;
}
@@ -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);

0 comments on commit c8501c6

Please sign in to comment.