You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by "jasondeng1997 (via GitHub)" <gi...@apache.org> on 2026/09/28 05:57:26 UTC

[PR] bugfix: dispatch ConsistentHashLoadBalance and LeastActiveLoadBalance… [incubator-seata-go]

jasondeng1997 opened a new pull request, #1205:
URL: https://github.com/apache/incubator-seata-go/pull/1205

   … in Select
   
   Select() only switched on RandomLoadBalance, XID and RoundRobinLoadBalance, so setting load-balance.type to ConsistentHashLoadBalance or LeastActiveLoadBalance fell through to the default branch and silently used random load balancing instead.
   
   Both strategies were already declared as constants and fully implemented, but the dispatch table was never extended for them. The existing unit tests call the strategy functions directly, which is why Select() was never exercised and the missing cases went unnoticed.
   
   Add the two missing cases and cover the dispatch table with regression tests that can tell each strategy apart from the random fallback:
   
   - ConsistentHashLoadBalance is checked through the hash circle it builds, which the random fallback never populates.
   - LeastActiveLoadBalance is checked by giving every session a distinct in-flight count, so only one session is a correct answer.
   
   <!--  Thanks for sending a pull request!
   -->
   <!-- Please make sure you have read and understood the contributing guidelines -->
   
   - [ ] I have registered the PR [changes](https://github.com/apache/incubator-seata-go/tree/master/changes).
   
   **What this PR does**:
   
   **Which issue(s) this PR fixes**:
   
   <!--
   *Automatically closes linked issue when PR is merged.
   Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
   _If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
   -->
   
   Fixes #
   
   **Special notes for your reviewer**:
   
   **Does this PR introduce a user-facing change?**:
   
   <!--
   If no, just write "NONE" in the release-note block below.
   If yes, a release note is required:
   Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
   -->
   
   ```release-note
   
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] bugfix: dispatch ConsistentHashLoadBalance and LeastActiveLoadBalance [incubator-seata-go]

Posted by "jasondeng1997 (via GitHub)" <gi...@apache.org>.
jasondeng1997 commented on code in PR #1205:
URL: https://github.com/apache/incubator-seata-go/pull/1205#discussion_r4139859331


##########
pkg/remoting/loadbalance/loadbalance.go:
##########
@@ -39,6 +39,10 @@ func Select(loadBalanceType string, sessions *sync.Map, xid string) connection.C
 		return XidLoadBalance(sessions, xid)
 	case roundRobinLoadBalance:
 		return RoundRobinLoadBalance(sessions, xid)
+	case consistentHashLoadBalance:
+		return ConsistentHashLoadBalance(sessions, xid)
+	case leastActiveLoadBalance:
+		return LeastActiveLoadBalance(sessions, xid)

Review Comment:
   fix https://github.com/apache/incubator-seata-go/issues/1073



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] bugfix: dispatch ConsistentHashLoadBalance and LeastActiveLoadBalance [incubator-seata-go]

Posted by "jasondeng1997 (via GitHub)" <gi...@apache.org>.
jasondeng1997 commented on PR #1205:
URL: https://github.com/apache/incubator-seata-go/pull/1205#issuecomment-5902133868

   Fixes https://github.com/apache/incubator-seata-go/issues/1073
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] bugfix: dispatch ConsistentHashLoadBalance and LeastActiveLoadBalance [incubator-seata-go]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #1205:
URL: https://github.com/apache/incubator-seata-go/pull/1205#issuecomment-5864385255

   ## [Codecov](https://app.codecov.io/gh/apache/incubator-seata-go/pull/1205?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 61.59%. Comparing base ([`7c162b6`](https://app.codecov.io/gh/apache/incubator-seata-go/commit/7c162b6a103c2f7a7e88aeb71d20e288469123e2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`4830565`](https://app.codecov.io/gh/apache/incubator-seata-go/commit/48305654274b6cdd5d412c79aace46008425bf0a?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #1205      +/-   ##
   ==========================================
   + Coverage   61.52%   61.59%   +0.07%     
   ==========================================
     Files         309      309              
     Lines       22625    22629       +4     
   ==========================================
   + Hits        13920    13939      +19     
   + Misses       7420     7409      -11     
   + Partials     1285     1281       -4     
   ```
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/incubator-seata-go/pull/1205?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] bugfix: dispatch ConsistentHashLoadBalance and LeastActiveLoadBalance [incubator-seata-go]

Posted by "Ethan-Xingyue (via GitHub)" <gi...@apache.org>.
Ethan-Xingyue commented on PR #1205:
URL: https://github.com/apache/incubator-seata-go/pull/1205#issuecomment-5885398944

   Thanks for addressing the feedback. I checked the new commit, and the fixes and regression tests look good. Keeping membership-change detection as a follow-up is fine.
   
   Please open the follow-up issue and link it here, and add `Fixes #1073` to the PR description. We can continue with this PR and close #1196 to avoid duplicate work.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] bugfix: dispatch ConsistentHashLoadBalance and LeastActiveLoadBalance [incubator-seata-go]

Posted by "thunguo (via GitHub)" <gi...@apache.org>.
thunguo merged PR #1205:
URL: https://github.com/apache/incubator-seata-go/pull/1205


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] bugfix: dispatch ConsistentHashLoadBalance and LeastActiveLoadBalance [incubator-seata-go]

Posted by "Ethan-Xingyue (via GitHub)" <gi...@apache.org>.
Ethan-Xingyue commented on code in PR #1205:
URL: https://github.com/apache/incubator-seata-go/pull/1205#discussion_r4122739468


##########
pkg/remoting/loadbalance/loadbalance.go:
##########
@@ -39,6 +39,10 @@ func Select(loadBalanceType string, sessions *sync.Map, xid string) connection.C
 		return XidLoadBalance(sessions, xid)
 	case roundRobinLoadBalance:
 		return RoundRobinLoadBalance(sessions, xid)
+	case consistentHashLoadBalance:
+		return ConsistentHashLoadBalance(sessions, xid)
+	case leastActiveLoadBalance:
+		return LeastActiveLoadBalance(sessions, xid)

Review Comment:
   This case makes `LeastActiveLoadBalance` reachable from the normal remoting path, so it may need a small concurrency-safety fix as part of this change.
   
   `GetActive()` currently performs a normal read of `Status.Active`, while `SendSync` / `SendAsync` update the field concurrently with `atomic.AddInt32`. A test that performs selection and counter updates concurrently is reported as a data race by `go test -race`.
   
   Could we use `atomic.LoadInt32` in `GetActive` and `GetTotal`, and add a regression test that updates the counters while least-active selection is running?



##########
pkg/remoting/loadbalance/loadbalance.go:
##########
@@ -39,6 +39,10 @@ func Select(loadBalanceType string, sessions *sync.Map, xid string) connection.C
 		return XidLoadBalance(sessions, xid)
 	case roundRobinLoadBalance:
 		return RoundRobinLoadBalance(sessions, xid)
+	case consistentHashLoadBalance:
+		return ConsistentHashLoadBalance(sessions, xid)

Review Comment:
   This case itself looks correct, but it makes an existing key-extraction issue visible in production.
   
   `SendSync` / `SendAsync` pass the complete `message.RpcMessage` to `selectSession` / `selectChannel` (`getty_remoting.go:53,71` and `grpc_remoting.go:52,71`), while `getXid` expects the concrete message body. Getty therefore obtains `"<invalid Value>"` and gRPC obtains an empty string, so different requests use the same hash key and may all be routed to one TC.
   
   Could we pass `msg.Body` to the selector, or unwrap `RpcMessage` inside `getXid`? When the message genuinely has no transaction key, a random key could be used as the fallback.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] bugfix: dispatch ConsistentHashLoadBalance and LeastActiveLoadBalance [incubator-seata-go]

Posted by "jasondeng1997 (via GitHub)" <gi...@apache.org>.
jasondeng1997 commented on code in PR #1205:
URL: https://github.com/apache/incubator-seata-go/pull/1205#discussion_r4129099421


##########
pkg/remoting/loadbalance/loadbalance.go:
##########
@@ -39,6 +39,10 @@ func Select(loadBalanceType string, sessions *sync.Map, xid string) connection.C
 		return XidLoadBalance(sessions, xid)
 	case roundRobinLoadBalance:
 		return RoundRobinLoadBalance(sessions, xid)
+	case consistentHashLoadBalance:
+		return ConsistentHashLoadBalance(sessions, xid)

Review Comment:
   Thanks for the detailed review — I verified all of it against the code and pushed the fixes in f543e33.
   Both blocking items, fixed in this PR:
   1. Constant key. Confirmed: SendSync / SendAsync passed the whole message.RpcMessage to
   selectSession / selectChannel, so getXid reflected over RpcMessage itself and returned the
   literal "<invalid Value>" for getty and "" for gRPC — every message hashed to one single key.
   The remoting layer now passes msg.Body; getXid additionally unwraps an RpcMessage
   defensively and guards the reflection fallback (nil body, missing or invalid field), so a message
   without a key yields "" instead of the placeholder string. ConsistentHashLoadBalance falls
   back to uuid.NewString() when there is no transaction key at all, as the Java client does.
   TestGetXidUnwrapsRpcMessage covers getty and gRPC.
   2. Counter race. Confirmed with -race: GetActive read Status.Active while
   BeginCount / EndCount wrote it through atomic.AddInt32. GetActive / GetTotal now use
   atomic.LoadInt32, and TestSelect_LeastActiveLoadBalance_ConcurrentWithCounters runs selection
   against concurrent BeginCount / EndCount.
   Non-blocking consistent-hash items — I took the two cheap ones here as well:
   - pick now wraps around to sortedHashNodes[0] instead of falling back to random.
   - an empty circle is rebuilt from the current snapshot, so a first selection that saw no sessions no
   longer degrades to random forever.
   The third one — rebuilding the ring when the snapshot membership changes, instead of only when a
   ringed connection closes — is a real gap, but doing it properly needs a membership comparison. I'd
   rather handle it as a follow-up and will open an issue unless you prefer it in this PR.
   On test quality: every new test fails without the fix. I verified by reverting each fix and
   re-running, including under -race: the concurrency test reports DATA RACE, the wrap-around and
   empty-circle tests fail on their assertions, and the keyless test sees only one distinct node.
   On duplication with #1196: it targets the same issue. As you noted there, its dispatcher tests
   still pass after removing the two new case lines, and it currently fails CI on gofmt; here the new
   tests do fail without those two lines and formatting is clean. I'm happy to close this in favour of
   #1196 if that is the preferred route — please let me know which PR you want to continue with.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] bugfix: dispatch ConsistentHashLoadBalance and LeastActiveLoadBalance [incubator-seata-go]

Posted by "jasondeng1997 (via GitHub)" <gi...@apache.org>.
jasondeng1997 commented on code in PR #1205:
URL: https://github.com/apache/incubator-seata-go/pull/1205#discussion_r4139859331


##########
pkg/remoting/loadbalance/loadbalance.go:
##########
@@ -39,6 +39,10 @@ func Select(loadBalanceType string, sessions *sync.Map, xid string) connection.C
 		return XidLoadBalance(sessions, xid)
 	case roundRobinLoadBalance:
 		return RoundRobinLoadBalance(sessions, xid)
+	case consistentHashLoadBalance:
+		return ConsistentHashLoadBalance(sessions, xid)
+	case leastActiveLoadBalance:
+		return LeastActiveLoadBalance(sessions, xid)

Review Comment:
   [https://github.com/apache/incubator-seata-go/issues/1073](url)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] bugfix: dispatch ConsistentHashLoadBalance and LeastActiveLoadBalance [incubator-seata-go]

Posted by "jasondeng1997 (via GitHub)" <gi...@apache.org>.
jasondeng1997 commented on PR #1205:
URL: https://github.com/apache/incubator-seata-go/pull/1205#issuecomment-5902894909

   done


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org