Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
onurctirtir committed Nov 21, 2023
1 parent 3b556cb commit f7f5bdf
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 74 deletions.
10 changes: 5 additions & 5 deletions src/backend/distributed/commands/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ PreprocessCreateDatabaseStmt(Node *node, const char *queryString,
return NIL;
}

EnsureCoordinator();
EnsurePropagationToCoordinator();

CreatedbStmt *stmt = castNode(CreatedbStmt, node);
EnsureSupportedCreateDatabaseCommand(stmt);
Expand All @@ -327,7 +327,7 @@ PostprocessCreateDatabaseStmt(Node *node, const char *queryString)
return NIL;
}

EnsureCoordinator();
EnsurePropagationToCoordinator();

/*
* Given that CREATE DATABASE doesn't support "IF NOT EXISTS" and we're
Expand All @@ -345,7 +345,7 @@ PostprocessCreateDatabaseStmt(Node *node, const char *queryString)
(void *) createDatabaseCommand,
ENABLE_DDL_PROPAGATION);

return NontransactionalNodeDDLTaskList(NON_COORDINATOR_NODES, commands);
return NontransactionalNodeDDLTaskList(REMOTE_NODES, commands);
}


Expand All @@ -365,7 +365,7 @@ PreprocessDropDatabaseStmt(Node *node, const char *queryString,
return NIL;
}

EnsureCoordinator();
EnsurePropagationToCoordinator();

DropdbStmt *stmt = (DropdbStmt *) node;

Expand All @@ -391,7 +391,7 @@ PreprocessDropDatabaseStmt(Node *node, const char *queryString,
(void *) dropDatabaseCommand,
ENABLE_DDL_PROPAGATION);

return NontransactionalNodeDDLTaskList(NON_COORDINATOR_NODES, commands);
return NontransactionalNodeDDLTaskList(REMOTE_NODES, commands);
}


Expand Down
4 changes: 2 additions & 2 deletions src/backend/distributed/commands/utility_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,9 @@ citus_ProcessUtilityInternal(PlannedStmt *pstmt,
ereport(NOTICE, (errmsg("Citus partially supports CREATE DATABASE for "
"distributed databases"),
errdetail("Citus does not propagate CREATE DATABASE "
"command to workers"),
"command to other nodes"),
errhint("You can manually create a database and its "
"extensions on workers.")));
"extensions on other nodes.")));
}
}
else if (IsA(parsetree, CreateRoleStmt) && !EnableCreateRolePropagation)
Expand Down
4 changes: 4 additions & 0 deletions src/test/regress/citus_tests/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ def extra_tests(self):
repeatable=False,
),
"multi_prepare_plsql": TestDeps("base_schedule"),
"columnar_drop": TestDeps(
"minimal_schedule",
["columnar_create", "columnar_load"],
),
}


Expand Down
4 changes: 2 additions & 2 deletions src/test/regress/expected/alter_role_propagation.out
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ SELECT run_command_on_workers('SHOW enable_hashagg');
-- also test case sensitivity
CREATE DATABASE "REGRESSION";
NOTICE: Citus partially supports CREATE DATABASE for distributed databases
DETAIL: Citus does not propagate CREATE DATABASE command to workers
HINT: You can manually create a database and its extensions on workers.
DETAIL: Citus does not propagate CREATE DATABASE command to other nodes
HINT: You can manually create a database and its extensions on other nodes.
ALTER ROLE CURRENT_USER IN DATABASE "REGRESSION" SET public.myguc TO "Hello from coordinator only";
SELECT d.datname, r.setconfig FROM pg_db_role_setting r LEFT JOIN pg_database d ON r.setdatabase=d.oid WHERE r.setconfig::text LIKE '%Hello from coordinator only%';
datname | setconfig
Expand Down
28 changes: 16 additions & 12 deletions src/test/regress/expected/columnar_drop.out
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,39 @@
-- 'postgres' directory is excluded from comparison to have the same result.
-- store postgres database oid
SELECT oid postgres_oid FROM pg_database WHERE datname = 'postgres' \gset
SELECT count(distinct storage_id) AS columnar_stripes_before_drop FROM columnar.stripe \gset
-- DROP columnar tables
DROP TABLE contestant;
DROP TABLE contestant_compressed;
SET client_min_messages TO WARNING;
DROP TABLE IF EXISTS contestant;
DROP TABLE IF EXISTS contestant_compressed;
RESET client_min_messages;
-- make sure DROP deletes metadata
SELECT :columnar_stripes_before_drop - count(distinct storage_id) FROM columnar.stripe;
?column?
WITH cte AS (SELECT distinct relation as distinct_rel FROM columnar.stripe)
SELECT
(SELECT COUNT(*) > 0 FROM cte WHERE distinct_rel::regclass::text like '%contestant%') AS contestant_rel_exists,
(SELECT COUNT(*) > 0 FROM cte WHERE distinct_rel::regclass::text like '%contestant_compressed%') AS contestant_compressed_rel_exists;
contestant_rel_exists | contestant_compressed_rel_exists
---------------------------------------------------------------------
2
f | f
(1 row)

-- Create a columnar table under a schema and drop it.
CREATE SCHEMA test_schema;
CREATE TABLE test_schema.test_table(data int) USING columnar;
INSERT INTO test_schema.test_table VALUES (1);
SELECT count(*) AS columnar_stripes_before_drop FROM columnar.stripe \gset
DROP SCHEMA test_schema CASCADE;
NOTICE: drop cascades to table test_schema.test_table
SELECT :columnar_stripes_before_drop - count(distinct storage_id) FROM columnar.stripe;
?column?
WITH cte AS (SELECT distinct relation as distinct_rel FROM columnar.stripe)
SELECT COUNT(*) > 0 AS test_schema_exists FROM cte WHERE distinct_rel::regclass::text like '%test_schema%';
test_schema_exists
---------------------------------------------------------------------
1
f
(1 row)

SELECT current_database() datname \gset
CREATE DATABASE db_to_drop;
NOTICE: Citus partially supports CREATE DATABASE for distributed databases
DETAIL: Citus does not propagate CREATE DATABASE command to workers
HINT: You can manually create a database and its extensions on workers.
DETAIL: Citus does not propagate CREATE DATABASE command to other nodes
HINT: You can manually create a database and its extensions on other nodes.
\c db_to_drop
CREATE EXTENSION citus_columnar;
SELECT oid::text databaseoid FROM pg_database WHERE datname = current_database() \gset
Expand Down
102 changes: 90 additions & 12 deletions src/test/regress/expected/create_drop_database_propagation.out
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ CREATE TABLESPACE create_drop_db_tablespace LOCATION :'create_drop_db_tablespace
\c - - - :master_port
CREATE DATABASE local_database;
NOTICE: Citus partially supports CREATE DATABASE for distributed databases
DETAIL: Citus does not propagate CREATE DATABASE command to workers
HINT: You can manually create a database and its extensions on workers.
DETAIL: Citus does not propagate CREATE DATABASE command to other nodes
HINT: You can manually create a database and its extensions on other nodes.
-- check that it's only created for coordinator
SELECT * FROM public.check_database_on_all_nodes('local_database') ORDER BY node_type;
node_type | result
Expand All @@ -88,8 +88,8 @@ SELECT * FROM public.check_database_on_all_nodes('local_database') ORDER BY node
\c - - - :worker_1_port
CREATE DATABASE local_database;
NOTICE: Citus partially supports CREATE DATABASE for distributed databases
DETAIL: Citus does not propagate CREATE DATABASE command to workers
HINT: You can manually create a database and its extensions on workers.
DETAIL: Citus does not propagate CREATE DATABASE command to other nodes
HINT: You can manually create a database and its extensions on other nodes.
-- check that it's only created for coordinator
SELECT * FROM public.check_database_on_all_nodes('local_database') ORDER BY node_type;
node_type | result
Expand Down Expand Up @@ -464,18 +464,14 @@ drop database "mydatabase#1'2";
ERROR: database "mydatabase#1'2" does not exist
\c - - - :worker_1_port
SET citus.enable_create_database_propagation TO ON;
-- show that dropping the database from workers is not allowed when citus.enable_create_database_propagation is on
-- show that dropping the database from workers is allowed when citus.enable_create_database_propagation is on
DROP DATABASE db_needs_escape;
ERROR: operation is not allowed on this node
HINT: Connect to the coordinator and run it again.
-- and the same applies to create database too
create database error_test;
ERROR: operation is not allowed on this node
HINT: Connect to the coordinator and run it again.
drop database error_test;
\c - - - :master_port
SET citus.enable_create_database_propagation TO ON;
DROP DATABASE test_node_activation;
DROP DATABASE db_needs_escape;
DROP USER "role-needs\!escape";
-- drop database with force options test
create database db_force_test;
Expand Down Expand Up @@ -506,8 +502,8 @@ select 1 from citus_remove_node('localhost', :worker_2_port);
SET citus.enable_create_database_propagation TO off;
CREATE DATABASE non_distributed_db;
NOTICE: Citus partially supports CREATE DATABASE for distributed databases
DETAIL: Citus does not propagate CREATE DATABASE command to workers
HINT: You can manually create a database and its extensions on workers.
DETAIL: Citus does not propagate CREATE DATABASE command to other nodes
HINT: You can manually create a database and its extensions on other nodes.
SET citus.enable_create_database_propagation TO on;
create database distributed_db;
select 1 from citus_add_node('localhost', :worker_2_port);
Expand Down Expand Up @@ -944,6 +940,88 @@ SELECT * FROM public.check_database_on_all_nodes('test_db') ORDER BY node_type;
REVOKE CONNECT ON DATABASE test_db FROM propagated_role;
DROP DATABASE test_db;
DROP ROLE propagated_role, non_propagated_role;
-- test create / drop database commands from workers
-- remove one of the workers to test node activation too
SELECT 1 from citus_remove_node('localhost', :worker_2_port);
?column?
---------------------------------------------------------------------
1
(1 row)

\c - - - :worker_1_port
CREATE DATABASE local_worker_db;
NOTICE: Citus partially supports CREATE DATABASE for distributed databases
DETAIL: Citus does not propagate CREATE DATABASE command to other nodes
HINT: You can manually create a database and its extensions on other nodes.
SET citus.enable_create_database_propagation TO ON;
CREATE DATABASE db_created_from_worker
WITH template=template1
OWNER = create_drop_db_test_user
ENCODING = 'UTF8'
CONNECTION LIMIT = 42
TABLESPACE = "ts-needs\!escape"
ALLOW_CONNECTIONS = false;
\c - - - :master_port
SET citus.enable_create_database_propagation TO ON;
SELECT 1 FROM citus_add_node('localhost', :worker_2_port);
?column?
---------------------------------------------------------------------
1
(1 row)

\c - - - :worker_1_port
SET citus.enable_create_database_propagation TO ON;
SELECT * FROM public.check_database_on_all_nodes('local_worker_db') ORDER BY node_type;
node_type | result
---------------------------------------------------------------------
coordinator (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
worker node (local) | {"database_properties": {"datacl": null, "datname": "local_worker_db", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "pg_default", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
worker node (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
(3 rows)

SELECT * FROM public.check_database_on_all_nodes('db_created_from_worker') ORDER BY node_type;
node_type | result
---------------------------------------------------------------------
coordinator (remote) | {"database_properties": {"datacl": null, "datname": "db_created_from_worker", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape", "daticurules": null, "datallowconn": false, "datconnlimit": 42, "daticulocale": null, "datistemplate": false, "database_owner": "create_drop_db_test_user", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false}
worker node (local) | {"database_properties": {"datacl": null, "datname": "db_created_from_worker", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape", "daticurules": null, "datallowconn": false, "datconnlimit": 42, "daticulocale": null, "datistemplate": false, "database_owner": "create_drop_db_test_user", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false}
worker node (remote) | {"database_properties": {"datacl": null, "datname": "db_created_from_worker", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "ts-needs\\!escape", "daticurules": null, "datallowconn": false, "datconnlimit": 42, "daticulocale": null, "datistemplate": false, "database_owner": "create_drop_db_test_user", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false}
(3 rows)

DROP DATABASE db_created_from_worker;
SELECT * FROM public.check_database_on_all_nodes('db_created_from_worker') ORDER BY node_type;
node_type | result
---------------------------------------------------------------------
coordinator (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
worker node (local) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
worker node (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
(3 rows)

-- drop the local database while the GUC is on
DROP DATABASE local_worker_db;
SELECT * FROM public.check_database_on_all_nodes('local_worker_db') ORDER BY node_type;
node_type | result
---------------------------------------------------------------------
coordinator (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
worker node (local) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
worker node (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
(3 rows)

SET citus.enable_create_database_propagation TO OFF;
CREATE DATABASE local_worker_db;
NOTICE: Citus partially supports CREATE DATABASE for distributed databases
DETAIL: Citus does not propagate CREATE DATABASE command to other nodes
HINT: You can manually create a database and its extensions on other nodes.
-- drop the local database while the GUC is off
DROP DATABASE local_worker_db;
SELECT * FROM public.check_database_on_all_nodes('local_worker_db') ORDER BY node_type;
node_type | result
---------------------------------------------------------------------
coordinator (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
worker node (local) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
worker node (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
(3 rows)

SET citus.enable_create_database_propagation TO ON;
--clean up resources created by this test
-- DROP TABLESPACE is not supported, so we need to drop it manually.
SELECT result FROM run_command_on_all_nodes(
Expand Down
16 changes: 8 additions & 8 deletions src/test/regress/expected/drop_database.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ SET citus.shard_replication_factor TO 1;
SET citus.next_shard_id TO 35137400;
CREATE DATABASE citus_created;
NOTICE: Citus partially supports CREATE DATABASE for distributed databases
DETAIL: Citus does not propagate CREATE DATABASE command to workers
HINT: You can manually create a database and its extensions on workers.
DETAIL: Citus does not propagate CREATE DATABASE command to other nodes
HINT: You can manually create a database and its extensions on other nodes.
\c citus_created
CREATE EXTENSION citus;
CREATE DATABASE citus_not_created;
NOTICE: Citus partially supports CREATE DATABASE for distributed databases
DETAIL: Citus does not propagate CREATE DATABASE command to workers
HINT: You can manually create a database and its extensions on workers.
DETAIL: Citus does not propagate CREATE DATABASE command to other nodes
HINT: You can manually create a database and its extensions on other nodes.
\c citus_not_created
DROP DATABASE citus_created;
\c regression
Expand All @@ -26,14 +26,14 @@ SET citus.shard_replication_factor TO 1;
SET citus.next_shard_id TO 35137400;
CREATE DATABASE citus_created;
NOTICE: Citus partially supports CREATE DATABASE for distributed databases
DETAIL: Citus does not propagate CREATE DATABASE command to workers
HINT: You can manually create a database and its extensions on workers.
DETAIL: Citus does not propagate CREATE DATABASE command to other nodes
HINT: You can manually create a database and its extensions on other nodes.
\c citus_created
CREATE EXTENSION citus;
CREATE DATABASE citus_not_created;
NOTICE: Citus partially supports CREATE DATABASE for distributed databases
DETAIL: Citus does not propagate CREATE DATABASE command to workers
HINT: You can manually create a database and its extensions on workers.
DETAIL: Citus does not propagate CREATE DATABASE command to other nodes
HINT: You can manually create a database and its extensions on other nodes.
\c citus_not_created
DROP DATABASE citus_created;
\c regression
Expand Down
4 changes: 2 additions & 2 deletions src/test/regress/expected/grant_on_database_propagation.out
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ create user myuser;
create user myuser_1;
create database test_db;
NOTICE: Citus partially supports CREATE DATABASE for distributed databases
DETAIL: Citus does not propagate CREATE DATABASE command to workers
HINT: You can manually create a database and its extensions on workers.
DETAIL: Citus does not propagate CREATE DATABASE command to other nodes
HINT: You can manually create a database and its extensions on other nodes.
SELECT result FROM run_command_on_workers($$create database test_db$$);
result
---------------------------------------------------------------------
Expand Down
Loading

0 comments on commit f7f5bdf

Please sign in to comment.