forked from citusdata/citus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix the problem citusdata#5763 DROP OWNED BY fails to drop the schema…
…s on the workers
- Loading branch information
1 parent
3b24c47
commit 8ff44b7
Showing
9 changed files
with
230 additions
and
1 deletion.
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,84 @@ | ||
/*------------------------------------------------------------------------- | ||
* | ||
* 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; | ||
} | ||
|
||
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,88 @@ | ||
/*------------------------------------------------------------------------- | ||
* | ||
* 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); | ||
} | ||
if (IsA(roleNode, AccessPriv)) | ||
{ | ||
rolename = quote_identifier(((AccessPriv *) roleNode)->priv_name); | ||
} | ||
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
Empty file.
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,16 @@ | ||
-- | ||
-- 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 WITH SUPERUSER; | ||
\c - issue_5763 - :master_port | ||
CREATE SCHEMA issue_5763_sc; | ||
\c - postgres - :master_port | ||
DROP OWNED BY issue_5763; | ||
\c - issue_5763 - :master_port | ||
CREATE SCHEMA issue_5763_sc; | ||
\c - postgres - :master_port | ||
DROP SCHEMA issue_5763_sc; | ||
DROP USER issue_5763; |
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,21 @@ | ||
-- | ||
-- 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 WITH SUPERUSER; | ||
|
||
\c - issue_5763 - :master_port | ||
CREATE SCHEMA issue_5763_sc; | ||
|
||
\c - postgres - :master_port | ||
DROP OWNED BY issue_5763; | ||
|
||
\c - issue_5763 - :master_port | ||
CREATE SCHEMA issue_5763_sc; | ||
|
||
\c - postgres - :master_port | ||
DROP SCHEMA issue_5763_sc; | ||
DROP USER issue_5763; |