HAWQ-588. Improve performance for truncate with small table
Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/36fa77df Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/36fa77df Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/36fa77df Branch: refs/heads/HAWQ-546 Commit: 36fa77df42cc97b141f7ab01132bbec30516a780 Parents: 71aa704 Author: Ruilong Huo <r...@pivotal.io> Authored: Thu Mar 24 01:43:19 2016 -0700 Committer: Oleksandr Diachenko <odiache...@pivotal.io> Committed: Wed Mar 30 17:23:31 2016 -0700 ---------------------------------------------------------------------- src/backend/catalog/catalog.c | 29 +++-------------------------- src/backend/storage/file/fd.c | 29 +++++++++++++++++++++++++++++ src/include/storage/fd.h | 2 ++ 3 files changed, 34 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/36fa77df/src/backend/catalog/catalog.c ---------------------------------------------------------------------- diff --git a/src/backend/catalog/catalog.c b/src/backend/catalog/catalog.c index dd10dc2..45aa9bb 100755 --- a/src/backend/catalog/catalog.c +++ b/src/backend/catalog/catalog.c @@ -1052,8 +1052,7 @@ GetNewRelFileNode(Oid reltablespace, bool relisshared, Relation pg_class, bool i { RelFileNode rnode; char *rpath; - int fd; - bool collides; + bool exist = false; /* This should match RelationInitPhysicalAddr */ if (isAo && reltablespace == InvalidOid) @@ -1077,32 +1076,10 @@ GetNewRelFileNode(Oid reltablespace, bool relisshared, Relation pg_class, bool i /* Check for existing file of same name */ rpath = relpath(rnode); - fd = PathNameOpenFile(rpath, O_RDONLY | PG_BINARY, 0); - - if (fd >= 0) - { - /* definite collision */ - gp_retry_close(fd); - collides = true; - } - else - { - /* - * Here we have a little bit of a dilemma: if errno is something - * other than ENOENT, should we declare a collision and loop? In - * particular one might think this advisable for, say, EPERM. - * However there really shouldn't be any unreadable files in a - * tablespace directory, and if the EPERM is actually complaining - * that we can't read the directory itself, we'd be in an infinite - * loop. In practice it seems best to go ahead regardless of the - * errno. If there is a colliding file we will get an smgr - * failure when we attempt to create the new relation file. - */ - collides = false; - } + exist = PathExist(rpath); pfree(rpath); - } while (collides); + } while (exist); if (!gp_upgrade_mode && Gp_role == GP_ROLE_EXECUTE) Insist(!PointerIsValid(pg_class)); http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/36fa77df/src/backend/storage/file/fd.c ---------------------------------------------------------------------- diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index e550307..e71282a 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -975,6 +975,35 @@ FileInvalidate(File file) } #endif +bool +PathExist(char *fileName) +{ + Assert(fileName); + + if (IsLocalPath(fileName)) + { + return LocalPathExist(fileName); + } + else + { + return HdfsPathExist(fileName); + } +} + +bool +LocalPathExist(char *fileName) +{ + Assert(fileName); + + if( access( fileName, F_OK ) != -1 ) + { + return true; + } + else + { + return false; + } +} /* * open a file in an arbitrary directory http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/36fa77df/src/include/storage/fd.h ---------------------------------------------------------------------- diff --git a/src/include/storage/fd.h b/src/include/storage/fd.h index d611894..3e0782d 100644 --- a/src/include/storage/fd.h +++ b/src/include/storage/fd.h @@ -89,6 +89,7 @@ extern int64 LocalFileSeek(File file, int64 offset, int whence); extern int LocalFileSync(File file); extern int LocalRemovePath(FileName fileName, int recursive); extern int LocalFileTruncate(File file, int64 offset); +extern bool LocalPathExist(char *path); /* access hdfs file system */ extern int HdfsParsePath(const char * path, char **protocol, char **host, int *port, short *replica); @@ -140,6 +141,7 @@ extern int64 FileNonVirtualTell(File file); extern int FileTruncate(File file, int64 offset); extern int PathFileTruncate(FileName fileName); extern int64 FileDiskSize(File file); +extern bool PathExist(char *path); /* Operations that allow use of regular stdio --- USE WITH CAUTION */ extern FILE *AllocateFile(const char *name, const char *mode);