Round-robin over worker nodes for 0-shard router queries

pull/1835/head
Marco Slot 2017-11-27 16:47:58 +01:00
parent ae67fa0e52
commit 7ea718fd8d
1 changed files with 8 additions and 1 deletions

View File

@ -1629,6 +1629,8 @@ PlanRouterQuery(Query *originalQuery, RelationRestrictionContext *restrictionCon
List **placementList, uint64 *anchorShardId, List **relationShardList, List **placementList, uint64 *anchorShardId, List **relationShardList,
bool replacePrunedQueryWithDummy, bool *multiShardModifyQuery) bool replacePrunedQueryWithDummy, bool *multiShardModifyQuery)
{ {
static uint32 zeroShardQueryRoundRobin = 0;
bool isMultiShardQuery = false; bool isMultiShardQuery = false;
List *prunedRelationShardList = NIL; List *prunedRelationShardList = NIL;
DeferredErrorMessage *planningError = NULL; DeferredErrorMessage *planningError = NULL;
@ -1730,7 +1732,10 @@ PlanRouterQuery(Query *originalQuery, RelationRestrictionContext *restrictionCon
List *workerNodeList = ActiveReadableNodeList(); List *workerNodeList = ActiveReadableNodeList();
if (workerNodeList != NIL) 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 *dummyPlacement =
(ShardPlacement *) CitusMakeNode(ShardPlacement); (ShardPlacement *) CitusMakeNode(ShardPlacement);
dummyPlacement->nodeName = workerNode->workerName; dummyPlacement->nodeName = workerNode->workerName;
@ -1738,6 +1743,8 @@ PlanRouterQuery(Query *originalQuery, RelationRestrictionContext *restrictionCon
dummyPlacement->groupId = workerNode->groupId; dummyPlacement->groupId = workerNode->groupId;
workerList = lappend(workerList, dummyPlacement); workerList = lappend(workerList, dummyPlacement);
zeroShardQueryRoundRobin++;
} }
} }
else else