Fix repeated RPC dispatch reusing a released FragmentInstanceContext (NPE)#17794
Open
JackieTien97 wants to merge 1 commit into
Open
Fix repeated RPC dispatch reusing a released FragmentInstanceContext (NPE)#17794JackieTien97 wants to merge 1 commit into
JackieTien97 wants to merge 1 commit into
Conversation
…(NPE) dispatchRemote retries the same FragmentInstance once after a TException. If the first delivery already executed and released its context (dataRegion == null) but the context is still cached in FragmentInstanceManager, the retry reused it and ran a fresh ALIVE driver on the released context, causing an NPE during init(). - Add REPEATED_RPC_CALL(723) status code (intentionally not retryable). - FragmentInstanceManager (data + schema paths): when instanceContext.computeIfAbsent would reuse an already-cached context for the same instanceId, reject the duplicated dispatch with REPEATED_RPC_CALL before the planning try block, so the first execution's cached resources are left untouched. - RegionReadExecutor: carry an IoTDBRuntimeException's status code back to the dispatcher so REPEATED_RPC_CALL is not downgraded to EXECUTE_STATEMENT_ERROR. - FragmentInstanceDispatcherImpl: skip the retry when the query has already timed out, failing fast with QUERY_TIMEOUT instead of re-dispatching. - ErrorHandlingUtils: map QueryTimeoutRuntimeException to QUERY_TIMEOUT. - Add RegionReadExecutorTest coverage for the status-code propagation.
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #17794 +/- ##
============================================
+ Coverage 40.78% 40.82% +0.04%
Complexity 2610 2610
============================================
Files 5184 5184
Lines 350861 351001 +140
Branches 44888 44900 +12
============================================
+ Hits 143082 143302 +220
+ Misses 207779 207699 -80 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
Per the root-cause analysis:
FragmentInstanceDispatcherImpl.dispatchRemoteretries the sameFragmentInstanceonce after aTException. ATExceptiononly means the client didn't receive the response — the server may have already executed the FI. After the first execution finishes it runsreleaseResource()(dataRegion = null) but itsFragmentInstanceContextstays cached inFragmentInstanceManager.instanceContext(~5 min) whileinstanceExecutionis removed. The retry hitsinstanceContext.computeIfAbsent, reuses the released context, and a fresh (ALIVE) driver dereferences the nulldataRegionininit()→ NPE. The single-execution guards don't help because this is cross-execution reuse.Changes
TSStatusCode: addREPEATED_RPC_CALL(723)(intentionally not inNEED_RETRY).FragmentInstanceManager(data + schema paths): wheninstanceContext.computeIfAbsentwould reuse an existing context for the sameinstanceId, throwIoTDBRuntimeException(REPEATED_RPC_CALL)before the planningtryblock — so it propagates up cleanly without invokingclearFIRelatedResources/createFailedInstanceInfoon the first execution's cached resources.RegionReadExecutor: in bothcatchblocks, carry anIoTDBRuntimeException's status code back soREPEATED_RPC_CALLreaches the dispatcher (instead of being downgraded toEXECUTE_STATEMENT_ERROR);needRetryHelperkeeps it non-retryable.FragmentInstanceDispatcherImpl: before retryingdispatchRemoteHelper, if the query has already timed out, fail fast with aQUERY_TIMEOUTstatus wrapped inFragmentInstanceDispatchExceptioninstead of re-dispatching.ErrorHandlingUtils: mapQueryTimeoutRuntimeExceptiontoQUERY_TIMEOUT.Test
RegionReadExecutorTest#testRepeatedRpcCallcovers both the consensus-read and VirtualDataRegion paths, asserting the response carriesREPEATED_RPC_CALLandreadNeedRetry == false.mvn test -pl iotdb-core/datanode -Dtest=RegionReadExecutorTest→ 6 passed.mvn compile -pl iotdb-core/datanode(incl. spotless:check) → BUILD SUCCESS.🤖 Generated with Claude Code