Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Grant Role support from non-main db #7404

Merged
merged 52 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
20dc902
Adds Grant Role support into 2PC
gurkanindibay Jan 5, 2024
febbadd
Fixes test errors
gurkanindibay Jan 5, 2024
245b451
Adds test for grant role
gurkanindibay Jan 5, 2024
5b577e2
Fixes flaky test error
gurkanindibay Jan 5, 2024
c790a35
Fixes test flakiness
gurkanindibay Jan 5, 2024
57d514c
Merge branch 'main' into grant_role_2pc
gurkanindibay Jan 5, 2024
665c65c
Merge branch 'main' into grant_role_2pc
gurkanindibay Jan 9, 2024
6d259d5
Fixes review issues
gurkanindibay Jan 10, 2024
340baa1
Fixes indentation
gurkanindibay Jan 10, 2024
f2f3541
Merge branch 'main' into grant_role_2pc
gurkanindibay Jan 11, 2024
a6dc70b
Fixes order problem
gurkanindibay Jan 10, 2024
4d9828a
Merge branch 'main' into grant_role_2pc
gurkanindibay Jan 18, 2024
78fd021
Fixes review notes
gurkanindibay Jan 18, 2024
d804aa3
Fixes test errors
gurkanindibay Jan 18, 2024
a0beab3
Merge branch 'main' into grant_role_2pc
gurkanindibay Jan 20, 2024
4c3028e
Merge branch 'main' into grant_role_2pc
gurkanindibay Jan 23, 2024
9a0259c
Adds metadata sync tests
gurkanindibay Jan 24, 2024
eba3553
Changes test order
gurkanindibay Jan 24, 2024
ee59e7e
Merge branch 'main' into grant_role_2pc
gurkanindibay Jan 25, 2024
016081a
Fixes test error
gurkanindibay Jan 24, 2024
3189159
Merge branch 'main' into grant_role_2pc
gurkanindibay Jan 26, 2024
58bddca
Update src/backend/distributed/commands/utility_hook.c
gurkanindibay Jan 29, 2024
3533461
Update src/backend/distributed/commands/utility_hook.c
gurkanindibay Jan 29, 2024
9632798
Update src/backend/distributed/commands/utility_hook.c
gurkanindibay Jan 29, 2024
42864d7
Update src/backend/distributed/commands/utility_hook.c
gurkanindibay Jan 29, 2024
2f45493
Update src/backend/distributed/commands/utility_hook.c
gurkanindibay Jan 29, 2024
510e558
Update src/backend/distributed/commands/utility_hook.c
gurkanindibay Jan 29, 2024
e2e8681
Fixes naming suggestions
gurkanindibay Jan 29, 2024
754d589
Refactors MarkObjectDistributed logic
gurkanindibay Jan 29, 2024
71a733c
Fixes indentation
gurkanindibay Jan 29, 2024
4553e1e
Fixes indentation
gurkanindibay Jan 29, 2024
fb1030f
Merge branch 'main' into grant_role_2pc
gurkanindibay Jan 29, 2024
848cf68
Changes postprocess logic
gurkanindibay Jan 29, 2024
97c060b
Fixes review notes
gurkanindibay Feb 1, 2024
762c390
Merge branch 'main' into grant_role_2pc
gurkanindibay Feb 1, 2024
91b1e8a
Merge branch 'grant_role_2pc' of https://github.com/citusdata/citus i…
gurkanindibay Feb 1, 2024
6bff0ad
Fixes review issues
gurkanindibay Feb 1, 2024
78d8509
Fixes indentation
gurkanindibay Feb 1, 2024
94450cd
Fixes review notes
gurkanindibay Feb 7, 2024
0466f60
Fixes review notes
gurkanindibay Feb 7, 2024
4e5379c
Merge branch 'main' into grant_role_2pc
gurkanindibay Feb 7, 2024
943aaf3
Merge branch 'main' into grant_role_2pc
gurkanindibay Feb 15, 2024
86817ff
Fixes main merge errors
gurkanindibay Feb 15, 2024
b51183b
Fixes review notes
gurkanindibay Feb 15, 2024
0d28702
Fixes review notes
gurkanindibay Feb 15, 2024
bc02206
Fixes review notes
gurkanindibay Feb 15, 2024
9e51149
Fixes review issue
gurkanindibay Feb 15, 2024
7b795f1
Fixes missing roles
gurkanindibay Feb 15, 2024
83e0fc2
Merge branch 'main' into grant_role_2pc
gurkanindibay Feb 16, 2024
7cad89d
Merge branch 'main' into grant_role_2pc
gurkanindibay Feb 19, 2024
aef7ea6
Merge branch 'main' into grant_role_2pc
gurkanindibay Feb 19, 2024
4ef4bad
Update src/backend/distributed/commands/utility_hook.c
gurkanindibay Feb 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 78 additions & 12 deletions src/backend/distributed/commands/utility_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "foreign/foreign.h"
#include "lib/stringinfo.h"
#include "nodes/makefuncs.h"
#include "nodes/nodes.h"
onurctirtir marked this conversation as resolved.
Show resolved Hide resolved
#include "nodes/parsenodes.h"
#include "nodes/pg_list.h"
#include "postmaster/postmaster.h"
Expand Down Expand Up @@ -95,6 +96,18 @@
"SELECT citus_internal.mark_object_distributed(%d, %s, %d)"


typedef struct TwoPcStatementInfo
halilozanakgul marked this conversation as resolved.
Show resolved Hide resolved
{
int statementType;
bool markAsDistributed;
} TwoPcStatementInfo;

const TwoPcStatementInfo twoPcSupportedStatements[] = {
{ T_GrantRoleStmt, false },
{ T_CreateRoleStmt, true }
};


bool EnableDDLPropagation = true; /* ddl propagation is enabled */
int CreateObjectPropagationMode = CREATE_OBJECT_PROPAGATION_IMMEDIATE;
PropSetCmdBehavior PropagateSetCommands = PROPSETCMD_NONE; /* SET prop off */
Expand Down Expand Up @@ -124,6 +137,8 @@
static bool ShouldCheckUndistributeCitusLocalTables(void);
static void RunPreprocessMainDBCommand(Node *parsetree, const char *queryString);
static void RunPostprocessMainDBCommand(Node *parsetree);
static bool IsStatementSupportedIn2Pc(Node *parsetree);
static bool IsStatementMarkDistributedFor2PC(Node *parsetree);

/*
* ProcessUtilityParseTree is a convenience method to create a PlannedStmt out of
Expand Down Expand Up @@ -1603,20 +1618,22 @@
static void
RunPreprocessMainDBCommand(Node *parsetree, const char *queryString)
{
if (IsA(parsetree, CreateRoleStmt))
if (!IsStatementSupportedIn2Pc(parsetree))
{
StringInfo mainDBQuery = makeStringInfo();
appendStringInfo(mainDBQuery,
START_MANAGEMENT_TRANSACTION,
GetCurrentFullTransactionId().value);
RunCitusMainDBQuery(mainDBQuery->data);
mainDBQuery = makeStringInfo();
appendStringInfo(mainDBQuery,
EXECUTE_COMMAND_ON_REMOTE_NODES_AS_USER,
quote_literal_cstr(queryString),
quote_literal_cstr(CurrentUserName()));
RunCitusMainDBQuery(mainDBQuery->data);
return;
}

StringInfo mainDBQuery = makeStringInfo();
appendStringInfo(mainDBQuery,

Check warning on line 1627 in src/backend/distributed/commands/utility_hook.c

View check run for this annotation

Codecov / codecov/patch

src/backend/distributed/commands/utility_hook.c#L1626-L1627

Added lines #L1626 - L1627 were not covered by tests
START_MANAGEMENT_TRANSACTION,
GetCurrentFullTransactionId().value);
RunCitusMainDBQuery(mainDBQuery->data);
mainDBQuery = makeStringInfo();
appendStringInfo(mainDBQuery,

Check warning on line 1632 in src/backend/distributed/commands/utility_hook.c

View check run for this annotation

Codecov / codecov/patch

src/backend/distributed/commands/utility_hook.c#L1629-L1632

Added lines #L1629 - L1632 were not covered by tests
EXECUTE_COMMAND_ON_REMOTE_NODES_AS_USER,
quote_literal_cstr(queryString),
onurctirtir marked this conversation as resolved.
Show resolved Hide resolved
quote_literal_cstr(CurrentUserName()));
gurkanindibay marked this conversation as resolved.
Show resolved Hide resolved
RunCitusMainDBQuery(mainDBQuery->data);

Check warning on line 1636 in src/backend/distributed/commands/utility_hook.c

View check run for this annotation

Codecov / codecov/patch

src/backend/distributed/commands/utility_hook.c#L1635-L1636

Added lines #L1635 - L1636 were not covered by tests
}


Expand All @@ -1627,6 +1644,12 @@
static void
RunPostprocessMainDBCommand(Node *parsetree)
{
if (!IsStatementSupportedIn2Pc(parsetree) ||
!IsStatementMarkDistributedFor2PC(parsetree))

Check warning on line 1648 in src/backend/distributed/commands/utility_hook.c

View check run for this annotation

Codecov / codecov/patch

src/backend/distributed/commands/utility_hook.c#L1648

Added line #L1648 was not covered by tests
gurkanindibay marked this conversation as resolved.
Show resolved Hide resolved
{
return;
}

if (IsA(parsetree, CreateRoleStmt))
{
StringInfo mainDBQuery = makeStringInfo();
Expand All @@ -1640,3 +1663,46 @@
RunCitusMainDBQuery(mainDBQuery->data);
}
}


/*
* IsStatementSupportedIn2Pc returns true if the statement is supported in 2pc
onurctirtir marked this conversation as resolved.
Show resolved Hide resolved
*/
static bool
IsStatementSupportedIn2Pc(Node *parsetree)
halilozanakgul marked this conversation as resolved.
Show resolved Hide resolved
{
NodeTag type = nodeTag(parsetree);

for (int i = 0; i < sizeof(twoPcSupportedStatements) /
sizeof(twoPcSupportedStatements[0]); i++)
{
if (type == twoPcSupportedStatements[i].statementType)
{
return true;
}
}

return false;
}


/*
* IsStatementMarkDistributedFor2PC returns true if the statement should be marked
* as distributed in 2pc
gurkanindibay marked this conversation as resolved.
Show resolved Hide resolved
*/
static bool
IsStatementMarkDistributedFor2PC(Node *parsetree)

Check warning on line 1694 in src/backend/distributed/commands/utility_hook.c

View check run for this annotation

Codecov / codecov/patch

src/backend/distributed/commands/utility_hook.c#L1694

Added line #L1694 was not covered by tests
halilozanakgul marked this conversation as resolved.
Show resolved Hide resolved
{
NodeTag type = nodeTag(parsetree);

Check warning on line 1696 in src/backend/distributed/commands/utility_hook.c

View check run for this annotation

Codecov / codecov/patch

src/backend/distributed/commands/utility_hook.c#L1696

Added line #L1696 was not covered by tests

for (int i = 0; i < sizeof(twoPcSupportedStatements) /
sizeof(twoPcSupportedStatements[0]); i++)

Check warning on line 1699 in src/backend/distributed/commands/utility_hook.c

View check run for this annotation

Codecov / codecov/patch

src/backend/distributed/commands/utility_hook.c#L1699

Added line #L1699 was not covered by tests
{
if (type == twoPcSupportedStatements[i].statementType)
{
return twoPcSupportedStatements[i].markAsDistributed;

Check warning on line 1703 in src/backend/distributed/commands/utility_hook.c

View check run for this annotation

Codecov / codecov/patch

src/backend/distributed/commands/utility_hook.c#L1703

Added line #L1703 was not covered by tests
}
}

return false;
}
Loading