Copy WorkerNode before returning in FindWorkerNode

pull/2822/head
Marco Slot 2019-07-05 09:35:53 +02:00
parent 99f18c55d9
commit 97334ff1ec
1 changed files with 10 additions and 4 deletions

View File

@ -764,7 +764,7 @@ get_shard_id_for_distribution_column(PG_FUNCTION_ARGS)
WorkerNode * WorkerNode *
FindWorkerNode(char *nodeName, int32 nodePort) FindWorkerNode(char *nodeName, int32 nodePort)
{ {
WorkerNode *workerNode = NULL; WorkerNode *cachedWorkerNode = NULL;
HTAB *workerNodeHash = GetWorkerNodeHash(); HTAB *workerNodeHash = GetWorkerNodeHash();
bool handleFound = false; bool handleFound = false;
void *hashKey = NULL; void *hashKey = NULL;
@ -774,10 +774,16 @@ FindWorkerNode(char *nodeName, int32 nodePort)
searchedNode->workerPort = nodePort; searchedNode->workerPort = nodePort;
hashKey = (void *) searchedNode; hashKey = (void *) searchedNode;
workerNode = (WorkerNode *) hash_search(workerNodeHash, hashKey, cachedWorkerNode = (WorkerNode *) hash_search(workerNodeHash, hashKey, HASH_FIND,
HASH_FIND, &handleFound); &handleFound);
if (handleFound)
{
WorkerNode *workerNode = (WorkerNode *) palloc(sizeof(WorkerNode));
memcpy(workerNode, cachedWorkerNode, sizeof(WorkerNode));
return workerNode;
}
return workerNode; return NULL;
} }