From 2bd8f8f12e869416c088df11c4c9b385a2ebe0e1 Mon Sep 17 00:00:00 2001 From: Metin Doslu Date: Thu, 19 Jan 2017 18:18:57 +0200 Subject: [PATCH] Add a function to delete shard metadata from MX nodes --- .../distributed/metadata/metadata_sync.c | 33 ++++++++++++++++++- src/include/distributed/metadata_sync.h | 1 + 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/backend/distributed/metadata/metadata_sync.c b/src/backend/distributed/metadata/metadata_sync.c index d0bbf5e05..b69ec3139 100644 --- a/src/backend/distributed/metadata/metadata_sync.c +++ b/src/backend/distributed/metadata/metadata_sync.c @@ -513,7 +513,7 @@ TableOwnerResetCommand(Oid relationId) /* - * ShardListInsertCommand generates a singe command that can be + * ShardListInsertCommand generates a single command that can be * executed to replicate shard and shard placement metadata for the * given shard intervals. The function assumes that each shard has a * single placement, and asserts this information. @@ -634,6 +634,37 @@ ShardListInsertCommand(List *shardIntervalList) } +/* + * ShardListDeleteCommand generates a command list that can be executed to delete + * shard and shard placement metadata for the given shard. + */ +List * +ShardDeleteCommandList(ShardInterval *shardInterval) +{ + uint64 shardId = shardInterval->shardId; + List *commandList = NIL; + StringInfo deletePlacementCommand = NULL; + StringInfo deleteShardCommand = NULL; + + /* create command to delete shard placements */ + deletePlacementCommand = makeStringInfo(); + appendStringInfo(deletePlacementCommand, + "DELETE FROM pg_dist_shard_placement WHERE shardid = %lu", + shardId); + + commandList = lappend(commandList, deletePlacementCommand->data); + + /* create command to delete shard */ + deleteShardCommand = makeStringInfo(); + appendStringInfo(deleteShardCommand, + "DELETE FROM pg_dist_shard WHERE shardid = %lu", shardId); + + commandList = lappend(commandList, deleteShardCommand->data); + + return commandList; +} + + /* * NodeDeleteCommand generate a command that can be * executed to delete the metadata for a worker node. diff --git a/src/include/distributed/metadata_sync.h b/src/include/distributed/metadata_sync.h index c9fef4e1c..f14a9dcd3 100644 --- a/src/include/distributed/metadata_sync.h +++ b/src/include/distributed/metadata_sync.h @@ -28,6 +28,7 @@ extern char * DistributionDeleteCommand(char *schemaName, extern char * TableOwnerResetCommand(Oid distributedRelationId); extern char * NodeListInsertCommand(List *workerNodeList); extern List * ShardListInsertCommand(List *shardIntervalList); +extern List * ShardDeleteCommandList(ShardInterval *shardInterval); extern char * NodeDeleteCommand(uint32 nodeId); extern char * ColocationIdUpdateCommand(Oid relationId, uint32 colocationId); extern char * CreateSchemaDDLCommand(Oid schemaId);