From 5ae2d03881e6397536bf9791d0a2e6729eabdd7c Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Mon, 26 Nov 2018 10:23:08 +0100 Subject: [PATCH] Refrain from having a strong opinion on maxGroupId. When initializing a Citus formation automatically from an external piece of software such as Citus-HA, the following process process may be used: - decide on the groupId in the external software - SELECT * FROM master_add_inactive_node('localhost', 9701, groupid => X) When Citus checks for maxGroupId, it forbids other software to pick their own group Ids to ues with the master_add_inactive_node() API. This patch removes the extra testing around maxGroupId. --- src/backend/distributed/utils/node_metadata.c | 38 ------------------- 1 file changed, 38 deletions(-) diff --git a/src/backend/distributed/utils/node_metadata.c b/src/backend/distributed/utils/node_metadata.c index 1272245ee..8d41966ff 100644 --- a/src/backend/distributed/utils/node_metadata.c +++ b/src/backend/distributed/utils/node_metadata.c @@ -62,7 +62,6 @@ static void SetNodeState(char *nodeName, int32 nodePort, bool isActive); static HeapTuple GetNodeTuple(char *nodeName, int32 nodePort); static Datum GenerateNodeTuple(WorkerNode *workerNode); static int32 GetNextGroupId(void); -static uint32 GetMaxGroupId(void); static int GetNextNodeId(void); static void InsertNodeRow(int nodeid, char *nodename, int32 nodeport, uint32 groupId, char *nodeRack, bool hasMetadata, bool isActive, Oid nodeRole, @@ -965,15 +964,6 @@ AddNodeMetadata(char *nodeName, int32 nodePort, int32 groupId, char *nodeRack, { groupId = GetNextGroupId(); } - else - { - uint32 maxGroupId = GetMaxGroupId(); - - if (groupId > maxGroupId) - { - ereport(ERROR, (errmsg("you cannot add a node to a non-existing group"))); - } - } /* if nodeRole hasn't been added yet there's a constraint for one-node-per-group */ if (nodeRole != InvalidOid && nodeRole == PrimaryNodeRoleId()) @@ -1182,34 +1172,6 @@ GetNextGroupId() } -/* - * GetMaxGroupId iterates over the worker node hash, and returns the maximum - * group id from the table. - */ -static uint32 -GetMaxGroupId() -{ - uint32 maxGroupId = 0; - WorkerNode *workerNode = NULL; - HTAB *workerNodeHash = GetWorkerNodeHash(); - HASH_SEQ_STATUS status; - - hash_seq_init(&status, workerNodeHash); - - while ((workerNode = hash_seq_search(&status)) != NULL) - { - uint32 workerNodeGroupId = workerNode->groupId; - - if (workerNodeGroupId > maxGroupId) - { - maxGroupId = workerNodeGroupId; - } - } - - return maxGroupId; -} - - /* * GetNextNodeId allocates and returns a unique nodeId for the node * to be added. This allocation occurs both in shared memory and in write