From d9c1e992b20113c78871ab7e80145a84d70382db Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Tue, 24 Oct 2023 18:32:48 +0300 Subject: [PATCH] remove WorkerNodeListGetNodeWithGroupId --- .../rebalancer_placement_separation.c | 50 ++----------------- 1 file changed, 5 insertions(+), 45 deletions(-) diff --git a/src/backend/distributed/operations/rebalancer_placement_separation.c b/src/backend/distributed/operations/rebalancer_placement_separation.c index a4085005f..8ef6f882a 100644 --- a/src/backend/distributed/operations/rebalancer_placement_separation.c +++ b/src/backend/distributed/operations/rebalancer_placement_separation.c @@ -99,7 +99,6 @@ static bool TryAssignPlacementGroupToNodeGroup( /* other helpers */ static List * PlacementListGetUniqueNodeGroupIds(List *placementList); -static int WorkerNodeListGetNodeWithGroupId(List *workerNodeList, int32 nodeGroupId); /* @@ -222,7 +221,6 @@ TryAssignPlacementGroupsToNodeGroups(RebalancerPlacementSeparationContext *conte List *rebalancePlacementList, FmgrInfo *shardAllowedOnNodeUDF) { - List *availableWorkerList = list_copy(activeWorkerNodeList); List *unassignedPlacementList = NIL; /* @@ -239,23 +237,10 @@ TryAssignPlacementGroupsToNodeGroups(RebalancerPlacementSeparationContext *conte } int32 currentNodeGroupId = shardPlacement->groupId; - if (TryAssignPlacementGroupToNodeGroup(context, - currentNodeGroupId, - shardPlacement, - shardAllowedOnNodeUDF)) - { - /* - * TryAssignPlacementGroupToNodeGroup() succeeds for each worker node - * once, hence we must not have removed the worker node from the list - * yet, and WorkerNodeListGetNodeWithGroupId() ensures that already. - */ - int currentPlacementNodeIdx = - WorkerNodeListGetNodeWithGroupId(availableWorkerList, - currentNodeGroupId); - availableWorkerList = list_delete_nth_cell(availableWorkerList, - currentPlacementNodeIdx); - } - else + if (!TryAssignPlacementGroupToNodeGroup(context, + currentNodeGroupId, + shardPlacement, + shardAllowedOnNodeUDF)) { unassignedPlacementList = lappend(unassignedPlacementList, shardPlacement); @@ -274,7 +259,7 @@ TryAssignPlacementGroupsToNodeGroups(RebalancerPlacementSeparationContext *conte bool separated = false; WorkerNode *availableWorkerNode = NULL; - foreach_ptr(availableWorkerNode, availableWorkerList) + foreach_ptr(availableWorkerNode, activeWorkerNodeList) { if (TryAssignPlacementGroupToNodeGroup(context, availableWorkerNode->groupId, @@ -430,28 +415,3 @@ PlacementListGetUniqueNodeGroupIds(List *placementList) return placementListUniqueNodeGroupIds; } - - -/* - * WorkerNodeListGetNodeWithGroupId returns the index of worker node with given id - * in given worker node list. - * - * Throws an error if no such node is found. - */ -static int -WorkerNodeListGetNodeWithGroupId(List *workerNodeList, int32 nodeGroupId) -{ - int workerNodeIndex = 0; - WorkerNode *workerNode = NULL; - foreach_ptr(workerNode, workerNodeList) - { - if (workerNode->groupId == nodeGroupId) - { - return workerNodeIndex; - } - - workerNodeIndex++; - } - - ereport(ERROR, (errmsg("no such node is found"))); -}