Skip to content

Commit

Permalink
Stop background daemon before dropping the database (#6688)
Browse files Browse the repository at this point in the history
DESCRIPTION: Stop maintenance daemon when dropping a database even
without Citus extension

Fixes #6670
  • Loading branch information
gokhangulbiz authored Feb 3, 2023
1 parent c7f8c5d commit b6a4652
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/backend/distributed/commands/utility_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,23 @@ multi_ProcessUtility(PlannedStmt *pstmt,
PreprocessCreateExtensionStmtForCitusColumnar(parsetree);
}

/*
* Make sure that on DROP DATABASE we terminate the background daemon
* associated with it.
*/
if (IsA(parsetree, DropdbStmt))
{
const bool missingOK = true;
DropdbStmt *dropDbStatement = (DropdbStmt *) parsetree;
char *dbname = dropDbStatement->dbname;
Oid databaseOid = get_database_oid(dbname, missingOK);

if (OidIsValid(databaseOid))
{
StopMaintenanceDaemon(databaseOid);
}
}

if (!CitusHasBeenLoaded())
{
/*
Expand Down Expand Up @@ -678,22 +695,9 @@ ProcessUtilityInternal(PlannedStmt *pstmt,
}

/*
* Make sure that on DROP DATABASE we terminate the background daemon
* Make sure that on DROP EXTENSION we terminate the background daemon
* associated with it.
*/
if (IsA(parsetree, DropdbStmt))
{
const bool missingOK = true;
DropdbStmt *dropDbStatement = (DropdbStmt *) parsetree;
char *dbname = dropDbStatement->dbname;
Oid databaseOid = get_database_oid(dbname, missingOK);

if (OidIsValid(databaseOid))
{
StopMaintenanceDaemon(databaseOid);
}
}

if (IsDropCitusExtensionStmt(parsetree))
{
StopMaintenanceDaemon(MyDatabaseId);
Expand Down
43 changes: 43 additions & 0 deletions src/test/regress/expected/drop_database.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- coordinator
CREATE SCHEMA drop_database;
SET search_path TO drop_database;
SET citus.shard_count TO 4;
SET citus.shard_replication_factor TO 1;
SET citus.next_shard_id TO 35137400;
CREATE DATABASE citus_created;
NOTICE: Citus partially supports CREATE DATABASE for distributed databases
DETAIL: Citus does not propagate CREATE DATABASE command to workers
HINT: You can manually create a database and its extensions on workers.
\c citus_created
CREATE EXTENSION citus;
CREATE DATABASE citus_not_created;
NOTICE: Citus partially supports CREATE DATABASE for distributed databases
DETAIL: Citus does not propagate CREATE DATABASE command to workers
HINT: You can manually create a database and its extensions on workers.
\c citus_not_created
DROP DATABASE citus_created;
\c regression
DROP DATABASE citus_not_created;
-- worker1
\c - - - :worker_1_port
SET search_path TO drop_database;
SET citus.shard_count TO 4;
SET citus.shard_replication_factor TO 1;
SET citus.next_shard_id TO 35137400;
CREATE DATABASE citus_created;
NOTICE: Citus partially supports CREATE DATABASE for distributed databases
DETAIL: Citus does not propagate CREATE DATABASE command to workers
HINT: You can manually create a database and its extensions on workers.
\c citus_created
CREATE EXTENSION citus;
CREATE DATABASE citus_not_created;
NOTICE: Citus partially supports CREATE DATABASE for distributed databases
DETAIL: Citus does not propagate CREATE DATABASE command to workers
HINT: You can manually create a database and its extensions on workers.
\c citus_not_created
DROP DATABASE citus_created;
\c regression
DROP DATABASE citus_not_created;
\c - - - :master_port
SET client_min_messages TO WARNING;
DROP SCHEMA drop_database CASCADE;
1 change: 1 addition & 0 deletions src/test/regress/multi_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,4 @@ test: ensure_no_shared_connection_leak
test: check_mx

test: generated_identity
test: drop_database
45 changes: 45 additions & 0 deletions src/test/regress/sql/drop_database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- coordinator
CREATE SCHEMA drop_database;
SET search_path TO drop_database;
SET citus.shard_count TO 4;
SET citus.shard_replication_factor TO 1;
SET citus.next_shard_id TO 35137400;

CREATE DATABASE citus_created;

\c citus_created
CREATE EXTENSION citus;

CREATE DATABASE citus_not_created;

\c citus_not_created
DROP DATABASE citus_created;

\c regression
DROP DATABASE citus_not_created;

-- worker1
\c - - - :worker_1_port

SET search_path TO drop_database;
SET citus.shard_count TO 4;
SET citus.shard_replication_factor TO 1;
SET citus.next_shard_id TO 35137400;

CREATE DATABASE citus_created;

\c citus_created
CREATE EXTENSION citus;

CREATE DATABASE citus_not_created;

\c citus_not_created
DROP DATABASE citus_created;

\c regression
DROP DATABASE citus_not_created;

\c - - - :master_port

SET client_min_messages TO WARNING;
DROP SCHEMA drop_database CASCADE;

0 comments on commit b6a4652

Please sign in to comment.