From 236ea1d1b9e1c67253b5938dedcf9fac5348138a Mon Sep 17 00:00:00 2001 From: gindibay Date: Wed, 4 Oct 2023 21:20:19 +0300 Subject: [PATCH] Adds tests for create and drop database --- src/backend/distributed/commands/database.c | 5 ++ .../deparser/deparse_database_stmts.c | 11 +++-- .../create_drop_database_propagation.out | 46 +++++++++++++++++++ src/test/regress/multi_1_schedule | 1 + .../sql/create_drop_database_propagation.sql | 45 ++++++++++++++++++ 5 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 src/test/regress/expected/create_drop_database_propagation.out create mode 100644 src/test/regress/sql/create_drop_database_propagation.sql diff --git a/src/backend/distributed/commands/database.c b/src/backend/distributed/commands/database.c index c760aaa70..c7da5d068 100644 --- a/src/backend/distributed/commands/database.c +++ b/src/backend/distributed/commands/database.c @@ -312,6 +312,11 @@ PreprocessAlterDatabaseSetStmt(Node *node, const char *queryString, List * PostprocessCreateDatabaseStmt(Node *node, const char *queryString) { + if (EnableCreateDatabasePropagation) + { + EnsureCoordinator(); + } + if (!EnableCreateDatabasePropagation || !ShouldPropagate()) { return NIL; diff --git a/src/backend/distributed/deparser/deparse_database_stmts.c b/src/backend/distributed/deparser/deparse_database_stmts.c index 75ab1d489..6ffce3b48 100644 --- a/src/backend/distributed/deparser/deparse_database_stmts.c +++ b/src/backend/distributed/deparser/deparse_database_stmts.c @@ -274,6 +274,13 @@ AppendCreatedbStmt(StringInfo buf, CreatedbStmt *stmt) appendStringInfo(buf, " ICU_LOCALE %s", quote_literal_cstr(icuLocale)); } + else if (strcmp(option->defname, "icu_rules") == 0) + { + char *icuLocale = defGetString(option); + + appendStringInfo(buf, " ICU_RULES %s", + quote_literal_cstr(icuLocale)); + } else if (strcmp(option->defname, "locale_provider") == 0) { char *localeProvider = defGetString(option); @@ -323,10 +330,6 @@ AppendCreatedbStmt(StringInfo buf, CreatedbStmt *stmt) quote_literal_cstr(strategy)); } #endif - else if (strcmp(option->defname, "location") == 0) - { - /* deprecated option */ - } else { ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), diff --git a/src/test/regress/expected/create_drop_database_propagation.out b/src/test/regress/expected/create_drop_database_propagation.out new file mode 100644 index 000000000..34251f9c4 --- /dev/null +++ b/src/test/regress/expected/create_drop_database_propagation.out @@ -0,0 +1,46 @@ +set citus.enable_create_database_propagation=on; +create user create_drop_db_test_user; +CREATE DATABASE mydatabase + WITH TEMPLATE = 'template0' + OWNER = create_drop_db_test_user + CONNECTION LIMIT = 10 + ENCODING = 'UTF8' + STRATEGY = 'wal_log' + LOCALE = 'en_US.UTF-8' + LC_COLLATE = 'en_US.UTF-8' + LC_CTYPE = 'en_US.UTF-8' + ICU_LOCALE = 'en_US.UTF-8' + LOCALE_PROVIDER = 'icu' + COLLATION_VERSION = '1.0' + TABLESPACE = test_tablespace + ALLOW_CONNECTIONS = true + IS_TEMPLATE = false + OID = 966345; +SELECT pd.datname , pd.datdba, pd.encoding, pd.datlocprovider, +pd.datistemplate, pd.datallowconn, pd.datconnlimit, +pd.datcollate , pd. datctype , pd.daticulocale, pd.datcollversion, +pd.datacl, rolname AS database_owner, pa.rolname AS database_owner, pt.spcname AS tablespace +FROM pg_database pd +JOIN pg_authid pa ON pd.datdba = pa.oid +join pg_tablespace pt on pd.dattablespace = pt.oid +WHERE datname = 'mydatabase'; + datname | datdba | encoding | datlocprovider | datistemplate | datallowconn | datconnlimit | datcollate | datctype | daticulocale | datcollversion | datacl | database_owner | database_owner | tablespace +--------------------------------------------------------------------- + mydatabase | 17343 | 6 | i | f | t | 10 | en_US.UTF-8 | en_US.UTF-8 | en_US.UTF-8 | 1.0 | | create_drop_db_test_user | create_drop_db_test_user | test_tablespace +(1 row) + +drop database mydatabase; +SELECT pd.datname , pd.datdba, pd.encoding, pd.datlocprovider, +pd.datistemplate, pd.datallowconn, pd.datconnlimit, +pd.datcollate , pd. datctype , pd.daticulocale, pd.datcollversion, +pd.datacl, rolname AS database_owner, pa.rolname AS database_owner, pt.spcname AS tablespace +FROM pg_database pd +JOIN pg_authid pa ON pd.datdba = pa.oid +join pg_tablespace pt on pd.dattablespace = pt.oid +WHERE datname = 'mydatabase'; + datname | datdba | encoding | datlocprovider | datistemplate | datallowconn | datconnlimit | datcollate | datctype | daticulocale | datcollversion | datacl | database_owner | database_owner | tablespace +--------------------------------------------------------------------- +(0 rows) + +drop user create_drop_db_test_user; +set citus.enable_create_database_propagation=off; diff --git a/src/test/regress/multi_1_schedule b/src/test/regress/multi_1_schedule index 4dead5be3..d55da08b8 100644 --- a/src/test/regress/multi_1_schedule +++ b/src/test/regress/multi_1_schedule @@ -52,6 +52,7 @@ test: multi_read_from_secondaries test: grant_on_database_propagation test: alter_database_propagation +test: create_drop_database_propagation # ---------- # multi_citus_tools tests utility functions written for citus tools diff --git a/src/test/regress/sql/create_drop_database_propagation.sql b/src/test/regress/sql/create_drop_database_propagation.sql new file mode 100644 index 000000000..27820b32b --- /dev/null +++ b/src/test/regress/sql/create_drop_database_propagation.sql @@ -0,0 +1,45 @@ +set citus.enable_create_database_propagation=on; +create user create_drop_db_test_user; + + +CREATE DATABASE mydatabase + WITH TEMPLATE = 'template0' + OWNER = create_drop_db_test_user + CONNECTION LIMIT = 10 + ENCODING = 'UTF8' + STRATEGY = 'wal_log' + LOCALE = 'en_US.UTF-8' + LC_COLLATE = 'en_US.UTF-8' + LC_CTYPE = 'en_US.UTF-8' + ICU_LOCALE = 'en_US.UTF-8' + LOCALE_PROVIDER = 'icu' + COLLATION_VERSION = '1.0' + TABLESPACE = test_tablespace + ALLOW_CONNECTIONS = true + IS_TEMPLATE = false + OID = 966345; + +SELECT pd.datname , pd.datdba, pd.encoding, pd.datlocprovider, +pd.datistemplate, pd.datallowconn, pd.datconnlimit, +pd.datcollate , pd. datctype , pd.daticulocale, pd.datcollversion, +pd.datacl, rolname AS database_owner, pa.rolname AS database_owner, pt.spcname AS tablespace +FROM pg_database pd +JOIN pg_authid pa ON pd.datdba = pa.oid +join pg_tablespace pt on pd.dattablespace = pt.oid +WHERE datname = 'mydatabase'; + +drop database mydatabase; + +SELECT pd.datname , pd.datdba, pd.encoding, pd.datlocprovider, +pd.datistemplate, pd.datallowconn, pd.datconnlimit, +pd.datcollate , pd. datctype , pd.daticulocale, pd.datcollversion, +pd.datacl, rolname AS database_owner, pa.rolname AS database_owner, pt.spcname AS tablespace +FROM pg_database pd +JOIN pg_authid pa ON pd.datdba = pa.oid +join pg_tablespace pt on pd.dattablespace = pt.oid +WHERE datname = 'mydatabase'; + +drop user create_drop_db_test_user; +set citus.enable_create_database_propagation=off; + +