WorkergetLocalFirstCandidateNode only returns primaries

pull/1235/head
Brian Cloutier 2017-02-17 14:28:10 +03:00
parent 8260fcddbd
commit e39ac1821f
2 changed files with 7 additions and 7 deletions

View File

@ -39,6 +39,7 @@ int MaxWorkerNodesTracked = 2048; /* determines worker node hash table size *
/* Local functions forward declarations */ /* Local functions forward declarations */
static char * ClientHostAddress(StringInfo remoteHostStringInfo); static char * ClientHostAddress(StringInfo remoteHostStringInfo);
static WorkerNode * FindRandomNodeFromList(List *workerNodeList); static WorkerNode * FindRandomNodeFromList(List *workerNodeList);
static WorkerNode * WorkerGetNodeWithName(const char *hostname);
static bool OddNumber(uint32 number); static bool OddNumber(uint32 number);
static bool ListMember(List *currentList, WorkerNode *workerNode); static bool ListMember(List *currentList, WorkerNode *workerNode);
@ -52,8 +53,8 @@ static List * PrimaryNodesNotInList(List *currentList);
/* /*
* WorkerGetRandomCandidateNode takes in a list of worker nodes, and then allocates * WorkerGetRandomCandidateNode takes in a list of worker nodes, and then allocates
* a new worker node. The allocation is performed by randomly picking a worker node * a new worker node. The allocation is performed by randomly picking a primary worker
* which is not in currentNodeList. * node which is not in currentNodeList.
* *
* Note that the function returns null if the worker membership list does not * Note that the function returns null if the worker membership list does not
* contain enough nodes to allocate a new worker node. * contain enough nodes to allocate a new worker node.
@ -157,7 +158,7 @@ WorkerGetRoundRobinCandidateNode(List *workerNodeList, uint64 shardId,
/* /*
* WorkerGetLocalFirstCandidateNode takes in a list of worker nodes, and then * WorkerGetLocalFirstCandidateNode takes in a list of worker nodes, and then
* allocates a new worker node. The allocation is performed according to the * allocates a new primary worker node. The allocation is performed according to the
* following policy: if the list is empty, the node where the caller is connecting * following policy: if the list is empty, the node where the caller is connecting
* from is allocated; if the list is not empty, a node is allocated according * from is allocated; if the list is not empty, a node is allocated according
* to random policy. * to random policy.
@ -270,10 +271,10 @@ ClientHostAddress(StringInfo clientHostStringInfo)
/* /*
* WorkerGetNodeWithName finds and returns a node from the membership list that * WorkerGetNodeWithName finds and returns a primary node from the membership list that
* has the given hostname. The function returns null if no such node exists. * has the given hostname. The function returns null if no such node exists.
*/ */
WorkerNode * static WorkerNode *
WorkerGetNodeWithName(const char *hostname) WorkerGetNodeWithName(const char *hostname)
{ {
WorkerNode *workerNode = NULL; WorkerNode *workerNode = NULL;
@ -285,7 +286,7 @@ WorkerGetNodeWithName(const char *hostname)
while ((workerNode = hash_seq_search(&status)) != NULL) while ((workerNode = hash_seq_search(&status)) != NULL)
{ {
int nameCompare = strncmp(workerNode->workerName, hostname, WORKER_LENGTH); int nameCompare = strncmp(workerNode->workerName, hostname, WORKER_LENGTH);
if (nameCompare == 0) if (nameCompare == 0 && workerNode->nodeRole == NODE_ROLE_PRIMARY)
{ {
/* we need to terminate the scan since we break */ /* we need to terminate the scan since we break */
hash_seq_term(&status); hash_seq_term(&status);

View File

@ -58,7 +58,6 @@ extern WorkerNode * WorkerGetRoundRobinCandidateNode(List *workerNodeList,
uint64 shardId, uint64 shardId,
uint32 placementIndex); uint32 placementIndex);
extern WorkerNode * WorkerGetLocalFirstCandidateNode(List *currentNodeList); extern WorkerNode * WorkerGetLocalFirstCandidateNode(List *currentNodeList);
extern WorkerNode * WorkerGetNodeWithName(const char *hostname);
extern uint32 WorkerGetLiveNodeCount(void); extern uint32 WorkerGetLiveNodeCount(void);
extern List * WorkerNodeList(void); extern List * WorkerNodeList(void);
extern WorkerNode * FindWorkerNode(char *nodeName, int32 nodePort); extern WorkerNode * FindWorkerNode(char *nodeName, int32 nodePort);