From 92b1cdf6c01f2b8f400ed47df32c970c0464e1fa Mon Sep 17 00:00:00 2001 From: Nitish Upreti Date: Thu, 25 Aug 2022 13:18:04 -0700 Subject: [PATCH] Deferred drop Hello World --- src/backend/distributed/operations/shard_cleaner.c | 10 +++++++++- src/backend/distributed/sql/citus--11.0-4--11.1-1.sql | 7 +++++-- src/include/distributed/pg_dist_cleanup.h | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/backend/distributed/operations/shard_cleaner.c b/src/backend/distributed/operations/shard_cleaner.c index 52b85409c..cd81e1a5b 100644 --- a/src/backend/distributed/operations/shard_cleaner.c +++ b/src/backend/distributed/operations/shard_cleaner.c @@ -61,6 +61,8 @@ typedef struct CleanupRecord CleanupPolicy policy; } CleanupRecord; +/* operation ID set by StartNewOperationNeedingCleanup */ +OperationId CurrentOperationId = INVALID_OPERATION_ID; /* declarations for dynamic loading */ PG_FUNCTION_INFO_V1(citus_cleanup_orphaned_shards); @@ -189,6 +191,12 @@ TryDropOrphanedShards(bool waitForLocks) static int DropOrphanedShardsForCleanup() { + /* Only runs on Coordinator */ + if (!IsCoordinator()) + { + return 0; + } + List *cleanupRecordList = ListCleanupRecords(); int removedShardCountForCleanup = 0; @@ -543,7 +551,7 @@ static bool TryDropShardOutsideTransaction(char *qualifiedTableName, char *nodeName, int nodePort) { ereport(LOG, (errmsg("dropping shard placement %s " - "on %s:%d after it was moved away", + "on %s:%d", qualifiedTableName, nodeName, nodePort))); /* prepare sql query to execute to drop the shard */ diff --git a/src/backend/distributed/sql/citus--11.0-4--11.1-1.sql b/src/backend/distributed/sql/citus--11.0-4--11.1-1.sql index 8107f6adc..6fa8b7318 100644 --- a/src/backend/distributed/sql/citus--11.0-4--11.1-1.sql +++ b/src/backend/distributed/sql/citus--11.0-4--11.1-1.sql @@ -92,5 +92,8 @@ ALTER TABLE citus.pg_dist_cleanup SET SCHEMA pg_catalog; -- Sequence used to generate an operation ID for use in pg_dist_cleanup_record. -CREATE SEQUENCE citus.pg_dist_operation_id_seq; -ALTER SEQUENCE citus.pg_dist_operation_id_seq SET SCHEMA pg_catalog; +CREATE SEQUENCE citus.pg_dist_operationid_seq; +ALTER SEQUENCE citus.pg_dist_operationid_seq SET SCHEMA pg_catalog; + +CREATE SEQUENCE citus.pg_dist_cleanup_recordid_seq; +ALTER SEQUENCE citus.pg_dist_cleanup_recordid_seq SET SCHEMA pg_catalog; diff --git a/src/include/distributed/pg_dist_cleanup.h b/src/include/distributed/pg_dist_cleanup.h index d8aa791b4..5f77911bf 100644 --- a/src/include/distributed/pg_dist_cleanup.h +++ b/src/include/distributed/pg_dist_cleanup.h @@ -28,7 +28,7 @@ #define PG_CATALOG "pg_catalog" #define PG_DIST_CLEANUP "pg_dist_cleanup" #define OPERATIONID_SEQUENCE_NAME "pg_dist_operationid_seq" -#define CLEANUPRECORDID_SEQUENCE_NAME "pg_dist_cleanup_record_id_seq" +#define CLEANUPRECORDID_SEQUENCE_NAME "pg_dist_cleanup_recordid_seq" #endif /* PG_DIST_CLEANUP_H */