Repository navigation
[Test] Stabilize the leader distribution assertions in IoTDBRegionGroupLeaderDistributionIT - #18981
Merged
CRZbulabula merged 1 commit intoOct 22, 2026
Conversation
testBasicLeaderDistribution sampled the RegionGroup leader distribution a single time, immediately after creating the DataRegionGroups. At that point the RegionGroups have only just been created: their leaders are still being elected and the leader balancer keeps migrating them, so the sample observes a transient state and the test fails with "expected:<3> but was:<2>" even though the cluster converges a moment later. The other two test methods in the same class did retry, but asserted a fixed number of leaders per DataNode (databaseNum / TEST_DATA_NODE_NUM). That count is not a state the leader balancer ever guarantees: it balances the RegionGroups of the system and audit databases too, which those assertions exclude from the count, and the number of RegionGroups is not necessarily divisible by the number of DataNodes. The assertions therefore could not converge and failed after all 50 retries. Poll the distribution through a shared helper and assert the property the balancer actually provides: every expected DataNode holds at least one RegionGroup leader and no two DataNodes differ by more than one leader. The same helper covers the post-shutdown and post-ReadOnly checks, and reports the observed distribution on timeout instead of a bare assertion error. This also matches the approach already used by IoTDBMultiDBRegionGroupLeaderDistributionIT.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
IoTDBRegionGroupLeaderDistributionITfails intermittently in the cluster IT suites. In one1C3D run all three of its test methods failed at once:
Root cause
Both problems are in the assertions, not in the balancer.
1.
testBasicLeaderDistributionsampled the distribution exactly once, immediately aftergetOrCreateDataPartitionTable. The RegionGroups have only just been created at that point, sothe leaders are still being elected and
RouteBalanceris still migrating them. From theConfigNode log of the failing run, while all three DataNodes were already
Running:The single sample therefore observed a transient state, and a moment later the distribution was
fine.
2.
testCFDWithUnknownStatusandtestCFDWithReadOnlyStatusdid retry (50 x 1s), butasserted a fixed per-DataNode leader count (
databaseNum / TEST_DATA_NODE_NUM, i.e. "exactly 2leaders each"). That is not a state the leader balancer guarantees:
out, so the counted subset is not the quantity being balanced;
In the observed run the cluster held 5 RegionGroups for 3 databases (4 DataRegionGroups + 1
SchemaRegionGroup); the Audit database owns the extra DataRegionGroup and the only
SchemaRegionGroup. Filtering the Audit database therefore leaves a subset whose even split is not
what the balancer optimizes, so the loop could not converge and failed only after the entire retry
budget.
Fix
countRegionLeadersand the waiting intoawaitBalancedLeaderDistribution, replacing four copies of the same sampling block.RegionGroup leader, and no two DataNodes differ by more than one leader. This is the invariant
IoTDBMultiDBRegionGroupLeaderDistributionITalready uses.AssertionError.TEST_DATA_NODE_NUM - 1, so it additionallyverifies that the leaders of the stopped DataNode really migrated: an unassigned leader keeps
the count of leader-holding DataNodes below the expected size, which a fixed per-node count
never checked.
For a converged cluster the behaviour is unchanged: 3 DataNodes holding 3 RegionGroups still has
to be 1/1/1.
Verification
mvn test-compile -pl integration-test -am -DskipTests -P with-integration-tests— BUILDSUCCESS (39 modules).
mvn spotless:apply -pl integration-test -P with-integration-tests— no diff.was being spent waiting for a state that cannot be reached, rather than timing out on a merely
slow balancer.