-
Notifications
You must be signed in to change notification settings - Fork 668
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: TsinghuaLucky912 <tsinghualucky912@foxmail.com> Fixes #5763
- Loading branch information
1 parent
3b24c47
commit ad6450b
Showing
14 changed files
with
284 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/*------------------------------------------------------------------------- | ||
* | ||
* owned.c | ||
* Commands for DROP OWNED statements. | ||
* | ||
* Copyright (c) Citus Data, Inc. | ||
* | ||
*------------------------------------------------------------------------- | ||
*/ | ||
|
||
#include "postgres.h" | ||
|
||
#include "access/heapam.h" | ||
#include "access/htup_details.h" | ||
#include "access/genam.h" | ||
#include "access/table.h" | ||
#include "access/xact.h" | ||
#include "catalog/catalog.h" | ||
#include "catalog/pg_auth_members.h" | ||
#include "catalog/pg_authid.h" | ||
#include "catalog/pg_db_role_setting.h" | ||
#include "catalog/pg_type.h" | ||
#include "catalog/objectaddress.h" | ||
#include "commands/dbcommands.h" | ||
#include "distributed/citus_ruleutils.h" | ||
#include "distributed/citus_safe_lib.h" | ||
#include "distributed/commands.h" | ||
#include "distributed/commands/utility_hook.h" | ||
#include "distributed/deparser.h" | ||
#include "distributed/listutils.h" | ||
#include "distributed/coordinator_protocol.h" | ||
#include "distributed/metadata/distobject.h" | ||
#include "distributed/metadata_sync.h" | ||
#include "distributed/metadata/distobject.h" | ||
#include "distributed/multi_executor.h" | ||
#include "distributed/relation_access_tracking.h" | ||
#include "distributed/version_compat.h" | ||
#include "distributed/worker_transaction.h" | ||
#include "miscadmin.h" | ||
#include "nodes/makefuncs.h" | ||
#include "nodes/parsenodes.h" | ||
#include "nodes/pg_list.h" | ||
#include "parser/scansup.h" | ||
#include "utils/builtins.h" | ||
#include "utils/fmgroids.h" | ||
#include "utils/rel.h" | ||
#include "utils/varlena.h" | ||
#include "utils/syscache.h" | ||
|
||
/* | ||
* PreprocessDropOwnedStmt finds the distributed role out of the ones | ||
* being dropped and unmarks them distributed and creates the drop statements | ||
* for the workers. | ||
*/ | ||
List * | ||
PreprocessDropOwnedStmt(Node *node, const char *queryString, | ||
ProcessUtilityContext processUtilityContext) | ||
{ | ||
DropOwnedStmt *stmt = castNode(DropOwnedStmt, node); | ||
List *allDropRoles = stmt->roles; | ||
|
||
List *distributedDropRoles = FilterDistributedRoles(allDropRoles); | ||
if (list_length(distributedDropRoles) <= 0) | ||
{ | ||
return NIL; | ||
} | ||
|
||
if (!ShouldPropagate()) | ||
{ | ||
return NIL; | ||
} | ||
|
||
/* check creation against multi-statement transaction policy */ | ||
if (!ShouldPropagateCreateInCoordinatedTransction()) | ||
{ | ||
return NIL; | ||
} | ||
|
||
EnsureCoordinator(); | ||
|
||
stmt->roles = distributedDropRoles; | ||
char *sql = DeparseTreeNode((Node *) stmt); | ||
stmt->roles = allDropRoles; | ||
|
||
List *commands = list_make3(DISABLE_DDL_PROPAGATION, | ||
sql, | ||
ENABLE_DDL_PROPAGATION); | ||
|
||
return NodeDDLTaskList(NON_COORDINATOR_NODES, commands); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/*------------------------------------------------------------------------- | ||
* | ||
* deparse_owned_stmts.c | ||
* Functions to turn all Statement structures related to owned back | ||
* into sql. | ||
* | ||
* Copyright (c), Citus Data, Inc. | ||
* | ||
*------------------------------------------------------------------------- | ||
*/ | ||
|
||
#include "postgres.h" | ||
|
||
#include "pg_version_compat.h" | ||
|
||
#include "distributed/citus_ruleutils.h" | ||
#include "distributed/deparser.h" | ||
#include "lib/stringinfo.h" | ||
#include "nodes/parsenodes.h" | ||
#include "utils/builtins.h" | ||
|
||
static void AppendDropOwnedStmt(StringInfo buf, DropOwnedStmt *stmt); | ||
static void AppendRoleList(StringInfo buf, List *roleList); | ||
|
||
/* | ||
* DeparseDropOwnedStmt builds and returns a string representing of the | ||
* DropOwnedStmt for application on a remote server. | ||
*/ | ||
char * | ||
DeparseDropOwnedStmt(Node *node) | ||
{ | ||
DropOwnedStmt *stmt = castNode(DropOwnedStmt, node); | ||
|
||
StringInfoData buf = { 0 }; | ||
initStringInfo(&buf); | ||
|
||
AppendDropOwnedStmt(&buf, stmt); | ||
|
||
return buf.data; | ||
} | ||
|
||
|
||
/* | ||
* AppendDropOwnedStmt generates the string representation of the | ||
* DropOwnedStmt and appends it to the buffer. | ||
*/ | ||
static void | ||
AppendDropOwnedStmt(StringInfo buf, DropOwnedStmt *stmt) | ||
{ | ||
appendStringInfo(buf, "DROP OWNED BY "); | ||
|
||
AppendRoleList(buf, stmt->roles); | ||
|
||
if (stmt->behavior == DROP_RESTRICT) | ||
{ | ||
appendStringInfo(buf, " RESTRICT"); | ||
} | ||
else if (stmt->behavior == DROP_CASCADE) | ||
{ | ||
appendStringInfo(buf, " CASCADE"); | ||
} | ||
} | ||
|
||
|
||
static void | ||
AppendRoleList(StringInfo buf, List *roleList) | ||
{ | ||
ListCell *cell = NULL; | ||
foreach(cell, roleList) | ||
{ | ||
Node *roleNode = (Node *) lfirst(cell); | ||
Assert(IsA(roleNode, RoleSpec) || IsA(roleNode, AccessPriv)); | ||
char const *rolename = NULL; | ||
if (IsA(roleNode, RoleSpec)) | ||
{ | ||
rolename = RoleSpecString((RoleSpec *) roleNode, true); | ||
} | ||
appendStringInfoString(buf, rolename); | ||
if (cell != list_tail(roleList)) | ||
{ | ||
appendStringInfo(buf, ", "); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
-- | ||
-- ISSUE_5763 | ||
-- | ||
-- Issue: DROP OWNED BY fails to drop the schemas on the workers | ||
-- Link: https://github.com/citusdata/citus/issues/5763 | ||
-- | ||
CREATE USER issue_5763_1 WITH SUPERUSER; | ||
CREATE USER issue_5763_2 WITH SUPERUSER; | ||
\c - issue_5763_1 - :master_port | ||
CREATE SCHEMA issue_5763_sc_1; | ||
\c - issue_5763_2 - :master_port | ||
CREATE SCHEMA issue_5763_sc_2; | ||
\c - postgres - :master_port | ||
DROP OWNED BY issue_5763_1, issue_5763_2; | ||
\c - issue_5763_1 - :master_port | ||
CREATE SCHEMA issue_5763_sc_1; | ||
\c - postgres - :master_port | ||
DROP SCHEMA issue_5763_sc_1; | ||
DROP USER issue_5763_1, issue_5763_2; | ||
-- test CASCADE options | ||
CREATE USER issue_5763_3 WITH SUPERUSER; | ||
\c - issue_5763_3 - :master_port | ||
CREATE SCHEMA issue_5763_sc_3; | ||
CREATE TABLE issue_5763_sc_3.tb1(id int); | ||
\c - postgres - :master_port | ||
DROP OWNED BY issue_5763_3 CASCADE; | ||
DROP USER issue_5763_3; | ||
-- test non-distributed role | ||
SET citus.enable_create_role_propagation TO off; | ||
CREATE USER issue_5763_4 WITH SUPERUSER; | ||
NOTICE: not propagating CREATE ROLE/USER commands to worker nodes | ||
HINT: Connect to worker nodes directly to manually create all necessary users and roles. | ||
\c - issue_5763_4 - :master_port | ||
set citus.enable_ddl_propagation = off; | ||
CREATE SCHEMA issue_5763_sc_4; | ||
\c - postgres - :master_port | ||
DROP OWNED BY issue_5763_4 RESTRICT; | ||
DROP USER issue_5763_4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
-- | ||
-- ISSUE_5763 | ||
-- | ||
-- Issue: DROP OWNED BY fails to drop the schemas on the workers | ||
-- Link: https://github.com/citusdata/citus/issues/5763 | ||
-- | ||
|
||
CREATE USER issue_5763_1 WITH SUPERUSER; | ||
CREATE USER issue_5763_2 WITH SUPERUSER; | ||
|
||
\c - issue_5763_1 - :master_port | ||
CREATE SCHEMA issue_5763_sc_1; | ||
|
||
\c - issue_5763_2 - :master_port | ||
CREATE SCHEMA issue_5763_sc_2; | ||
|
||
\c - postgres - :master_port | ||
DROP OWNED BY issue_5763_1, issue_5763_2; | ||
|
||
\c - issue_5763_1 - :master_port | ||
CREATE SCHEMA issue_5763_sc_1; | ||
|
||
\c - postgres - :master_port | ||
DROP SCHEMA issue_5763_sc_1; | ||
DROP USER issue_5763_1, issue_5763_2; | ||
|
||
-- test CASCADE options | ||
CREATE USER issue_5763_3 WITH SUPERUSER; | ||
|
||
\c - issue_5763_3 - :master_port | ||
CREATE SCHEMA issue_5763_sc_3; | ||
CREATE TABLE issue_5763_sc_3.tb1(id int); | ||
|
||
\c - postgres - :master_port | ||
DROP OWNED BY issue_5763_3 CASCADE; | ||
|
||
DROP USER issue_5763_3; | ||
|
||
-- test non-distributed role | ||
SET citus.enable_create_role_propagation TO off; | ||
CREATE USER issue_5763_4 WITH SUPERUSER; | ||
|
||
\c - issue_5763_4 - :master_port | ||
set citus.enable_ddl_propagation = off; | ||
CREATE SCHEMA issue_5763_sc_4; | ||
|
||
\c - postgres - :master_port | ||
DROP OWNED BY issue_5763_4 RESTRICT; | ||
|
||
DROP USER issue_5763_4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.