[ISSUE #432] add redress running connectors status - #433
Conversation
|
Can you describe what problem this PR solves? |
测试的时候发现Connector似乎也有这个问题,当发生负载均衡时,一个Running的Connector状态也会UNASSIGNED,因此想要纠正它的正确状态。 |
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
This PR modifies 2 file(s) with 65 lines of diff. No test changes detected — consider adding test coverage.
Automated review by github-manager-bot
| @@ -80,6 +80,7 @@ | |||
|
|
|||
There was a problem hiding this comment.
No test changes detected alongside source modifications. Consider adding tests to cover the changes.
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
PR received and logged for review. This PR requires detailed code review by a maintainer.
Diff size: 65 lines
Author: Slideee (CONTRIBUTOR)
Automated review by RockteMQ-AI
| } | ||
|
|
||
| private enum State { | ||
| public enum State { |
There was a problem hiding this comment.
The state field is not volatile, yet getState() is now called from the StateMachineService thread (in redressRunningConnectors()) while state is written from the connector's own thread (e.g., in doStart(), onFailure(), pause()). This is a data race under the Java Memory Model — reads may return stale values. The field should be declared volatile to guarantee cross-thread visibility.
| return state; | ||
| } | ||
|
|
||
| public void setState(State state) { |
There was a problem hiding this comment.
The public setState(State) setter is added but not used anywhere in this PR. Exposing a public unsynchronized setter on a non-volatile field expands the API surface and invites future callers to mutate connector state from arbitrary threads without any synchronization guarantee. If there is no current need, it should not be added; if needed, the field must be volatile and access should be constrained.
|
|
||
| public void maintainConnectorState() { | ||
|
|
||
| // STEP 1: redress running connectors status |
There was a problem hiding this comment.
redressRunningConnectors() is called every ~1 second from StateMachineService and unconditionally iterates all connectors, calling stateManagementService.get() for each one. For connectors that are already in RUNNING state (the common case), this produces unnecessary distributed status store reads on every tick. Consider an early-exit or only checking connectors that were recently started, similar to how the task-level redress is scoped to checkRunningTasks().
|
|
||
| public void maintainConnectorState() { | ||
|
|
||
| // STEP 1: redress running connectors status |
There was a problem hiding this comment.
No test coverage is provided for redressRunningConnectors(). The existing redressRunningStatus() for tasks also lacks tests. Given that this method modifies distributed connector state and interacts with stateManagementService, at minimum a unit test should verify: (1) UNASSIGNED + STARTED connector gets redressed to RUNNING, (2) already-RUNNING connectors are left alone, (3) connectors with non-STARTED target state are skipped.
|
|
||
| public void maintainConnectorState() { | ||
|
|
||
| // STEP 1: redress running connectors status |
There was a problem hiding this comment.
During cluster rebalancing, UNASSIGNED may be a legitimate transient state set by the leader before reassignment completes. This redress logic could race with the rebalance protocol by overwriting UNASSIGNED back to RUNNING on a worker that is about to lose ownership. The three-way check (UNASSIGNED status + STARTED target + STARTED local state) provides some protection, but if the local state transition to STOPPED hasn't propagated yet, a spurious RUNNING status could be published.
What is the purpose of the change
#432
Brief changelog
XX
Verifying this change
XXXX
Follow this checklist to help us incorporate your contribution quickly and easily. Notice,
it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR.[ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.mvn -B clean apache-rat:check findbugs:findbugs checkstyle:checkstyleto make sure basic checks pass. Runmvn clean install -DskipITsto make sure unit-test pass. Runmvn clean test-compile failsafe:integration-testto make sure integration-test pass.