Fixes review notes

pull/7384/head
gindibay 2023-11-22 12:13:35 +03:00
parent 557dd71133
commit f3427932ed
6 changed files with 70 additions and 36 deletions

View File

@ -278,8 +278,8 @@ static DistributeObjectOps Any_CreateRole = {
static DistributeObjectOps Any_ReassignOwned = {
.deparse = DeparseReassignOwnedStmt,
.qualify = NULL,
.preprocess = PreprocessReassignOwnedStmt,
.postprocess = NULL,
.preprocess = NULL,
.postprocess = PostprocessReassignOwnedStmt,
.operationType = DIST_OPS_DROP,
.address = NULL,
.markDistributed = false,

View File

@ -90,9 +90,25 @@ PreprocessDropOwnedStmt(Node *node, const char *queryString,
}
/*
* Post-processes a REASSIGN OWNED statement.
*
* This function takes a Node pointer representing a REASSIGN OWNED statement,
* and performs any necessary post-processing after the statement has been executed.
* In this method, we propagate all the roles that are being reassigned.
* Therefore, we don't filter the roles based on whether they are distributed or not.
* If roles are not distributed and those roles are not present in the nodes
* where the statement is being propagated, then the statement will fail.
*
* Parameters:
* stmt: A pointer to a Node representing a REASSIGN OWNED statement.
* queryString: The original SQL command string from the client.
*
* Returns:
* List of SQL statements to be executed.
*/
List *
PreprocessReassignOwnedStmt(Node *node, const char *queryString,
ProcessUtilityContext processUtilityContext)
PostprocessReassignOwnedStmt(Node *node, const char *queryString)
{
ReassignOwnedStmt *stmt = castNode(ReassignOwnedStmt, node);
List *allReassignRoles = stmt->roles;

View File

@ -427,8 +427,7 @@ extern List * CreateExtensionStmtObjectAddress(Node *stmt, bool missing_ok, bool
/* owned.c - forward declarations */
extern List * PreprocessDropOwnedStmt(Node *node, const char *queryString,
ProcessUtilityContext processUtilityContext);
extern List * PreprocessReassignOwnedStmt(Node *node, const char *queryString,
ProcessUtilityContext processUtilityContext);
extern List * PostprocessReassignOwnedStmt(Node *node, const char *queryString);
/* policy.c - forward declarations */
extern List * CreatePolicyCommands(Oid relationId);

View File

@ -1,8 +1,11 @@
CREATE ROLE role1;
CREATE ROLE role2;
GRANT CREATE ON SCHEMA public TO role1;
create ROLE role2;
CREATE ROLE role3;
GRANT CREATE ON SCHEMA public TO role1,role2;
SET ROLE role1;
CREATE TABLE public.test_table (col1 int);
set role role2;
CREATE TABLE public.test_table2 (col2 int);
RESET ROLE;
select create_distributed_table('test_table', 'col1');
create_distributed_table
@ -10,6 +13,12 @@ select create_distributed_table('test_table', 'col1');
(1 row)
select create_distributed_table('test_table2', 'col2');
create_distributed_table
---------------------------------------------------------------------
(1 row)
SELECT result from run_command_on_all_nodes(
$$
SELECT jsonb_agg(to_jsonb(q2.*)) FROM (
@ -20,23 +29,23 @@ SELECT result from run_command_on_all_nodes(
FROM
pg_tables
WHERE
tablename = 'test_table'
tablename in ('test_table', 'test_table2')
) q2
$$
) ORDER BY result;
result
result
---------------------------------------------------------------------
[{"tablename": "test_table", "schemaname": "public", "tableowner": "role1"}]
[{"tablename": "test_table", "schemaname": "public", "tableowner": "role1"}]
[{"tablename": "test_table", "schemaname": "public", "tableowner": "role1"}]
[{"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"}]
(3 rows)
set citus.log_remote_commands to on;
set citus.grep_remote_commands = '%REASSIGN OWNED BY%';
REASSIGN OWNED BY role1 TO role2;
NOTICE: issuing REASSIGN OWNED BY role1 TO role2
REASSIGN OWNED BY role1,role2 TO role3;
NOTICE: issuing REASSIGN OWNED BY role1, role2 TO role3
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
NOTICE: issuing REASSIGN OWNED BY role1 TO role2
NOTICE: issuing REASSIGN OWNED BY role1, role2 TO role3
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
SET citus.log_remote_commands = false;
SELECT result from run_command_on_all_nodes(
@ -49,19 +58,20 @@ SELECT result from run_command_on_all_nodes(
FROM
pg_tables
WHERE
tablename = 'test_table'
tablename in ('test_table', 'test_table2')
) q2
$$
) ORDER BY result;
result
result
---------------------------------------------------------------------
[{"tablename": "test_table", "schemaname": "public", "tableowner": "role2"}]
[{"tablename": "test_table", "schemaname": "public", "tableowner": "role2"}]
[{"tablename": "test_table", "schemaname": "public", "tableowner": "role2"}]
[{"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"}]
(3 rows)
--clear resources
SET citus.log_remote_commands = true;
DROP OWNED BY role1, role2;
DROP OWNED BY role1, role2,role3;
SET citus.log_remote_commands = false;
SELECT result from run_command_on_all_nodes(
$$
@ -73,7 +83,7 @@ SELECT result from run_command_on_all_nodes(
FROM
pg_tables
WHERE
tablename = 'test_table'
tablename in ('test_table', 'test_table2')
) q2
$$
) ORDER BY result;
@ -86,8 +96,8 @@ WHERE
SET citus.log_remote_commands = true;
set citus.grep_remote_commands = '%DROP ROLE%';
drop role role1, role2 ;
NOTICE: issuing DROP ROLE role1, role2
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
NOTICE: issuing DROP ROLE role1, role2, role3
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx

View File

@ -56,7 +56,7 @@ test: grant_on_database_propagation
test: alter_database_propagation
test: citus_shards
test: reassure_owned
test: reassign_owned
# ----------
# multi_citus_tools tests utility functions written for citus tools

View File

@ -1,12 +1,19 @@
CREATE ROLE role1;
CREATE ROLE role2;
GRANT CREATE ON SCHEMA public TO role1;
create ROLE role2;
CREATE ROLE role3;
GRANT CREATE ON SCHEMA public TO role1,role2;
SET ROLE role1;
CREATE TABLE public.test_table (col1 int);
set role role2;
CREATE TABLE public.test_table2 (col2 int);
RESET ROLE;
select create_distributed_table('test_table', 'col1');
select create_distributed_table('test_table2', 'col2');
SELECT result from run_command_on_all_nodes(
$$
@ -18,14 +25,14 @@ SELECT result from run_command_on_all_nodes(
FROM
pg_tables
WHERE
tablename = 'test_table'
tablename in ('test_table', 'test_table2')
) q2
$$
) ORDER BY result;
set citus.log_remote_commands to on;
set citus.grep_remote_commands = '%REASSIGN OWNED BY%';
REASSIGN OWNED BY role1 TO role2;
REASSIGN OWNED BY role1,role2 TO role3;
SET citus.log_remote_commands = false;
@ -39,15 +46,15 @@ SELECT result from run_command_on_all_nodes(
FROM
pg_tables
WHERE
tablename = 'test_table'
tablename in ('test_table', 'test_table2')
) q2
$$
) ORDER BY result;
--clear resources
SET citus.log_remote_commands = true;
DROP OWNED BY role1, role2;
DROP OWNED BY role1, role2,role3;
SET citus.log_remote_commands = false;
SELECT result from run_command_on_all_nodes(
@ -60,11 +67,13 @@ SELECT result from run_command_on_all_nodes(
FROM
pg_tables
WHERE
tablename = 'test_table'
tablename in ('test_table', 'test_table2')
) q2
$$
) ORDER BY result;
SET citus.log_remote_commands = true;
set citus.grep_remote_commands = '%DROP ROLE%';
drop role role1, role2 ;
drop role role1, role2,role3 ;