From 7ea718fd8d7621f3a21d39aa8920fb3e93a5a0e3 Mon Sep 17 00:00:00 2001 From: Marco Slot Date: Mon, 27 Nov 2017 16:47:58 +0100 Subject: [PATCH] Round-robin over worker nodes for 0-shard router queries --- src/backend/distributed/planner/multi_router_planner.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/backend/distributed/planner/multi_router_planner.c b/src/backend/distributed/planner/multi_router_planner.c index 743bc98d7..d4fb9304d 100644 --- a/src/backend/distributed/planner/multi_router_planner.c +++ b/src/backend/distributed/planner/multi_router_planner.c @@ -1629,6 +1629,8 @@ PlanRouterQuery(Query *originalQuery, RelationRestrictionContext *restrictionCon List **placementList, uint64 *anchorShardId, List **relationShardList, bool replacePrunedQueryWithDummy, bool *multiShardModifyQuery) { + static uint32 zeroShardQueryRoundRobin = 0; + bool isMultiShardQuery = false; List *prunedRelationShardList = NIL; DeferredErrorMessage *planningError = NULL; @@ -1730,7 +1732,10 @@ PlanRouterQuery(Query *originalQuery, RelationRestrictionContext *restrictionCon List *workerNodeList = ActiveReadableNodeList(); if (workerNodeList != NIL) { - WorkerNode *workerNode = (WorkerNode *) linitial(workerNodeList); + int workerNodeCount = list_length(workerNodeList); + int workerNodeIndex = zeroShardQueryRoundRobin % workerNodeCount; + WorkerNode *workerNode = (WorkerNode *) list_nth(workerNodeList, + workerNodeIndex); ShardPlacement *dummyPlacement = (ShardPlacement *) CitusMakeNode(ShardPlacement); dummyPlacement->nodeName = workerNode->workerName; @@ -1738,6 +1743,8 @@ PlanRouterQuery(Query *originalQuery, RelationRestrictionContext *restrictionCon dummyPlacement->groupId = workerNode->groupId; workerList = lappend(workerList, dummyPlacement); + + zeroShardQueryRoundRobin++; } } else