private TSStatus extendRegionGroupIfNecessary(
      final Map<String, Integer> unassignedPartitionSlotsCountMap,
      final TConsensusGroupType consensusGroupType) {

    final TSStatus result = new TSStatus();

    try {
      if (TConsensusGroupType.SchemaRegion.equals(consensusGroupType)) {
        switch (SCHEMA_REGION_GROUP_EXTENSION_POLICY) {
          case CUSTOM:
            return customExtendRegionGroupIfNecessary(
                unassignedPartitionSlotsCountMap, consensusGroupType);
          case AUTO:
          default:
            return autoExtendRegionGroupIfNecessary(
                unassignedPartitionSlotsCountMap, consensusGroupType);
        }
      } else {
        switch (DATA_REGION_GROUP_EXTENSION_POLICY) {
          case CUSTOM:
            return customExtendRegionGroupIfNecessary(
                unassignedPartitionSlotsCountMap, consensusGroupType);
          case AUTO:
          default:
            return autoExtendRegionGroupIfNecessary(
                unassignedPartitionSlotsCountMap, consensusGroupType);
        }
      }
    } catch (NotEnoughDataNodeException e) {
      LOGGER.error("Extend region group failed", e);
      result.setCode(TSStatusCode.NO_ENOUGH_DATANODE.getStatusCode());
      result.setMessage(e.getMessage());
    } catch (DatabaseNotExistsException e) {
      LOGGER.error("Extend region group failed", e);
      result.setCode(TSStatusCode.DATABASE_NOT_EXIST.getStatusCode());
      result.setMessage(e.getMessage());
    }

    return result;
  }
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