You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "CRZbulabula (via GitHub)" <gi...@apache.org> on 2026/05/19 01:47:27 UTC

[PR] Balance per-database replicas in PGP and Greedy region allocators [iotdb]

CRZbulabula opened a new pull request, #17714:
URL: https://github.com/apache/iotdb/pull/17714

   ## Summary
   
   `PartiteGraphPlacementRegionGroupAllocator` ignored its `databaseAllocatedRegionGroups` argument, so PGP balanced only the global per-DataNode region count and let one DataNode hold many replicas of one database while holding few of another. On a 20-DataNode / 2-database cluster with 60 DataRegion groups per database (replication factor 3), this could leave DN-16 with 15 replicas of `tod_sod0` but only 3 of `usr_sod0`. That imbalance bled into the leader balancer: per-(database, DataNode) leader counts that should have been a flat 3 ranged from 2 to 4, with one DataNode holding 8 leaders total.
   
   This PR makes both PGP and the Greedy fallback aware of the per-database load.
   
   ## Approach
   
   Comparison priority (smaller is better) for both allocators:
   
   1. **`regionSum`** &mdash; total per-DataNode region count (global balance)
   2. **`databaseRegionSum`** &mdash; per-(database, DataNode) region count (new)
   3. **`edgeSum`** &mdash; 2-region scatter (PGP only)
   
   PGP's partite-graph structure already provides the high-scatter property by construction, so demoting `edgeSum` to the tertiary key does not regress scatter width.
   
   ### PartiteGraphPlacementRegionGroupAllocator
   
   - `prepare()` now consumes `databaseAllocatedRegionGroups` and builds a `databaseRegionCounter[]` parallel to `regionCounter[]`.
   - `valuation()` returns a `Value(regionSum, databaseRegionSum, edgeSum)` triple; `subGraphSearch` and `partiteGraphSearch` compare via `Value.compareTo`.
   - The sub-graph pre-sort uses a new internal `PgpDataNodeEntry` ordered by `(regionCount, databaseRegionCount, freeDiskSpace, random)` so the fixed alpha slots also honour per-database balance.
   
   ### GreedyRegionGroupAllocator
   
   - `DataNodeEntry` gains a `databaseRegionCount` field; `compareTo` orders by `(regionCount, databaseRegionCount, freeDiskSpace, random)`.
   - `buildWeightList` accepts and accumulates `databaseAllocatedRegionGroups`.
   
   ### IT framework
   
   `CommonConfig` (and the `Mpp` / `Shared` / `Remote` implementations) gains `setRegionGroupAllocatePolicy(String)` so integration tests can switch between PGR / GCR / GREEDY.
   
   ## Test plan
   
   - [x] `mvn test -pl iotdb-core/confignode -Dtest='*RegionGroupAllocator*Test'` &mdash; 9 unit tests pass.
   - [x] New `PartiteGraphPlacementRegionGroupAllocatorTest` covers replication factor 2 / 3 / 5 multi-database scenarios. The 20-DN / 2-db / rf-3 regression now distributes each database's 60 region groups as exactly 9 replicas per DataNode (max &minus; min = 0).
   - [x] New per-database balance test in `GreedyRegionGroupAllocatorTest`.
   - [x] `mvn verify -DskipUTs -Dit.test='IoTDBPerDatabaseRegionGroupAllocationIT#testPgrPolicyPerDbReplicaBalance' -PClusterIT -P with-integration-tests` &mdash; PGR end-to-end IT passes on a 1C4D cluster.
   - [x] Same IT also passes for `GCR` policy.
   - [x] `mvn spotless:apply` &mdash; clean.
   
   ## Out of scope / follow-ups
   
   - This PR only affects new region group allocation. Pre-existing region groups are not rebalanced. The follow-up to rebalance an existing cluster would need a separate migration tool and is not addressed here.
   - The leader balancer's separate-balancing-per-region-type behaviour (which also contributes to combined imbalance) is unchanged in this PR.


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Balance per-database replicas in PGP and Greedy region allocators [iotdb]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17714:
URL: https://github.com/apache/iotdb/pull/17714#issuecomment-4484725915

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17714) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [4 New issues](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17714&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17714&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_iotdb&pullRequest=17714&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_iotdb&pullRequest=17714&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_iotdb&pullRequest=17714&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17714)
   
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Balance per-database replicas in PGP and Greedy region allocators [iotdb]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #17714:
URL: https://github.com/apache/iotdb/pull/17714#issuecomment-4484905763

   ## [Codecov](https://app.codecov.io/gh/apache/iotdb/pull/17714?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `56.57895%` with `33 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 40.42%. Comparing base ([`4ac0b7e`](https://app.codecov.io/gh/apache/iotdb/commit/4ac0b7ee029587d7a6f3393dcac24ca53fc0b7c3?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`5d390f2`](https://app.codecov.io/gh/apache/iotdb/commit/5d390f22a49d63cdf3c554756d520a54377f852e?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 6 commits behind head on master.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/iotdb/pull/17714?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...ion/PartiteGraphPlacementRegionGroupAllocator.java](https://app.codecov.io/gh/apache/iotdb/pull/17714?src=pr&el=tree&filepath=iotdb-core%2Fconfignode%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fiotdb%2Fconfignode%2Fmanager%2Fload%2Fbalancer%2Fregion%2FPartiteGraphPlacementRegionGroupAllocator.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aW90ZGItY29yZS9jb25maWdub2RlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9pb3RkYi9jb25maWdub2RlL21hbmFnZXIvbG9hZC9iYWxhbmNlci9yZWdpb24vUGFydGl0ZUdyYXBoUGxhY2VtZW50UmVnaW9uR3JvdXBBbGxvY2F0b3IuamF2YQ==) | 43.85% | [32 Missing :warning: ](https://app.codecov.io/gh/apache/iotdb/pull/17714?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...ad/balancer/region/GreedyRegionGroupAllocator.java](https://app.codecov.io/gh/apache/iotdb/pull/17714?src=pr&el=tree&filepath=iotdb-core%2Fconfignode%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fiotdb%2Fconfignode%2Fmanager%2Fload%2Fbalancer%2Fregion%2FGreedyRegionGroupAllocator.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aW90ZGItY29yZS9jb25maWdub2RlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9pb3RkYi9jb25maWdub2RlL21hbmFnZXIvbG9hZC9iYWxhbmNlci9yZWdpb24vR3JlZWR5UmVnaW9uR3JvdXBBbGxvY2F0b3IuamF2YQ==) | 94.44% | [1 Missing :warning: ](https://app.codecov.io/gh/apache/iotdb/pull/17714?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #17714      +/-   ##
   ============================================
   + Coverage     40.39%   40.42%   +0.02%     
   + Complexity     2575     2574       -1     
   ============================================
     Files          5179     5179              
     Lines        349659   349756      +97     
     Branches      44688    44712      +24     
   ============================================
   + Hits         141251   141380     +129     
   + Misses       208408   208376      -32     
   ```
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/iotdb/pull/17714?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   </details>


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Balance per-database replicas in PGP and Greedy region allocators [iotdb]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17714:
URL: https://github.com/apache/iotdb/pull/17714#issuecomment-4483772848

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17714) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [4 New issues](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17714&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17714&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_iotdb&pullRequest=17714&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_iotdb&pullRequest=17714&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_iotdb&pullRequest=17714&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17714)
   
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Balance per-database replicas in PGP and Greedy region allocators [iotdb]

Posted by "CRZbulabula (via GitHub)" <gi...@apache.org>.
CRZbulabula merged PR #17714:
URL: https://github.com/apache/iotdb/pull/17714


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org