Skip to content

Commit

Permalink
Stabilize single_node.sql and others that report illegal node removal (
Browse files Browse the repository at this point in the history
  • Loading branch information
onurctirtir authored Mar 8, 2023
1 parent d82c11f commit e3cf7ac
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/backend/distributed/metadata/node_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -1918,6 +1918,10 @@ ErrorIfNodeContainsNonRemovablePlacements(WorkerNode *workerNode)
{
int32 groupId = workerNode->groupId;
List *shardPlacements = AllShardPlacementsOnNodeGroup(groupId);

/* sort the list to prevent regression tests getting flaky */
shardPlacements = SortList(shardPlacements, CompareGroupShardPlacements);

GroupShardPlacement *placement = NULL;
foreach_ptr(placement, shardPlacements)
{
Expand Down
32 changes: 30 additions & 2 deletions src/backend/distributed/planner/multi_physical_planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -5343,8 +5343,7 @@ ActiveShardPlacementLists(List *taskList)


/*
* CompareShardPlacements compares two shard placements by their tuple oid; this
* oid reflects the tuple's insertion order into pg_dist_placement.
* CompareShardPlacements compares two shard placements by placement id.
*/
int
CompareShardPlacements(const void *leftElement, const void *rightElement)
Expand All @@ -5370,6 +5369,35 @@ CompareShardPlacements(const void *leftElement, const void *rightElement)
}


/*
* CompareGroupShardPlacements compares two group shard placements by placement id.
*/
int
CompareGroupShardPlacements(const void *leftElement, const void *rightElement)
{
const GroupShardPlacement *leftPlacement =
*((const GroupShardPlacement **) leftElement);
const GroupShardPlacement *rightPlacement =
*((const GroupShardPlacement **) rightElement);

uint64 leftPlacementId = leftPlacement->placementId;
uint64 rightPlacementId = rightPlacement->placementId;

if (leftPlacementId < rightPlacementId)
{
return -1;
}
else if (leftPlacementId > rightPlacementId)
{
return 1;
}
else
{
return 0;
}
}


/*
* LeftRotateList returns a copy of the given list that has been cyclically
* shifted to the left by the given rotation count. For this, the function
Expand Down
1 change: 1 addition & 0 deletions src/include/distributed/multi_physical_planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ extern bool BinaryOpExpression(Expr *clause, Node **leftOperand, Node **rightOpe
/* helper functions */
extern Var * MakeInt4Column(void);
extern int CompareShardPlacements(const void *leftElement, const void *rightElement);
extern int CompareGroupShardPlacements(const void *leftElement, const void *rightElement);
extern bool ShardIntervalsOverlap(ShardInterval *firstInterval,
ShardInterval *secondInterval);
extern bool ShardIntervalsOverlapWithParams(Datum firstMin, Datum firstMax,
Expand Down

0 comments on commit e3cf7ac

Please sign in to comment.