refactor assigning shardgroups in splits

feature/shardgroup
Nils Dijk 2023-12-01 12:43:32 +00:00
parent 2cc7f62de9
commit 22f8de88c8
No known key found for this signature in database
GPG Key ID: CA1177EF9434F241
1 changed files with 35 additions and 18 deletions

View File

@ -1050,8 +1050,33 @@ CreateSplitIntervalsForShardGroup(List *sourceColocatedShardIntervalList,
List *splitPointsForShard,
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;
foreach_ptr(shardToSplitInterval, sourceColocatedShardIntervalList)
{
@ -1059,26 +1084,18 @@ CreateSplitIntervalsForShardGroup(List *sourceColocatedShardIntervalList,
CreateSplitIntervalsForShard(shardToSplitInterval, splitPointsForShard,
&shardSplitIntervalList);
int shardcount = list_length(shardSplitIntervalList);
if (list_length(shardgroupIdsList) > 0)
if (list_length(shardgroupIdsList) != list_length(shardSplitIntervalList))
{
Assert(list_length(shardgroupIdsList) == shardcount);
for (int i = 0; i < shardcount; i++)
{
ShardInterval *shardInterval = list_nth(shardSplitIntervalList, i);
shardInterval->shardgroupId = *((ShardgroupID *) list_nth(
shardgroupIdsList, i));
}
/* developer error, but significant enough to stop code flow */
elog(ERROR, "length inconsisteny between shardgroup ids and shard intervals");
}
else
ShardgroupID *shardgroupID = NULL;
ShardInterval *shardInterval = NULL;
forboth_ptr(shardgroupID, shardgroupIdsList, shardInterval,
shardSplitIntervalList)
{
for (int i = 0; i < shardcount; i++)
{
ShardInterval *shardInterval = list_nth(shardSplitIntervalList, i);
shardInterval->shardgroupId = GetNextColocationId();
shardgroupIdsList = lappend(shardgroupIdsList,
(void *) &shardInterval->shardgroupId);
}
shardInterval->shardgroupId = *shardgroupID;
}
shardGroupSplitIntervalListList = lappend(shardGroupSplitIntervalListList,