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 3777618D5B for ; Wed, 3 Feb 2016 02:56:41 +0000 (UTC) Received: (qmail 87767 invoked by uid 500); 3 Feb 2016 02:56:34 -0000 Delivered-To: apmail-hawq-commits-archive@hawq.apache.org Received: (qmail 87731 invoked by uid 500); 3 Feb 2016 02:56:34 -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 87722 invoked by uid 99); 3 Feb 2016 02:56:34 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Feb 2016 02:56:34 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 6DFFDC0D56 for ; Wed, 3 Feb 2016 02:56:34 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.256 X-Spam-Level: * X-Spam-Status: No, score=1.256 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.545, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 0u7kCqLihXGU for ; Wed, 3 Feb 2016 02:56:22 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with SMTP id B21BD20522 for ; Wed, 3 Feb 2016 02:56:22 +0000 (UTC) Received: (qmail 87621 invoked by uid 99); 3 Feb 2016 02:56:22 -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; Wed, 03 Feb 2016 02:56:22 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 80563DFC8F; Wed, 3 Feb 2016 02:56:22 +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 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: incubator-hawq git commit: HAWQ-369. Hcatalog as reserved name. [Forced Update!] Date: Wed, 3 Feb 2016 02:56:22 +0000 (UTC) Repository: incubator-hawq Updated Branches: refs/heads/HAWQ-369 d00a2ab5a -> 9db45b948 (forced update) HAWQ-369. Hcatalog as reserved name. Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/9db45b94 Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/9db45b94 Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/9db45b94 Branch: refs/heads/HAWQ-369 Commit: 9db45b9484d90497227e8e5e87cc99941cfc2da9 Parents: 226a55c Author: Oleksandr Diachenko Authored: Thu Jan 28 19:31:02 2016 -0800 Committer: Oleksandr Diachenko Committed: Tue Feb 2 18:56:14 2016 -0800 ---------------------------------------------------------------------- doc/src/sgml/ref/alter_database.sgml | 10 ++++++ doc/src/sgml/ref/create_database.sgml | 4 +++ src/backend/commands/dbcommands.c | 29 ++++++++++++++++-- src/backend/utils/init/postinit.c | 16 ++++++++++ src/test/regress/input/hcatalog_lookup.source | 34 +++++++++++++++++++++ src/test/regress/output/hcatalog_lookup.source | 28 +++++++++++++++++ 6 files changed, 118 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/9db45b94/doc/src/sgml/ref/alter_database.sgml ---------------------------------------------------------------------- diff --git a/doc/src/sgml/ref/alter_database.sgml b/doc/src/sgml/ref/alter_database.sgml index 8ddff97..b8fbbda 100755 --- a/doc/src/sgml/ref/alter_database.sgml +++ b/doc/src/sgml/ref/alter_database.sgml @@ -154,6 +154,16 @@ ALTER DATABASE name OWNER TO + + + Currently RENAME TO is supported only when called by pgdump utility. + + + User can not use "hcatalog" as a name for database, because it's reserved for HCatalog integration feature. + + + User can not rename "hcatalog" database, because it's reserved for HCatalog integration feature. + http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/9db45b94/doc/src/sgml/ref/create_database.sgml ---------------------------------------------------------------------- diff --git a/doc/src/sgml/ref/create_database.sgml b/doc/src/sgml/ref/create_database.sgml index 3183e2a..e252fe3 100755 --- a/doc/src/sgml/ref/create_database.sgml +++ b/doc/src/sgml/ref/create_database.sgml @@ -184,6 +184,10 @@ CREATE DATABASE name connection slot remains for the database, it is possible that both will fail. Also, the limit is not enforced against superusers. + + + User can not create database named "hcatalog", because it's reserved for HCatalog integration feature. + http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/9db45b94/src/backend/commands/dbcommands.c ---------------------------------------------------------------------- diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index f80e01a..1f61f5e 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -848,11 +848,18 @@ createdb(CreatedbStmt *stmt) * Check for db name conflict. This is just to give a more friendly error * message than "unique index violation". There's a race condition but * we're willing to accept the less friendly message in that case. + * Also check that user is not trying to use "hcatalog" as a database name, + * because it's already reserved for HCatalog integration feature. */ if (OidIsValid(get_database_oid(dbname))) - ereport(ERROR, - (errcode(ERRCODE_DUPLICATE_DATABASE), - errmsg("database \"%s\" already exists", dbname))); + if (strcmp(dbname, HcatalogDbName) == 0) + ereport(ERROR, + (errcode(ERRCODE_RESERVED_NAME), + errmsg("\"%s\" is a reserved name for HCatalog integration feature", HcatalogDbName))); + else + ereport(ERROR, + (errcode(ERRCODE_DUPLICATE_DATABASE), + errmsg("database \"%s\" already exists", dbname))); /* * Select an OID for the new database, checking that it doesn't have @@ -1533,6 +1540,15 @@ RenameDatabase(const char *oldname, const char *newname) cqContext cqc; cqContext *pcqCtx; + + /* + * Make sure "hcatalog" is not used as new name, because it's reserved for + * HCatalog integration feature + */ + if (strcmp(newname, HcatalogDbName) == 0) + ereport(ERROR, + (errcode(ERRCODE_RESERVED_NAME), + errmsg("\"%s\" is a reserved name for HCatalog integration feature", HcatalogDbName))); /* * Look up the target database's OID, and get exclusive lock on it. We * need this for the same reasons as DROP DATABASE. @@ -1555,6 +1571,13 @@ RenameDatabase(const char *oldname, const char *newname) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("current database may not be renamed"))); + /* + * "hcatalog" database cannot be renamed + */ + if (db_id == HcatalogDbOid) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("permission denied to ALTER DATABASE \"%s\" is reserved for system use", HcatalogDbName))); /* * Make sure the database does not have active sessions. This is the same http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/9db45b94/src/backend/utils/init/postinit.c ---------------------------------------------------------------------- diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index e4d0752..904aa67 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -368,6 +368,22 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, char dbname[NAMEDATALEN]; /* + * User is not supposed to connect to hcatalog database, + * because it's reserved for HCatalog integration feature + */ + if (!bootstrap) + { + if (strcmp(in_dbname, HcatalogDbName) == 0) + { + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_DATABASE), + errmsg("\"%s\" database is only for system use", + HcatalogDbName))); + } + } + + + /* * Set up the global variables holding database id and path. But note we * won't actually try to touch the database just yet. * http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/9db45b94/src/test/regress/input/hcatalog_lookup.source ---------------------------------------------------------------------- diff --git a/src/test/regress/input/hcatalog_lookup.source b/src/test/regress/input/hcatalog_lookup.source index a011abf..11be8b9 100644 --- a/src/test/regress/input/hcatalog_lookup.source +++ b/src/test/regress/input/hcatalog_lookup.source @@ -138,16 +138,50 @@ alter table test_schema.p exchange partition p1 with table hcatalog.test_schema. select pg_catalog.pg_database_size('hcatalog'); select pg_catalog.pg_database_size(6120); +--positive test: should be able to create table named "hcatalog" +CREATE TABLE hcatalog(a int); + +--negative test: cannot create database named "hcatalog" +CREATE DATABASE hcatalog; + +--allow renaming schemas and databases +SET gp_called_by_pgdump = true; + +--negative test: cannot rename existing database to "hcatalog" +ALTER DATABASE regression RENAME TO hcatalog; + +--positive test: can rename existing schema to "hcatalog" +CREATE SCHEMA test_schema3; +ALTER SCHEMA test_schema3 RENAME to hcatalog; + +--positive test: can rename schema "hcatalog" +ALTER SCHEMA hcatalog RENAME to hcatalog1; + +--positive test: should be able to create schema named "hcatalog" +CREATE SCHEMA hcatalog; + +--negative test: cannot create a database using "hcatalog" as a template +CREATE DATABASE hcatalog2 TEMPLATE hcatalog; + +--restrict renaming schemas and databases +SET gp_called_by_pgdump = false; + -- cleanup DROP schema test_schema cascade; SELECT convert_to_internal_schema('test_schema'); DROP schema test_schema cascade; DROP schema test_schema2 cascade; +DROP schema hcatalog cascade; +DROP schema hcatalog1 cascade; select nspname,nspdboid from pg_namespace where nspname='test_schema'; DROP FUNCTION convert_to_hcatalog_schema(text); DROP FUNCTION convert_to_internal_schema(text); DROP FUNCTION trigger_func(); DROP USER newuser; +DROP TABLE hcatalog; -- disable GUC SET hcatalog_enable = false; + +--negative test: cannot connect to "hcatalog" database +\connect hcatalog; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/9db45b94/src/test/regress/output/hcatalog_lookup.source ---------------------------------------------------------------------- diff --git a/src/test/regress/output/hcatalog_lookup.source b/src/test/regress/output/hcatalog_lookup.source index 8708e59..a5a2231 100644 --- a/src/test/regress/output/hcatalog_lookup.source +++ b/src/test/regress/output/hcatalog_lookup.source @@ -266,6 +266,28 @@ select pg_catalog.pg_database_size('hcatalog'); ERROR: database hcatalog (OID 6120) is reserved (SOMEFILE:SOMEFUNC) select pg_catalog.pg_database_size(6120); ERROR: database hcatalog (OID 6120) is reserved (SOMEFILE:SOMEFUNC) +--positive test: should be able to create table named "hcatalog" +CREATE TABLE hcatalog(a int); +--negative test: cannot create database named "hcatalog" +CREATE DATABASE hcatalog; +ERROR: "hcatalog" is a reserved name for HCatalog integration feature +--allow renaming schemas and databases +SET gp_called_by_pgdump = true; +--negative test: cannot rename existing database to "hcatalog" +ALTER DATABASE regression RENAME TO hcatalog; +ERROR: "hcatalog" is a reserved name for HCatalog integration feature +--positive test: can rename existing schema to "hcatalog" +CREATE SCHEMA test_schema3; +ALTER SCHEMA test_schema3 RENAME to hcatalog; +--positive test: can rename schema "hcatalog" +ALTER SCHEMA hcatalog RENAME to hcatalog1; +--positive test: should be able to create schema named "hcatalog" +CREATE SCHEMA hcatalog; +--negative test: cannot create a database using "hcatalog" as a template +CREATE DATABASE hcatalog2 TEMPLATE hcatalog; +ERROR: copy non template database is not supported +--restrict renaming schemas and databases +SET gp_called_by_pgdump = false; -- cleanup DROP schema test_schema cascade; NOTICE: drop cascades to append only table test_schema.r @@ -286,6 +308,8 @@ NOTICE: drop cascades to append only table test_schema.tt NOTICE: drop cascades to append only table test_schema.t NOTICE: drop cascades to append only table test_schema.r DROP schema test_schema2 cascade; +DROP schema hcatalog cascade; +DROP schema hcatalog1 cascade; select nspname,nspdboid from pg_namespace where nspname='test_schema'; nspname | nspdboid ---------+---------- @@ -295,5 +319,9 @@ DROP FUNCTION convert_to_hcatalog_schema(text); DROP FUNCTION convert_to_internal_schema(text); DROP FUNCTION trigger_func(); DROP USER newuser; +DROP TABLE hcatalog; -- disable GUC SET hcatalog_enable = false; +--negative test: cannot connect to "hcatalog" database +\connect hcatalog; +\connect: FATAL: "hcatalog" database is only for system use