From f68ac4a7cf8eca34fa4f7bc9eab8bda2e665d6a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96nder=20Kalac=C4=B1?= Date: Fri, 28 Jan 2022 13:38:14 +0100 Subject: [PATCH] Consider foreign keys between reference tables (#5659) On #5071, we avoid edge cases, but below there are foreign key constraints as well This commit makes sure we cover those as well --- .../distributed/utils/reference_table_utils.c | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/backend/distributed/utils/reference_table_utils.c b/src/backend/distributed/utils/reference_table_utils.c index 50ee92d0e..f2a170bc4 100644 --- a/src/backend/distributed/utils/reference_table_utils.c +++ b/src/backend/distributed/utils/reference_table_utils.c @@ -350,22 +350,6 @@ ReplicateReferenceTableShardToNode(ShardInterval *shardInterval, char *nodeName, List *ddlCommandList = CopyShardCommandList(shardInterval, srcNodeName, srcNodePort, includeData); - List *shardPlacementList = ShardPlacementListIncludingOrphanedPlacements(shardId); - ShardPlacement *targetPlacement = SearchShardPlacementInList(shardPlacementList, - nodeName, nodePort); - if (targetPlacement != NULL) - { - if (targetPlacement->shardState == SHARD_STATE_ACTIVE) - { - /* We already have the shard, nothing to do */ - return; - } - ereport(ERROR, (errmsg( - "Placement for reference table \"%s\" on node %s:%d is not active. This should not be possible, please report this as a bug", - get_rel_name(shardInterval->relationId), nodeName, - nodePort))); - } - ereport(NOTICE, (errmsg("Replicating reference table \"%s\" to the node %s:%d", get_rel_name(shardInterval->relationId), nodeName, nodePort))); @@ -573,6 +557,18 @@ ReplicateAllReferenceTablesToNode(char *nodeName, int nodePort) List *shardIntervalList = LoadShardIntervalList(referenceTableId); ShardInterval *shardInterval = (ShardInterval *) linitial(shardIntervalList); + List *shardPlacementList = + ShardPlacementListIncludingOrphanedPlacements(shardInterval->shardId); + ShardPlacement *targetPlacement = + SearchShardPlacementInList(shardPlacementList, nodeName, nodePort); + if (targetPlacement != NULL && + targetPlacement->shardState == SHARD_STATE_ACTIVE) + { + /* We already have the shard, nothing to do */ + continue; + } + + referenceShardIntervalList = lappend(referenceShardIntervalList, shardInterval); }