Add AppendDistributedTablePlacementNodeList function

issue4237-2
naisila 2020-12-11 22:35:45 +03:00
parent 145112f3a0
commit 7e30e717ef
3 changed files with 32 additions and 1 deletions

View File

@ -166,7 +166,7 @@ master_create_empty_shard(PG_FUNCTION_ARGS)
uint64 shardId = GetNextShardId();
/* if enough live groups, add an extra candidate node as backup */
List *workerNodeList = DistributedTablePlacementNodeList(NoLock);
List *workerNodeList = AppendDistributedTablePlacementNodeList(NoLock);
if (list_length(workerNodeList) > ShardReplicationFactor)
{

View File

@ -499,6 +499,19 @@ DistributedTablePlacementNodeList(LOCKMODE lockMode)
}
/*
* AppendDistributedTablePlacementNodeList returns a list of all active, primary
* worker nodes that can store new data, i.e shouldstoreshards is 'true', and are
* not the coordinator
*/
List *
AppendDistributedTablePlacementNodeList(LOCKMODE lockMode)
{
EnsureModificationsCanRun();
return FilterActiveNodeListFunc(lockMode, NodeCanHaveAppendDistTablePlacements);
}
/*
* NodeCanHaveDistTablePlacements returns true if the given node can have
* shards of a distributed table.
@ -515,6 +528,22 @@ NodeCanHaveDistTablePlacements(WorkerNode *node)
}
/*
* NodeCanHaveAppendDistTablePlacements returns true if the given node can have
* shards of a distributed table, and is not the coordinator
*/
bool
NodeCanHaveAppendDistTablePlacements(WorkerNode *node)
{
if (!NodeIsPrimary(node))
{
return false;
}
return node->shouldHaveShards && (node->groupId != 0);
}
/*
* ActiveReadableNonCoordinatorNodeList returns a list of all nodes in workerNodeHash
* that are readable nodes This method excludes coordinator.

View File

@ -79,7 +79,9 @@ extern List * ReferenceTablePlacementNodeList(LOCKMODE lockMode);
extern WorkerNode * CoordinatorNodeIfAddedAsWorkerOrError(void);
extern void ErrorIfCoordinatorNotAddedAsWorkerNode(void);
extern List * DistributedTablePlacementNodeList(LOCKMODE lockMode);
extern List * AppendDistributedTablePlacementNodeList(LOCKMODE lockMode);
extern bool NodeCanHaveDistTablePlacements(WorkerNode *node);
extern bool NodeCanHaveAppendDistTablePlacements(WorkerNode *node);
extern uint32 ActiveReadableNonCoordinatorNodeCount(void);
extern List * ActiveReadableNonCoordinatorNodeList(void);
extern List * ActiveReadableNodeList(void);