[Fix-18274][Registry] Handle expired JDBC heartbeat sessions - #18416
[Fix-18274][Registry] Handle expired JDBC heartbeat sessions#18416qiuyanjun888 wants to merge 5 commits into
Conversation
|
When This can happen after a long JVM pause or heartbeat scheduler starvation:
A missing heartbeat row is definitive evidence that the session has expired, not a transient database error. Continuing to run after that point can overlap with a server that has already taken over, leaving a split-brain window. Please handle this condition separately and transition directly to The new test sets the server state to |
Thanks for your suggestions! I have already implemented, can you please help review? |
|
Thanks for addressing the previous feedback. A zero-row heartbeat update now disconnects the server immediately, and the added test covers the However, there is still a shutdown race:
Previously, the exception handler inspected the current state, so |
|
Addressed the shutdown race described in #18416 (comment) in commit
Validation:
Could you please take another look? |
SbloodyS
left a comment
There was a problem hiding this comment.
There is still a shutdown race in the other state transitions.
close() and transitionToDisconnected() are synchronized, but the successful heartbeat and exception paths still update jdbcRegistryServerState directly:
SUSPENDED -> STARTEDafter a successful refreshSTARTED -> SUSPENDEDafter a refresh exception
For example:
- The heartbeat thread observes
SUSPENDED. close()changes the state toSTOPPED.- The heartbeat thread writes
STARTEDand invokesonReconnected().
The exception path can similarly overwrite STOPPED with SUSPENDED. Since the field is also neither volatile nor consistently accessed under the same lock, state visibility is not guaranteed.
Please make all state transitions atomic and use one synchronization strategy for every read/write, such as synchronized transition methods or an AtomicReference with compare-and-set. Connection callbacks should only run when their corresponding transition succeeds.
Please also add regression coverage for close() racing with:
- A successful heartbeat while the server is
SUSPENDED. - A heartbeat exception while the server is
STARTED.
In both cases, STOPPED must remain the final state and no reconnect/disconnect callback should be triggered after shutdown.
Was this PR generated or assisted by AI?
YES. This pull request was assisted by Hermes Agent / OpenAI Codex for code changes, focused tests, review feedback analysis, and local verification. The scope and final submission were directed by the contributor.
Purpose of the pull request
Closes #18274.
When the JDBC registry database is unavailable longer than the session timeout, another server can purge the stale heartbeat row. After recovery, the still-running client previously ignored the zero-row heartbeat update and incorrectly treated the refresh as successful.
This is an independent alternative related to #18275. It addresses the outstanding technical concerns discussed there by not recreating or upserting an expired heartbeat, which could revive a failed-over identity. Instead, a missing heartbeat enters the existing disconnect state machine so the owning service can terminate.
Brief change log
DISCONNECTED.Verify this pull request
This change added tests and can be verified as follows:
./mvnw clean -pl dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc -am -DskipITs -Dtest=JdbcRegistryServerTest,JdbcRegistryDataChangeListenerAdapterTest -Dsurefire.failIfNoSpecifiedTests=false testBUILD SUCCESSacross the selected reactor../mvnw -pl dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc spotless:applyPull Request Notice
Pull Request Notice
This pull request contains no incompatible change.