private TSStatus customExtendRegionGroupIfNecessary(
      final Map<String, Integer> unassignedPartitionSlotsCountMap,
      final TConsensusGroupType consensusGroupType)
      throws DatabaseNotExistsException, NotEnoughDataNodeException {

    // Map<Database, Region allotment>
    final Map<String, Integer> allotmentMap = new ConcurrentHashMap<>();

    for (final Map.Entry<String, Integer> entry : unassignedPartitionSlotsCountMap.entrySet()) {
      final String database = entry.getKey();
      final int minRegionGroupNum =
          getClusterSchemaManager().getMinRegionGroupNum(database, consensusGroupType);
      final int allocatedRegionGroupCount =
          partitionInfo.getRegionGroupCount(database, consensusGroupType);

      // Extend RegionGroups until allocatedRegionGroupCount == minRegionGroupNum
      if (allocatedRegionGroupCount < minRegionGroupNum) {
        allotmentMap.put(database, minRegionGroupNum - allocatedRegionGroupCount);
      }
    }

    return generateAndAllocateRegionGroups(allotmentMap, consensusGroupType);
  }
Allocate more RegionGroup to the specified StorageGroups if necessary.

@param unassignedPartitionSlotsCountMap Map<StorageGroup, unassigned Partition count>
@param consensusGroupType SchemaRegion or DataRegion
@return SUCCESS_STATUS when RegionGroup extension successful; NOT_ENOUGH_DATA_NODE when there
    are not enough DataNodes; STORAGE_GROUP_NOT_EXIST when some StorageGroups don't exist
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionManager.java