Fix ConfigNode NPE when extend/reconstruct region targets a non-DataNode id#18075
Open
CRZbulabula wants to merge 2 commits into
Open
Fix ConfigNode NPE when extend/reconstruct region targets a non-DataNode id#18075CRZbulabula wants to merge 2 commits into
CRZbulabula wants to merge 2 commits into
Conversation
…-DataNode id When the target node id of `extend region` (or `reconstruct region`) does not belong to any registered DataNode -- for example it is a ConfigNode id or simply does not exist -- NodeManager.getRegisteredDataNode returns an empty TDataNodeConfiguration whose location is null. checkExtendRegion and checkReconstructRegion then dereferenced targetDataNode.getDataNodeId() unconditionally, throwing a NullPointerException in the ConfigNode RPC handler. The client only saw a misleading "Fail to connect to any config node" message. regionOperationCommonCheck already reports "Cannot find Target DataNode" for a null target, so reorder both checks to follow the safe checkMigrateRegion pattern: run regionOperationCommonCheck first and short-circuit before any targetDataNode dereference. The client now receives a clear, correct error. Add regression ITs for both the extend and reconstruct paths.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #18075 +/- ##
============================================
- Coverage 41.46% 41.46% -0.01%
Complexity 318 318
============================================
Files 5294 5294
Lines 371228 371238 +10
Branches 48036 48038 +2
============================================
- Hits 153941 153928 -13
- Misses 217287 217310 +23 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…-DN IT Address review feedback: instead of tolerating a null targetDataNode inside checkExtendRegion / checkReconstructRegion, detect the invalid target at the resolution layer. extendOneRegion and reconstructRegion now resolve the target via getRegisteredDataNodeLocationOrNull and, when the id is not a registered DataNode (a ConfigNode id or a non-existent id), immediately return "Target DataNode <id> does not exist in the cluster" -- mirroring the existing migrateRegion pattern -- so the check methods only ever receive a non-null target. The two check methods are restored to their original form. Also fix the flaky IoTDBRemoveDataNodeNormalIT.success1C5DRemoveTwoDataNodesUseSQL (added in #18046): it removed two randomly chosen DataNodes and asserted success, but if both hosted a replica of the same consensus group the ConfigNode correctly rejects the request ("Only one replica of the same consensus group is allowed to be migrated at the same time."). Add selectRemoveDataNodesWithoutRegionConflict, which picks DataNodes whose region sets are pairwise disjoint, and use it whenever more than one DataNode is removed. Verified locally: extendRegionToInvalidDataNodeTest, reconstructRegionToInvalidDataNodeTest and success1C5DRemoveTwoDataNodesUseSQL all pass.
|
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
Running
extend region <regionId> to <nodeId>(orreconstruct region <regionId> on <nodeId>) where<nodeId>does not belong to any registered DataNode — e.g. it is a ConfigNode id or simply a non-existent id like9999— crashes the ConfigNode RPC handler with aNullPointerException, and the client only sees a misleading error:ConfigNode log:
Root cause
NodeManager.getRegisteredDataNode(id)is backed byregisteredDataNodes.getOrDefault(id, new TDataNodeConfiguration()), so for an unregistered id it returns an emptyTDataNodeConfigurationwhoselocationisnull. InextendOneRegion/reconstructRegion:targetDataNodebecomesnull, andcheckExtendRegion/checkReconstructRegionthen dereferencetargetDataNode.getDataNodeId(), throwing the NPE out of the Thrift handler — which the client reports as the generic "Fail to connect to any config node".Fix
Detect the invalid target at the resolution layer, not inside the check methods.
extendOneRegionandreconstructRegionnow resolve the target through a smallgetRegisteredDataNodeLocationOrNullhelper and, when the id is not a registered DataNode, return immediately with a clear message:This mirrors the existing
migrateRegionpattern (which already resolves and validatesfromId/toIdup front), socheckExtendRegion/checkReconstructRegiononly ever receive a non-null target and are left in their original form.Tests
Added two regression integration tests asserting the operation is rejected cleanly and never surfaces a
NullPointerException:IoTDBRegionGroupExpandAndShrinkForIoTV1IT#extendRegionToInvalidDataNodeTestIoTDBRegionReconstructForIoTV1IT#reconstructRegionToInvalidDataNodeTest(
extend/remove regionwrap every region's status viaprocessExtendOrRemoveRegions, so the JDBC top-level message shows the aggregateTotal regions: 1, ..., failed to submit: 1and the concrete reason is carried in the per-region sub-status; the extend test asserts on the aggregate + absence of NPE, while the reconstruct test — which returns itsTSStatusdirectly — asserts the full "does not exist in the cluster" message.)Drive-by: fix a pre-existing flaky test
While validating CI I found
IoTDBRemoveDataNodeNormalIT.success1C5DRemoveTwoDataNodesUseSQL(added in #18046) is flaky, unrelated to this change. It removes two randomly chosen DataNodes and asserts success, but if both happen to host a replica of the same consensus group the ConfigNode correctly rejects the request:Added
IoTDBRemoveDataNodeUtils#selectRemoveDataNodesWithoutRegionConflict, which selects DataNodes whose region sets are pairwise disjoint, and use it whenever more than one DataNode is removed.All three tests pass locally.