Fixes role propagation issue

pull/7384/head
gindibay 2023-11-26 18:50:46 +03:00
parent e39c15f50c
commit aed2035e22
3 changed files with 347 additions and 41 deletions

View File

@ -137,8 +137,16 @@ PostprocessReassignOwnedStmt(Node *node, const char *queryString)
ObjectAddress *newRoleAddress = GetNewRoleAddress(stmt);
int saveNestLevel = NewGUCNestLevel();
set_config_option("citus.enable_create_role_propagation", "on",
(superuser() ? PGC_SUSET : PGC_USERSET), PGC_S_SESSION,
GUC_ACTION_LOCAL, true, 0, false);
EnsureObjectAndDependenciesExistOnAllNodes(newRoleAddress);
/* rollback GUCs to the state before this session */
AtEOXact_GUC(true, saveNestLevel);
List *commands = list_make3(DISABLE_DDL_PROPAGATION,
sql,
ENABLE_DDL_PROPAGATION);

View File

@ -1,10 +1,18 @@
CREATE ROLE role1;
create ROLE role2;
CREATE ROLE role3;
GRANT CREATE ON SCHEMA public TO role1,role2;
SET ROLE role1;
CREATE ROLE distributed_source_role1;
create ROLE distributed_source_role2;
CREATE ROLE distributed_target_role1;
set citus.enable_create_role_propagation to off;
create ROLE local_target_role1;
NOTICE: not propagating CREATE ROLE/USER commands to other nodes
HINT: Connect to other nodes directly to manually create all necessary users and roles.
create role local_source_role1;
NOTICE: not propagating CREATE ROLE/USER commands to other nodes
HINT: Connect to other nodes directly to manually create all necessary users and roles.
reset citus.enable_create_role_propagation;
GRANT CREATE ON SCHEMA public TO distributed_source_role1,distributed_source_role2;
SET ROLE distributed_source_role1;
CREATE TABLE public.test_table (col1 int);
set role role2;
set role distributed_source_role2;
CREATE TABLE public.test_table2 (col2 int);
RESET ROLE;
select create_distributed_table('test_table', 'col1');
@ -33,21 +41,26 @@ WHERE
) q2
$$
) ORDER BY result;
result
result
---------------------------------------------------------------------
[{"tablename": "test_table", "schemaname": "public", "tableowner": "role1"}, {"tablename": "test_table2", "schemaname": "public", "tableowner": "role2"}]
[{"tablename": "test_table", "schemaname": "public", "tableowner": "role1"}, {"tablename": "test_table2", "schemaname": "public", "tableowner": "role2"}]
[{"tablename": "test_table", "schemaname": "public", "tableowner": "role1"}, {"tablename": "test_table2", "schemaname": "public", "tableowner": "role2"}]
[{"tablename": "test_table", "schemaname": "public", "tableowner": "distributed_source_role1"}, {"tablename": "test_table2", "schemaname": "public", "tableowner": "distributed_source_role2"}]
[{"tablename": "test_table", "schemaname": "public", "tableowner": "distributed_source_role1"}, {"tablename": "test_table2", "schemaname": "public", "tableowner": "distributed_source_role2"}]
[{"tablename": "test_table", "schemaname": "public", "tableowner": "distributed_source_role1"}, {"tablename": "test_table2", "schemaname": "public", "tableowner": "distributed_source_role2"}]
(3 rows)
--tests for reassing owned by with multiple distributed roles and a local role to a distributed role
--local role should be ignored
set citus.log_remote_commands to on;
set citus.grep_remote_commands = '%REASSIGN OWNED BY%';
REASSIGN OWNED BY role1,role2 TO role3;
NOTICE: issuing REASSIGN OWNED BY role1, role2 TO role3
REASSIGN OWNED BY distributed_source_role1,distributed_source_role2,local_source_role1 TO distributed_target_role1;
NOTICE: issuing REASSIGN OWNED BY distributed_source_role1, distributed_source_role2 TO distributed_target_role1
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
NOTICE: issuing REASSIGN OWNED BY role1, role2 TO role3
NOTICE: issuing REASSIGN OWNED BY distributed_source_role1, distributed_source_role2 TO distributed_target_role1
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
SET citus.log_remote_commands = false;
reset citus.grep_remote_commands;
reset citus.log_remote_commands;
--check if the owner changed to distributed_target_role1
RESET citus.log_remote_commands;
SELECT result from run_command_on_all_nodes(
$$
SELECT jsonb_agg(to_jsonb(q2.*)) FROM (
@ -62,16 +75,43 @@ WHERE
) q2
$$
) ORDER BY result;
result
result
---------------------------------------------------------------------
[{"tablename": "test_table", "schemaname": "public", "tableowner": "role3"}, {"tablename": "test_table2", "schemaname": "public", "tableowner": "role3"}]
[{"tablename": "test_table", "schemaname": "public", "tableowner": "role3"}, {"tablename": "test_table2", "schemaname": "public", "tableowner": "role3"}]
[{"tablename": "test_table", "schemaname": "public", "tableowner": "role3"}, {"tablename": "test_table2", "schemaname": "public", "tableowner": "role3"}]
[{"tablename": "test_table", "schemaname": "public", "tableowner": "distributed_target_role1"}, {"tablename": "test_table2", "schemaname": "public", "tableowner": "distributed_target_role1"}]
[{"tablename": "test_table", "schemaname": "public", "tableowner": "distributed_target_role1"}, {"tablename": "test_table2", "schemaname": "public", "tableowner": "distributed_target_role1"}]
[{"tablename": "test_table", "schemaname": "public", "tableowner": "distributed_target_role1"}, {"tablename": "test_table2", "schemaname": "public", "tableowner": "distributed_target_role1"}]
(3 rows)
--clear resources
SET citus.log_remote_commands = true;
DROP OWNED BY role1, role2,role3;
--tests for reassing owned by with multiple distributed roles and a local role to a local role
--local role should be ignored
SET ROLE distributed_source_role1;
CREATE TABLE public.test_table3 (col1 int);
set role distributed_source_role2;
CREATE TABLE public.test_table4 (col2 int);
RESET ROLE;
select create_distributed_table('test_table3', 'col1');
create_distributed_table
---------------------------------------------------------------------
(1 row)
select create_distributed_table('test_table4', 'col2');
create_distributed_table
---------------------------------------------------------------------
(1 row)
set citus.log_remote_commands to on;
set citus.grep_remote_commands = '%REASSIGN OWNED BY%';
set citus.enable_create_role_propagation to off;
REASSIGN OWNED BY distributed_source_role1,distributed_source_role2,local_source_role1 TO local_target_role1;
NOTICE: issuing REASSIGN OWNED BY distributed_source_role1, distributed_source_role2 TO local_target_role1
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
NOTICE: issuing REASSIGN OWNED BY distributed_source_role1, distributed_source_role2 TO local_target_role1
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
reset citus.grep_remote_commands;
reset citus.log_remote_commands;
--check if the owner changed to local_target_role1
SET citus.log_remote_commands = false;
SELECT result from run_command_on_all_nodes(
$$
@ -83,7 +123,228 @@ SELECT result from run_command_on_all_nodes(
FROM
pg_tables
WHERE
tablename in ('test_table', 'test_table2')
tablename in ('test_table3', 'test_table4')
) q2
$$
) ORDER BY result;
result
---------------------------------------------------------------------
[{"tablename": "test_table3", "schemaname": "public", "tableowner": "local_target_role1"}, {"tablename": "test_table4", "schemaname": "public", "tableowner": "local_target_role1"}]
[{"tablename": "test_table4", "schemaname": "public", "tableowner": "local_target_role1"}, {"tablename": "test_table3", "schemaname": "public", "tableowner": "local_target_role1"}]
[{"tablename": "test_table4", "schemaname": "public", "tableowner": "local_target_role1"}, {"tablename": "test_table3", "schemaname": "public", "tableowner": "local_target_role1"}]
(3 rows)
--clear resources
SET citus.log_remote_commands = true;
DROP OWNED BY distributed_source_role1, distributed_source_role2,distributed_target_role1,local_target_role1;
NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx');
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT master_remove_distributed_table_metadata_from_workers(v_obj.objid, v_obj.schema_name, v_obj.object_name)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT assign_distributed_transaction_id(xx, xx, 'xxxxxxx');
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT master_remove_distributed_table_metadata_from_workers(v_obj.objid, v_obj.schema_name, v_obj.object_name)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing SELECT worker_drop_distributed_table('public.test_table')
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT master_remove_distributed_table_metadata_from_workers(v_obj.objid, v_obj.schema_name, v_obj.object_name)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing SELECT worker_drop_distributed_table('public.test_table')
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT master_remove_distributed_table_metadata_from_workers(v_obj.objid, v_obj.schema_name, v_obj.object_name)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing SELECT worker_drop_distributed_table('public.test_table2')
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT master_remove_distributed_table_metadata_from_workers(v_obj.objid, v_obj.schema_name, v_obj.object_name)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing SELECT worker_drop_distributed_table('public.test_table2')
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT master_remove_distributed_table_metadata_from_workers(v_obj.objid, v_obj.schema_name, v_obj.object_name)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table2_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table2_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table2_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table2_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table2_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table2_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table2_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table2_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing SELECT worker_drop_distributed_table('public.test_table3')
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT master_remove_distributed_table_metadata_from_workers(v_obj.objid, v_obj.schema_name, v_obj.object_name)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing SELECT worker_drop_distributed_table('public.test_table3')
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT master_remove_distributed_table_metadata_from_workers(v_obj.objid, v_obj.schema_name, v_obj.object_name)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table3_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table3_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table3_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table3_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table3_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table3_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table3_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table3_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing SELECT worker_drop_distributed_table('public.test_table4')
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT master_remove_distributed_table_metadata_from_workers(v_obj.objid, v_obj.schema_name, v_obj.object_name)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing SELECT worker_drop_distributed_table('public.test_table4')
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT master_remove_distributed_table_metadata_from_workers(v_obj.objid, v_obj.schema_name, v_obj.object_name)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table4_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table4_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table4_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table4_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table4_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table4_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table4_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing DROP TABLE IF EXISTS public.test_table4_xxxxx CASCADE
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT citus_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name, drop_shards_metadata_only := false)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing SELECT pg_catalog.citus_internal_delete_colocation_metadata(1390004)
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT master_remove_partition_metadata(v_obj.objid, v_obj.schema_name, v_obj.object_name)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing SELECT pg_catalog.citus_internal_delete_colocation_metadata(1390004)
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
CONTEXT: SQL statement "SELECT master_remove_partition_metadata(v_obj.objid, v_obj.schema_name, v_obj.object_name)"
PL/pgSQL function citus_drop_trigger() line XX at PERFORM
NOTICE: issuing SET citus.enable_ddl_propagation TO 'off'
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
NOTICE: issuing SET citus.enable_ddl_propagation TO 'off'
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
NOTICE: issuing DROP OWNED BY distributed_source_role1, distributed_source_role2, distributed_target_role1, local_target_role1 RESTRICT
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
NOTICE: issuing DROP OWNED BY distributed_source_role1, distributed_source_role2, distributed_target_role1, local_target_role1 RESTRICT
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
NOTICE: issuing SET citus.enable_ddl_propagation TO 'on'
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
NOTICE: issuing SET citus.enable_ddl_propagation TO 'on'
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
NOTICE: issuing PREPARE TRANSACTION 'citus_xx_xx_xx_xx'
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
NOTICE: issuing PREPARE TRANSACTION 'citus_xx_xx_xx_xx'
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
NOTICE: issuing COMMIT PREPARED 'citus_xx_xx_xx_xx'
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
NOTICE: issuing COMMIT PREPARED 'citus_xx_xx_xx_xx'
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
reset citus.log_remote_commands;
SELECT result from run_command_on_all_nodes(
$$
SELECT jsonb_agg(to_jsonb(q2.*)) FROM (
SELECT
schemaname,
tablename,
tableowner
FROM
pg_tables
WHERE
tablename in ('test_table', 'test_table2', 'test_table3', 'test_table4')
) q2
$$
) ORDER BY result;
@ -96,8 +357,4 @@ WHERE
SET citus.log_remote_commands = true;
set citus.grep_remote_commands = '%DROP ROLE%';
drop role role1, role2,role3 ;
NOTICE: issuing DROP ROLE role1, role2, role3
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
NOTICE: issuing DROP ROLE role1, role2, role3
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
drop role distributed_source_role1, distributed_source_role2,distributed_target_role1,local_target_role1,local_source_role1;

View File

@ -1,16 +1,19 @@
CREATE ROLE role1;
CREATE ROLE distributed_source_role1;
create ROLE distributed_source_role2;
create ROLE role2;
CREATE ROLE distributed_target_role1;
set citus.create_role
CREATE ROLE role3;
set citus.enable_create_role_propagation to off;
create ROLE local_target_role1;
create role local_source_role1;
reset citus.enable_create_role_propagation;
GRANT CREATE ON SCHEMA public TO role1,role2;
GRANT CREATE ON SCHEMA public TO distributed_source_role1,distributed_source_role2;
SET ROLE role1;
SET ROLE distributed_source_role1;
CREATE TABLE public.test_table (col1 int);
set role role2;
set role distributed_source_role2;
CREATE TABLE public.test_table2 (col2 int);
RESET ROLE;
select create_distributed_table('test_table', 'col1');
@ -32,12 +35,17 @@ WHERE
$$
) ORDER BY result;
--tests for reassing owned by with multiple distributed roles and a local role to a distributed role
--local role should be ignored
set citus.log_remote_commands to on;
set citus.grep_remote_commands = '%REASSIGN OWNED BY%';
REASSIGN OWNED BY role1,role2 TO role3;
REASSIGN OWNED BY distributed_source_role1,distributed_source_role2,local_source_role1 TO distributed_target_role1;
reset citus.grep_remote_commands;
reset citus.log_remote_commands;
--check if the owner changed to distributed_target_role1
SET citus.log_remote_commands = false;
RESET citus.log_remote_commands;
SELECT result from run_command_on_all_nodes(
$$
SELECT jsonb_agg(to_jsonb(q2.*)) FROM (
@ -53,12 +61,46 @@ WHERE
$$
) ORDER BY result;
--tests for reassing owned by with multiple distributed roles and a local role to a local role
--local role should be ignored
SET ROLE distributed_source_role1;
CREATE TABLE public.test_table3 (col1 int);
set role distributed_source_role2;
CREATE TABLE public.test_table4 (col2 int);
RESET ROLE;
select create_distributed_table('test_table3', 'col1');
select create_distributed_table('test_table4', 'col2');
set citus.log_remote_commands to on;
set citus.grep_remote_commands = '%REASSIGN OWNED BY%';
set citus.enable_create_role_propagation to off;
REASSIGN OWNED BY distributed_source_role1,distributed_source_role2,local_source_role1 TO local_target_role1;
reset citus.grep_remote_commands;
reset citus.log_remote_commands;
--check if the owner changed to local_target_role1
SET citus.log_remote_commands = false;
SELECT result from run_command_on_all_nodes(
$$
SELECT jsonb_agg(to_jsonb(q2.*)) FROM (
SELECT
schemaname,
tablename,
tableowner
FROM
pg_tables
WHERE
tablename in ('test_table3', 'test_table4')
) q2
$$
) ORDER BY result;
--clear resources
SET citus.log_remote_commands = true;
DROP OWNED BY role1, role2,role3;
DROP OWNED BY distributed_source_role1, distributed_source_role2,distributed_target_role1,local_target_role1;
reset citus.log_remote_commands;
SET citus.log_remote_commands = false;
SELECT result from run_command_on_all_nodes(
$$
SELECT jsonb_agg(to_jsonb(q2.*)) FROM (
@ -69,13 +111,12 @@ SELECT result from run_command_on_all_nodes(
FROM
pg_tables
WHERE
tablename in ('test_table', 'test_table2')
tablename in ('test_table', 'test_table2', 'test_table3', 'test_table4')
) q2
$$
) ORDER BY result;
SET citus.log_remote_commands = true;
set citus.grep_remote_commands = '%DROP ROLE%';
drop role role1, role2,role3 ;
drop role distributed_source_role1, distributed_source_role2,distributed_target_role1,local_target_role1,local_source_role1;