diff options
author | Tomas Vondra | 2017-06-11 13:30:59 +0000 |
---|---|---|
committer | Tomas Vondra | 2017-06-17 21:28:49 +0000 |
commit | 1d14325822e41fee5edc529ee8776a1dd22bda06 (patch) | |
tree | e1b4e6877da41563ae57a6d55b8b0a6407afe9d2 | |
parent | 93656ace7562bf6892764d314311c802fbfdc34f (diff) |
Randomize the choice of the initial ROUNDROBIN node
With roundrobin node, the initial node was always set to the first node
in the list. That works fine when inserting many rows at once (e.g. with
INSERT SELECT), but with single-row inserts this puts all data on the
first node, resulting in unbalanced distribution.
This randomizes the choice of the initial node, so that with single-row
inserts the ROUNDROBIN behaves a bit like RANDOM distribution.
This also removes unnecessary srand() call from RelationBuildLocator(),
located after a call to rand().
-rw-r--r-- | src/backend/pgxc/locator/locator.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/backend/pgxc/locator/locator.c b/src/backend/pgxc/locator/locator.c index 2c8aa676ae..4c7772f07d 100644 --- a/src/backend/pgxc/locator/locator.c +++ b/src/backend/pgxc/locator/locator.c @@ -577,7 +577,6 @@ RelationBuildLocator(Relation rel) */ offset = compute_modulo(abs(rand()), list_length(relationLocInfo->rl_nodeList)); - srand(time(NULL)); relationLocInfo->roundRobinNode = relationLocInfo->rl_nodeList->head; /* initialize */ for (j = 0; j < offset && relationLocInfo->roundRobinNode->next != NULL; j++) relationLocInfo->roundRobinNode = relationLocInfo->roundRobinNode->next; @@ -907,7 +906,8 @@ createLocator(char locatorType, RelationAccessType accessType, Assert(false); break; } - locator->roundRobinNode = -1; + /* randomize choice of the initial node */ + locator->roundRobinNode = (abs(rand()) % locator->nodeCount) - 1; } else { |