From 34e3119b48633fdc13f209e4ef4ffc770a291183 Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Mon, 28 Aug 2023 18:05:17 +0300 Subject: [PATCH] Intersect shard placements in a table type agnostic way If we're in the middle of a table type conversion (such as from Citus local table to a reference table), the table might not have all the placements that we expect from the table type. For this reason, we should intersect the placements of tables at hand when creating inter-shard ddl tasks. --- src/backend/distributed/commands/table.c | 38 +++++++++++++----------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/backend/distributed/commands/table.c b/src/backend/distributed/commands/table.c index a4b1d2ad1..c93e72599 100644 --- a/src/backend/distributed/commands/table.c +++ b/src/backend/distributed/commands/table.c @@ -3956,25 +3956,29 @@ static void SetInterShardDDLTaskPlacementList(Task *task, ShardInterval *leftShardInterval, ShardInterval *rightShardInterval) { - Oid leftRelationId = leftShardInterval->relationId; - Oid rightRelationId = rightShardInterval->relationId; - if (IsCitusTableType(leftRelationId, REFERENCE_TABLE) && - IsCitusTableType(rightRelationId, CITUS_LOCAL_TABLE)) + uint64 leftShardId = leftShardInterval->shardId; + List *leftShardPlacementList = ActiveShardPlacementList(leftShardId); + + uint64 rightShardId = rightShardInterval->shardId; + List *rightShardPlacementList = ActiveShardPlacementList(rightShardId); + + List *intersectedPlacementList = NIL; + + ShardPlacement *leftShardPlacement = NULL; + foreach_ptr(leftShardPlacement, leftShardPlacementList) { - /* - * If we are defining/dropping a foreign key from a reference table - * to a citus local table, then we will execute ADD/DROP constraint - * command only for coordinator placement of reference table. - */ - uint64 leftShardId = leftShardInterval->shardId; - task->taskPlacementList = ActiveShardPlacementListOnGroup(leftShardId, - COORDINATOR_GROUP_ID); - } - else - { - uint64 leftShardId = leftShardInterval->shardId; - task->taskPlacementList = ActiveShardPlacementList(leftShardId); + ShardPlacement *rightShardPlacement = NULL; + foreach_ptr(rightShardPlacement, rightShardPlacementList) + { + if (leftShardPlacement->nodeId == rightShardPlacement->nodeId) + { + intersectedPlacementList = lappend(intersectedPlacementList, + leftShardPlacement); + } + } } + + task->taskPlacementList = intersectedPlacementList; }