Don't propagate ALTER ROLE SET when scoped to a different database (#4471)

Co-authored-by: brberger <brberger@microsoft.com>
pull/4607/head
Brian Bergeron 2021-02-01 04:49:26 -08:00 committed by GitHub
parent 31763ef079
commit 1253eeb9ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 0 deletions

View File

@ -195,6 +195,14 @@ PreprocessAlterRoleSetStmt(Node *node, const char *queryString,
} }
AlterRoleSetStmt *stmt = castNode(AlterRoleSetStmt, node); AlterRoleSetStmt *stmt = castNode(AlterRoleSetStmt, node);
/* don't propagate if the statement is scoped to another database */
if (stmt->database != NULL &&
strcmp(stmt->database, get_database_name(MyDatabaseId)) != 0)
{
return NIL;
}
ObjectAddress address = GetObjectAddressFromParseTree(node, false); ObjectAddress address = GetObjectAddressFromParseTree(node, false);
/* /*

View File

@ -223,6 +223,27 @@ SELECT run_command_on_workers('SHOW enable_hashagg');
(localhost,57638,t,on) (localhost,57638,t,on)
(2 rows) (2 rows)
-- check that ALTER ROLE SET is not propagated when scoped to a different database
-- 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.
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
---------------------------------------------------------------------
REGRESSION | {"public.myguc=Hello from coordinator only"}
(1 row)
SELECT run_command_on_workers($$SELECT json_agg((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%'$$);
run_command_on_workers
---------------------------------------------------------------------
(localhost,57637,t,"")
(localhost,57638,t,"")
(2 rows)
DROP DATABASE "REGRESSION";
-- make sure alter role set is not propagated when the feature is deliberately turned off -- make sure alter role set is not propagated when the feature is deliberately turned off
SET citus.enable_alter_role_set_propagation TO off; SET citus.enable_alter_role_set_propagation TO off;
-- remove 1 node to verify settings are NOT copied when the node gets added back -- remove 1 node to verify settings are NOT copied when the node gets added back

View File

@ -72,6 +72,14 @@ SELECT run_command_on_workers('SHOW enable_hashjoin');
SELECT run_command_on_workers('SHOW enable_indexonlyscan'); SELECT run_command_on_workers('SHOW enable_indexonlyscan');
SELECT run_command_on_workers('SHOW enable_hashagg'); SELECT run_command_on_workers('SHOW enable_hashagg');
-- check that ALTER ROLE SET is not propagated when scoped to a different database
-- also test case sensitivity
CREATE DATABASE "REGRESSION";
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%';
SELECT run_command_on_workers($$SELECT json_agg((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%'$$);
DROP DATABASE "REGRESSION";
-- make sure alter role set is not propagated when the feature is deliberately turned off -- make sure alter role set is not propagated when the feature is deliberately turned off
SET citus.enable_alter_role_set_propagation TO off; SET citus.enable_alter_role_set_propagation TO off;
-- remove 1 node to verify settings are NOT copied when the node gets added back -- remove 1 node to verify settings are NOT copied when the node gets added back