Skip to content

Commit

Permalink
Prohibit DROP EXTENSION bdr when BDR is active
Browse files Browse the repository at this point in the history
Closes #206
  • Loading branch information
ringerc committed Jul 29, 2016
1 parent a182649 commit 4bc975d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
38 changes: 38 additions & 0 deletions bdr_commandfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,42 @@ bdr_commandfilter_dbname(const char *dbname)
}
}

static void
prevent_drop_extension_bdr(DropStmt *stmt)
{
ListCell *cell;

/* Only interested in DROP EXTENSION */
if (stmt->removeType != OBJECT_EXTENSION)
return;

/* Check to see if the BDR extension is being dropped */
foreach(cell, stmt->objects)
{
ObjectAddress address;
List *objname = lfirst(cell);
Relation relation = NULL;

/* Get an ObjectAddress for the object. */
address = get_object_address(stmt->removeType,
objname, NULL,
&relation,
AccessExclusiveLock,
stmt->missing_ok);

if (!OidIsValid(address.objectId))
continue;

/* for an extension the object name is unqualified */
Assert(list_length(objname) == 1);

if (strcmp(strVal(linitial(objname)), "bdr") == 0)
ereport(ERROR,
(errmsg("Dropping the BDR extension is prohibited while BDR is active"),
errhint("Part this node with bdr.part_by_node_names(...) first, or if appropriate use bdr.remove_bdr_from_local_node(...)")));
}
}

static void
bdr_commandfilter(Node *parsetree,
const char *queryString,
Expand Down Expand Up @@ -858,6 +894,8 @@ bdr_commandfilter(Node *parsetree,
{
DropStmt *stmt = (DropStmt *) parsetree;

prevent_drop_extension_bdr(stmt);

if (EventTriggerSupportsObjectType(stmt->removeType))
break;
else
Expand Down
9 changes: 9 additions & 0 deletions expected/part_bdr.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
CREATE SCHEMA "some $SCHEMA";
CREATE TABLE "some $SCHEMA"."table table table" ("a column" integer);
CREATE SEQUENCE "some $SCHEMA"."some ""sequence"" name" USING bdr;
-- Dropping the BDR extension isn't allowed while BDR is active
DROP EXTENSION bdr;
ERROR: Dropping the BDR extension is prohibited while BDR is active
HINT: Part this node with bdr.part_by_node_names(...) first, or if appropriate use bdr.remove_bdr_from_local_node(...)
-- Initial state
SELECT node_name, node_status FROM bdr.bdr_nodes ORDER BY node_name;
node_name | node_status
Expand Down Expand Up @@ -129,6 +133,11 @@ WARNING: Node node-pg is in state k not expected 'r'. Attempting to remove anyw

(1 row)

-- BDR is parted, but not fully removed, so don't allow the extension
-- to be dropped yet.
DROP EXTENSION bdr;
ERROR: Dropping the BDR extension is prohibited while BDR is active
HINT: Part this node with bdr.part_by_node_names(...) first, or if appropriate use bdr.remove_bdr_from_local_node(...)
-- Strip BDR from this node entirely and convert global sequences to local.
SELECT bdr.remove_bdr_from_local_node(true, true);
WARNING: forcing deletion of possibly active BDR node
Expand Down
7 changes: 7 additions & 0 deletions sql/part_bdr.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ CREATE SCHEMA "some $SCHEMA";
CREATE TABLE "some $SCHEMA"."table table table" ("a column" integer);
CREATE SEQUENCE "some $SCHEMA"."some ""sequence"" name" USING bdr;

-- Dropping the BDR extension isn't allowed while BDR is active
DROP EXTENSION bdr;

-- Initial state
SELECT node_name, node_status FROM bdr.bdr_nodes ORDER BY node_name;

Expand Down Expand Up @@ -90,6 +93,10 @@ SELECT node_name, node_status FROM bdr.bdr_nodes ORDER BY node_name;
-- so a warning will be generated.
SELECT bdr.bdr_part_by_node_names(ARRAY['node-pg']);

-- BDR is parted, but not fully removed, so don't allow the extension
-- to be dropped yet.
DROP EXTENSION bdr;

-- Strip BDR from this node entirely and convert global sequences to local.
SELECT bdr.remove_bdr_from_local_node(true, true);

Expand Down

0 comments on commit 4bc975d

Please sign in to comment.