Copilot commented on code in PR #18692:
URL: https://github.com/apache/iotdb/pull/18692#discussion_r4078289535
##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionManager.java:
##########
@@ -645,16 +651,62 @@ private TSStatus extendRegionGroupIfNecessary(
return result;
}
+ private TSStatus proactiveExtendRegionGroupIfNecessary(
+ final Map<String, ? extends Collection<TSeriesPartitionSlot>>
unassignedPartitionSlotsMap,
+ final TConsensusGroupType consensusGroupType)
+ throws DatabaseNotExistsException, NotEnoughDataNodeException {
+ final Map<String, Integer> allotmentMap = new HashMap<>();
+ for (Map.Entry<String, ? extends Collection<TSeriesPartitionSlot>> entry :
+ unassignedPartitionSlotsMap.entrySet()) {
+ final String database = entry.getKey();
+ final int maxRegionGroupCount =
+ getClusterSchemaManager().getMaxRegionGroupNum(database,
consensusGroupType);
+ final int minRegionGroupCount =
+ getClusterSchemaManager().getMinRegionGroupNum(database,
consensusGroupType);
+ final int allocatedRegionGroupCount =
+ partitionInfo.getRegionGroupCount(database, consensusGroupType);
+ // As with AUTO, grow toward the minimum by at most the number of
pending series slots.
+ // An existing data slot with new time partitions also contributes to
this incremental growth.
+ final int minimumRegionGroupTarget =
+ Math.min(
+ minRegionGroupCount,
+ allocatedRegionGroupCount + new
HashSet<>(entry.getValue()).size());
+ final int targetRegionGroupCount =
+ Math.min(
+ maxRegionGroupCount,
+ Math.max(
+ minimumRegionGroupTarget,
+ partitionInfo.getSeriesPartitionSlotsCount(
+ database, consensusGroupType, entry.getValue())));
+ // Also allocate one group per active series slot, up to the same
maximum as AUTO.
+ // Existing groups are retained when the maximum decreases or the policy
changes.
+ if (allocatedRegionGroupCount < targetRegionGroupCount) {
+ allotmentMap.put(database, targetRegionGroupCount -
allocatedRegionGroupCount);
+ } else if (!entry.getValue().isEmpty()
+ && allocatedRegionGroupCount > 0
+ && allocatedRegionGroupCount < maxRegionGroupCount
+ && partitionInfo.getAllRegionGroupIds(database,
consensusGroupType).stream()
+ .allMatch(
+ regionGroupId ->
+ RegionGroupStatus.Disabled.equals(
+
getLoadManager().getRegionGroupStatus(regionGroupId)))) {
Review Comment:
`LoadCache.getRegionGroupStatus` returns `Disabled` when a region has no
cache yet (LoadCache.java:663-672). This `allMatch` therefore treats every
persisted group as disabled during startup or leader recovery before heartbeat
caches are rebuilt, so each pending partition request can allocate another
replacement until the database maximum is reached even when the groups are
healthy. Distinguish an unknown status from explicitly disabled, or reuse the
existing cache-based disabled-group filtering used by AUTO.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]