Skip to content

[TDB-247] Wait for region leader election before region migration - #18699

Merged
CRZbulabula merged 2 commits into
apache:masterfrom
CRZbulabula:yongzao/fix-tdb-247
Sep 23, 2026
Merged

CRZbulabula merged 2 commits into
apache:masterfrom
CRZbulabula:yongzao/fix-tdb-247

Conversation

@CRZbulabula

@CRZbulabula CRZbulabula commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Description

After a ConfigNode leader switch, RemoveRegionPeerProcedure can resume before the Region leader cache has been rebuilt. RegionMaintainHandler consults that cache while selecting a replica and transferring a Ratis leader. A missing or explicitly unknown entry can otherwise cause a NullPointerException, terminating the procedure before region removal completes.

Centralize Region leader lookup in a helper that treats a missing or -1 entry as unknown, waits for the existing LoadManager.waitForRegionGroupReady leader-election and priority-update cycle, and then reads the cache again. If the leader is still unavailable after the wait, the helper retains the -1 fallback so the procedure can continue safely without dereferencing null. Both replica selection and Ratis leader transfer use this lookup.

Add regression coverage for DataRegions and SchemaRegions covering missing and unknown leaders, waiting and rereading the cache after election, avoiding an unnecessary wait for a known leader, successful transfer and cache updates, and a cache entry disappearing between lookups.

Validation

  • mvn -B -pl iotdb-core/confignode -Dtest=RegionMaintainHandlerTest,RegionMaintainHandlerConsensusPipeTest,RemoveRegionPeerProcedureTest,RegionMigrateProcedureTest -Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false test (28 tests passed)
  • mvn -B spotless:apply -pl iotdb-core/confignode
  • mvn -B test-compile -DskipTests -P with-zh-locale

Cluster failover integration testing was not run.

This PR has:

  • been self-reviewed.
  • added unit tests to cover the affected code paths.

Key changed/added classes

  • RegionMaintainHandler
  • RegionMaintainHandlerTest

@CRZbulabula CRZbulabula changed the title Fix region migration NPE after ConfigNode leader failover [TDB-247] Wait for region leader election before region migration Sep 22, 2026
@CRZbulabula
CRZbulabula merged commit 02ae00d into apache:master Sep 23, 2026
39 checks passed
@CRZbulabula
CRZbulabula deleted the yongzao/fix-tdb-247 branch September 23, 2026 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant