Repository: incubator-hawq
Updated Branches:
  refs/heads/master 682749953 -> 37a5043aa


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/master
Commit: 9db45b9484d90497227e8e5e87cc99941cfc2da9
Parents: 226a55c
Author: Oleksandr Diachenko <odiache...@pivotal.io>
Authored: Thu Jan 28 19:31:02 2016 -0800
Committer: Oleksandr Diachenko <odiache...@pivotal.io>
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 <replaceable 
class="PARAMETER">name</replaceable> OWNER TO <repla
    User-specific settings override database-specific
    ones if there is a conflict.
   </para>
+
+  <para>
+   Currently RENAME TO is supported only when called by pgdump utility.
+  </para>
+  <para>
+   User can not use "hcatalog" as a name for database, because it's reserved 
for HCatalog integration feature.
+  </para>
+  <para>
+   User can not rename "hcatalog" database, because it's reserved for HCatalog 
integration feature.
+  </para>
  </refsect1>
 
  <refsect1>

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 <replaceable 
class="PARAMETER">name</replaceable>
    connection <quote>slot</> remains for the database, it is possible that
    both will fail.  Also, the limit is not enforced against superusers.
   </para>
+
+  <para>
+   User can not create database named "hcatalog", because it's reserved for 
HCatalog integration feature.
+  </para>
  </refsect1>
 
  <refsect1>

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

Reply via email to