Skip to content

Commit 4bc975d

Browse files
committed
Prohibit DROP EXTENSION bdr when BDR is active
Closes #206
1 parent a182649 commit 4bc975d

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

bdr_commandfilter.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,42 @@ bdr_commandfilter_dbname(const char *dbname)
714714
}
715715
}
716716

717+
static void
718+
prevent_drop_extension_bdr(DropStmt *stmt)
719+
{
720+
ListCell *cell;
721+
722+
/* Only interested in DROP EXTENSION */
723+
if (stmt->removeType != OBJECT_EXTENSION)
724+
return;
725+
726+
/* Check to see if the BDR extension is being dropped */
727+
foreach(cell, stmt->objects)
728+
{
729+
ObjectAddress address;
730+
List *objname = lfirst(cell);
731+
Relation relation = NULL;
732+
733+
/* Get an ObjectAddress for the object. */
734+
address = get_object_address(stmt->removeType,
735+
objname, NULL,
736+
&relation,
737+
AccessExclusiveLock,
738+
stmt->missing_ok);
739+
740+
if (!OidIsValid(address.objectId))
741+
continue;
742+
743+
/* for an extension the object name is unqualified */
744+
Assert(list_length(objname) == 1);
745+
746+
if (strcmp(strVal(linitial(objname)), "bdr") == 0)
747+
ereport(ERROR,
748+
(errmsg("Dropping the BDR extension is prohibited while BDR is active"),
749+
errhint("Part this node with bdr.part_by_node_names(...) first, or if appropriate use bdr.remove_bdr_from_local_node(...)")));
750+
}
751+
}
752+
717753
static void
718754
bdr_commandfilter(Node *parsetree,
719755
const char *queryString,
@@ -858,6 +894,8 @@ bdr_commandfilter(Node *parsetree,
858894
{
859895
DropStmt *stmt = (DropStmt *) parsetree;
860896

897+
prevent_drop_extension_bdr(stmt);
898+
861899
if (EventTriggerSupportsObjectType(stmt->removeType))
862900
break;
863901
else

expected/part_bdr.out

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
CREATE SCHEMA "some $SCHEMA";
55
CREATE TABLE "some $SCHEMA"."table table table" ("a column" integer);
66
CREATE SEQUENCE "some $SCHEMA"."some ""sequence"" name" USING bdr;
7+
-- Dropping the BDR extension isn't allowed while BDR is active
8+
DROP EXTENSION bdr;
9+
ERROR: Dropping the BDR extension is prohibited while BDR is active
10+
HINT: Part this node with bdr.part_by_node_names(...) first, or if appropriate use bdr.remove_bdr_from_local_node(...)
711
-- Initial state
812
SELECT node_name, node_status FROM bdr.bdr_nodes ORDER BY node_name;
913
node_name | node_status
@@ -129,6 +133,11 @@ WARNING: Node node-pg is in state k not expected 'r'. Attempting to remove anyw
129133

130134
(1 row)
131135

136+
-- BDR is parted, but not fully removed, so don't allow the extension
137+
-- to be dropped yet.
138+
DROP EXTENSION bdr;
139+
ERROR: Dropping the BDR extension is prohibited while BDR is active
140+
HINT: Part this node with bdr.part_by_node_names(...) first, or if appropriate use bdr.remove_bdr_from_local_node(...)
132141
-- Strip BDR from this node entirely and convert global sequences to local.
133142
SELECT bdr.remove_bdr_from_local_node(true, true);
134143
WARNING: forcing deletion of possibly active BDR node

sql/part_bdr.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ CREATE SCHEMA "some $SCHEMA";
77
CREATE TABLE "some $SCHEMA"."table table table" ("a column" integer);
88
CREATE SEQUENCE "some $SCHEMA"."some ""sequence"" name" USING bdr;
99

10+
-- Dropping the BDR extension isn't allowed while BDR is active
11+
DROP EXTENSION bdr;
12+
1013
-- Initial state
1114
SELECT node_name, node_status FROM bdr.bdr_nodes ORDER BY node_name;
1215

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

96+
-- BDR is parted, but not fully removed, so don't allow the extension
97+
-- to be dropped yet.
98+
DROP EXTENSION bdr;
99+
93100
-- Strip BDR from this node entirely and convert global sequences to local.
94101
SELECT bdr.remove_bdr_from_local_node(true, true);
95102

0 commit comments

Comments
 (0)