mirror of https://github.com/citusdata/citus.git
refactor assigning shardgroups in splits
parent
2cc7f62de9
commit
22f8de88c8
|
@ -1050,8 +1050,33 @@ CreateSplitIntervalsForShardGroup(List *sourceColocatedShardIntervalList,
|
||||||
List *splitPointsForShard,
|
List *splitPointsForShard,
|
||||||
List *shardgroupIdsList)
|
List *shardgroupIdsList)
|
||||||
{
|
{
|
||||||
List *shardGroupSplitIntervalListList = NIL;
|
if (list_length(sourceColocatedShardIntervalList) == 0)
|
||||||
|
{
|
||||||
|
/* should not happen, prevent consuming ShardgroupIDs if it does */
|
||||||
|
Assert(false);
|
||||||
|
return NIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (list_length(shardgroupIdsList) <= 0)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* If an empty shardgroupIdsList is passed we populate it here with newly
|
||||||
|
* generated shardgroupIds.
|
||||||
|
*
|
||||||
|
* Because Lists can not contain ShardgroupID as values we need them as
|
||||||
|
* pointers. To reduce the overhead we allocate an array that we populate and
|
||||||
|
* store pointers to the array elements in the list.
|
||||||
|
*/
|
||||||
|
int shardcount = list_length(splitPointsForShard) + 1;
|
||||||
|
ShardgroupID *shardgroupIDs = palloc0(sizeof(ShardgroupID) * shardcount);
|
||||||
|
for (int i = 0; i < shardcount; i++)
|
||||||
|
{
|
||||||
|
shardgroupIDs[i] = GetNextColocationId();
|
||||||
|
shardgroupIdsList = lappend(shardgroupIdsList, &shardgroupIDs[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List *shardGroupSplitIntervalListList = NIL;
|
||||||
ShardInterval *shardToSplitInterval = NULL;
|
ShardInterval *shardToSplitInterval = NULL;
|
||||||
foreach_ptr(shardToSplitInterval, sourceColocatedShardIntervalList)
|
foreach_ptr(shardToSplitInterval, sourceColocatedShardIntervalList)
|
||||||
{
|
{
|
||||||
|
@ -1059,26 +1084,18 @@ CreateSplitIntervalsForShardGroup(List *sourceColocatedShardIntervalList,
|
||||||
CreateSplitIntervalsForShard(shardToSplitInterval, splitPointsForShard,
|
CreateSplitIntervalsForShard(shardToSplitInterval, splitPointsForShard,
|
||||||
&shardSplitIntervalList);
|
&shardSplitIntervalList);
|
||||||
|
|
||||||
int shardcount = list_length(shardSplitIntervalList);
|
if (list_length(shardgroupIdsList) != list_length(shardSplitIntervalList))
|
||||||
if (list_length(shardgroupIdsList) > 0)
|
|
||||||
{
|
{
|
||||||
Assert(list_length(shardgroupIdsList) == shardcount);
|
/* developer error, but significant enough to stop code flow */
|
||||||
for (int i = 0; i < shardcount; i++)
|
elog(ERROR, "length inconsisteny between shardgroup ids and shard intervals");
|
||||||
{
|
|
||||||
ShardInterval *shardInterval = list_nth(shardSplitIntervalList, i);
|
|
||||||
shardInterval->shardgroupId = *((ShardgroupID *) list_nth(
|
|
||||||
shardgroupIdsList, i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
ShardgroupID *shardgroupID = NULL;
|
||||||
|
ShardInterval *shardInterval = NULL;
|
||||||
|
forboth_ptr(shardgroupID, shardgroupIdsList, shardInterval,
|
||||||
|
shardSplitIntervalList)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < shardcount; i++)
|
shardInterval->shardgroupId = *shardgroupID;
|
||||||
{
|
|
||||||
ShardInterval *shardInterval = list_nth(shardSplitIntervalList, i);
|
|
||||||
shardInterval->shardgroupId = GetNextColocationId();
|
|
||||||
shardgroupIdsList = lappend(shardgroupIdsList,
|
|
||||||
(void *) &shardInterval->shardgroupId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
shardGroupSplitIntervalListList = lappend(shardGroupSplitIntervalListList,
|
shardGroupSplitIntervalListList = lappend(shardGroupSplitIntervalListList,
|
||||||
|
|
Loading…
Reference in New Issue