Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Sumit6307
Copy link
Contributor

What's changed

  • Remove RouteTable.refreshLeader() and RouteTable.selectLeader() from GET /metadata/v1/cluster in ClusterController.
  • Use only RaftStateMachine.getRaftLeaderMetadata() for cluster metadata (leader, followers, learners, term).
  • Remove unused PeerId import.

Why

The cluster endpoint already builds the response from RaftStateMachine.getRaftLeaderMetadata(). The refreshLeader/selectLeader calls only checked "is there a leader?" via JRaft's RouteTable, duplicating info we already have. Removing them:

  • Drops the extra JRaft round-trip on every /cluster call
  • Keeps the same MetadataResponse shape and semantics
  • Leaves changeCluster unchanged (still uses RouteTable for changePeers/updateConfiguration)

Testing

  • ClusterControllerTest (run mvn test -pl server -Dtest=ClusterControllerTest)
  • No changes to RaftRegistryServiceImpl or other callers; response contract unchanged.

fix #7967

…er cluster endpoint

- Remove RouteTable.refreshLeader/selectLeader calls in GET /metadata/v1/cluster
- Use RaftStateMachine.getRaftLeaderMetadata() only for cluster metadata
- Removes redundant JRaft round-trip; response shape and semantics unchanged
- Remove unused PeerId import
@codecov
Copy link

codecov bot commented Jan 29, 2026

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.80%. Comparing base (9e6a843) to head (00a9191).

Files with missing lines Patch % Lines
...che/seata/server/controller/ClusterController.java 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                2.x    #7970      +/-   ##
============================================
+ Coverage     71.74%   71.80%   +0.05%     
  Complexity      872      872              
============================================
  Files          1300     1300              
  Lines         49727    49721       -6     
  Branches       5908     5908              
============================================
+ Hits          35678    35702      +24     
+ Misses        11114    11083      -31     
- Partials       2935     2936       +1     
Files with missing lines Coverage Δ
...che/seata/server/controller/ClusterController.java 19.51% <0.00%> (+2.49%) ⬆️

... and 8 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@funky-eyes funky-eyes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please register your PR in those two files :
https://github.com/apache/incubator-seata/blob/2.x/changes/zh-cn/2.x.md https://github.com/apache/incubator-seata/blob/2.x/changes/en-us/2.x.md
And I believe this PR is an optimization, not a bug. Therefore the PR title should begin with the prefix "optimize:".

Copy link

@Abhishekmishra2808 Abhishekmishra2808 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I noticed: Codecov reports 4 uncovered lines in ClusterController.java.

Should we add or adjust a test in ClusterControllerTest to explicitly cover the path where:

  • raftServer != null
  • leaderNode is present via getRaftLeaderMetadata()

This would help avoid coverage regressions.

routeTable.refreshLeader(RaftServerManager.getCliClientServiceInstance(), group, 1000);
PeerId leader = routeTable.selectLeader(group);
if (leader != null) {
RaftClusterMetadata raftClusterMetadata =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small question: do we need a null-safety check around getRaftLeaderMetadata() or its fields (leader / learners) during leader transition windows, or is the state machine guaranteed to return a consistent snapshot here?

@Sumit6307
Copy link
Contributor Author

Sumit6307 commented Jan 29, 2026

Please register your PR in those two files : https://github.com/apache/incubator-seata/blob/2.x/changes/zh-cn/2.x.md https://github.com/apache/incubator-seata/blob/2.x/changes/en-us/2.x.md And I believe this PR is an optimization, not a bug. Therefore the PR title should begin with the prefix "optimize:".

Thanks. I’m registering this PR in both changes/en-us/2.x.md and changes/zh-cn/2.x.md under the Optimize section.

@Sumit6307
Copy link
Contributor Author

Sumit6307 commented Jan 29, 2026

Thanks. I’m registering this PR in both changes/en-us/2.x.md and changes/zh-cn/2.x.md under the Optimize section.
@funky-eyes

Sumit6307 added a commit to Sumit6307/gsoc_incubator-seata that referenced this pull request Jan 29, 2026
Remove unnecessary refreshLeader from ClusterController
Sumit6307 added a commit to Sumit6307/gsoc_incubator-seata that referenced this pull request Jan 29, 2026
Remove unnecessary refreshLeader from ClusterController
Sumit6307 added a commit to Sumit6307/gsoc_incubator-seata that referenced this pull request Jan 29, 2026
Remove unnecessary refreshLeader from ClusterController cluster endpoint.
@funky-eyes
Copy link
Contributor

Thanks. I’m registering this PR in both changes/en-us/2.x.md and changes/zh-cn/2.x.md under the Optimize section. @funky-eyes

Why didn't you commit the related changes directly to this PR's branch instead of creating a new branch and opening a separate PR?

@xingfudeshi xingfudeshi changed the title fix #7967 Remove unnecessary refreshLeader from ClusterController cluster endpoint optimize:Remove unnecessary refreshLeader from ClusterController cluster endpoint Jan 30, 2026
Copy link
Member

@xingfudeshi xingfudeshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove unnecessary refreshLeader behavior from the Cluster interface

4 participants