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.
pull/7131/head
Onur Tirtir 2023-08-28 18:05:17 +03:00
parent 5bdf19f517
commit 34e3119b48
1 changed files with 21 additions and 17 deletions

View File

@ -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;
}