Fix StateMachineProcedure EOF state re-execution#18099
Open
Caideyipi wants to merge 4 commits into
Open
Conversation
jt2594838
reviewed
Jul 3, 2026
Comment on lines
+153
to
+156
| LOG.warn( | ||
| "StateMachineProcedure pid={} is scheduled with EOF state, skip execution: {}", | ||
| getProcId(), | ||
| this); |
Contributor
There was a problem hiding this comment.
i18n
DO NOT LET ME SAY IT AGAIN
Collaborator
Author
There was a problem hiding this comment.
Applied in 52632c4: moved the EOF-state error messages into the ConfigNode procedure i18n messages with both English and Chinese entries.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #18099 +/- ##
============================================
+ Coverage 41.53% 41.55% +0.02%
Complexity 318 318
============================================
Files 5296 5296
Lines 371679 371825 +146
Branches 48088 48107 +19
============================================
+ Hits 154360 154528 +168
+ Misses 217319 217297 -22 ☔ View full report in Codecov by Harness. 🚀 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.



Description
Problem
A ConfigNode may occasionally re-schedule a
StateMachineProcedurewhose internal state stack already points to the EOF sentinel after procedure recovery or leader-switch timing. In that casegetCurrentState()returnsnull.For pipe procedures such as
PipeHandleLeaderChangeProcedure, the next execution path can then pass that null state back into the state-machine framework or the concrete enum mapping. The observed production symptom is an NPE like:The procedure can roll back and the ConfigNode can continue starting, but this is still a framework robustness bug during recovery.
Root Cause
StateMachineProcedureuses an internal EOF sentinel to represent no-more-state. When the procedure is scheduled while the last state is EOF butstateFlowstill allows execution,getCurrentState()returnsnull.The framework previously did not guard this case at the beginning of
execute(). That allowed subclasses to receive a null state, even though theirgetStateId()implementations normally expect a real enum state and callordinal().Fix
This PR makes
StateMachineProcedure.execute()treat a null current state as an already-completed EOF state:stateFlowtoNO_MORE_STATE;executeFromState().This keeps EOF handling inside the state-machine framework instead of requiring every enum-based procedure subclass to be null-safe.
UT / IT Coverage Check
UT coverage is added in
STMProcedureTest:testEofStateReexecutionDoesNotCallExecuteFromStateconstructs the exact framework edge case by forcing the internal state stack to EOF whilestateFlowremainsHAS_MORE_STATE;doExecute()returns normally;executeFromState()is not called, so no enumordinal()path can receive a null state.Existing
PipeHandleLeaderChangeProcedureTestcontinues to cover serialization compatibility for the pipe leader-change procedure. The new UT targets the shared framework path, which is where the null state is produced.IT coverage was reviewed and not added for this PR. The reported production reproduction depends on a timing-sensitive ConfigNode startup / Ratis leader-election / pipe leader-change recovery race, which is not deterministic enough for an integration test. The deterministic failure condition is the framework EOF/null state, and the new unit test covers that condition directly. Cluster ITs would mainly duplicate startup orchestration without reliably asserting the root cause.
Validation
Passed locally:
Attempted but blocked locally before reaching ConfigNode tests:
This failed during dependency resolution because local/remote repositories did not provide required
2.0.11-SNAPSHOTreactor artifacts for the standalone ConfigNode module.This failed before reaching ConfigNode tests while compiling
iotdb-protocol/thrift-datanodegenerated sources becausejavax.annotationwas missing from the current local build environment.This PR has:
Key changed/added classes (or packages if there are too many classes) in this PR
org.apache.iotdb.confignode.procedure.impl.StateMachineProcedureorg.apache.iotdb.confignode.procedure.STMProcedureTest