Return-Path: X-Original-To: apmail-hawq-commits-archive@minotaur.apache.org Delivered-To: apmail-hawq-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 93C4519F98 for ; Thu, 31 Mar 2016 00:23:59 +0000 (UTC) Received: (qmail 13464 invoked by uid 500); 31 Mar 2016 00:23:59 -0000 Delivered-To: apmail-hawq-commits-archive@hawq.apache.org Received: (qmail 13425 invoked by uid 500); 31 Mar 2016 00:23:59 -0000 Mailing-List: contact commits-help@hawq.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hawq.incubator.apache.org Delivered-To: mailing list commits@hawq.incubator.apache.org Received: (qmail 13363 invoked by uid 99); 31 Mar 2016 00:23:59 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 31 Mar 2016 00:23:59 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id BCF5A1A022B for ; Thu, 31 Mar 2016 00:23:58 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.221 X-Spam-Level: X-Spam-Status: No, score=-3.221 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id QyQ3d9IUlt94 for ; Thu, 31 Mar 2016 00:23:56 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id CE24C5FAE0 for ; Thu, 31 Mar 2016 00:23:55 +0000 (UTC) Received: (qmail 12718 invoked by uid 99); 31 Mar 2016 00:23:55 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 31 Mar 2016 00:23:55 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EE16BE97AC; Thu, 31 Mar 2016 00:23:54 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: odiachenko@apache.org To: commits@hawq.incubator.apache.org Date: Thu, 31 Mar 2016 00:24:17 -0000 Message-Id: <2baf6bc083e44edab432b3e0f30bbf21@git.apache.org> In-Reply-To: <2d1376a31d3a4184952642c3e58e7662@git.apache.org> References: <2d1376a31d3a4184952642c3e58e7662@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [24/38] incubator-hawq git commit: HAWQ-588. Improve performance for truncate with small table 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 Authored: Thu Mar 24 01:43:19 2016 -0700 Committer: Oleksandr Diachenko 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);