diff --git a/src/backend/distributed/metadata/metadata_sync.c b/src/backend/distributed/metadata/metadata_sync.c index f73856169..8ae295f17 100644 --- a/src/backend/distributed/metadata/metadata_sync.c +++ b/src/backend/distributed/metadata/metadata_sync.c @@ -2962,7 +2962,7 @@ SyncNodeMetadataToNodesOptional(void) /* we fetch the same node again to check if it's synced or not */ WorkerNode *nodeUpdated = FindWorkerNode(workerNode->workerName, workerNode->workerPort); - if (!nodeUpdated->metadataSynced) + if (nodeUpdated == NULL || !nodeUpdated->metadataSynced) { /* set the result to FAILED to trigger the sync again */ result = NODE_METADATA_SYNC_FAILED_SYNC; diff --git a/src/backend/distributed/operations/worker_node_manager.c b/src/backend/distributed/operations/worker_node_manager.c index 8a4245ca0..219104042 100644 --- a/src/backend/distributed/operations/worker_node_manager.c +++ b/src/backend/distributed/operations/worker_node_manager.c @@ -110,7 +110,7 @@ ActiveReadableNodeCount(void) * NodeIsCoordinator returns true if the given node represents the coordinator. */ bool -NodeIsCoordinator(WorkerNode *node) +NodeIsCoordinator(const WorkerNode *node) { return node->groupId == COORDINATOR_GROUP_ID; } @@ -354,6 +354,9 @@ CompareWorkerNodes(const void *leftElement, const void *rightElement) * WorkerNodeCompare compares two worker nodes by their host name and port * number. Two nodes that only differ by their rack locations are considered to * be equal to each other. + * + * This function also makes sure that coordinator nodes are always considered + * lexicographically smaller than other worker nodes. */ int WorkerNodeCompare(const void *lhsKey, const void *rhsKey, Size keySize) @@ -361,6 +364,15 @@ WorkerNodeCompare(const void *lhsKey, const void *rhsKey, Size keySize) const WorkerNode *workerLhs = (const WorkerNode *) lhsKey; const WorkerNode *workerRhs = (const WorkerNode *) rhsKey; + if (NodeIsCoordinator(workerLhs)) + { + return -1; + } + if (NodeIsCoordinator(workerRhs)) + { + return 1; + } + return NodeNamePortCompare(workerLhs->workerName, workerRhs->workerName, workerLhs->workerPort, workerRhs->workerPort); } diff --git a/src/include/distributed/worker_manager.h b/src/include/distributed/worker_manager.h index 02a43fe0b..fa08f44c7 100644 --- a/src/include/distributed/worker_manager.h +++ b/src/include/distributed/worker_manager.h @@ -96,7 +96,7 @@ extern bool NodeIsPrimaryAndRemote(WorkerNode *worker); extern bool NodeIsPrimary(WorkerNode *worker); extern bool NodeIsSecondary(WorkerNode *worker); extern bool NodeIsReadable(WorkerNode *worker); -extern bool NodeIsCoordinator(WorkerNode *node); +extern bool NodeIsCoordinator(const WorkerNode *node); extern WorkerNode * SetWorkerColumn(WorkerNode *workerNode, int columnIndex, Datum value); extern WorkerNode * SetWorkerColumnOptional(WorkerNode *workerNode, int columnIndex, Datum value);