Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

etcdserver: export method EtcdServer.leaderChangedNotify (#12378) #12410

Merged
merged 1 commit into from
Feb 2, 2021

Conversation

Yanhao
Copy link
Contributor

@Yanhao Yanhao commented Oct 21, 2020

No description provided.

@stale
Copy link

stale bot commented Jan 19, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 19, 2021
Copy link
Contributor

@ptabor ptabor left a comment

Choose a reason for hiding this comment

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

Please justify the change / describe problem you are trying to solve.

From first glance it sounds to me as undesired, as the space is implementation detail of etcd.

@stale stale bot removed the stale label Feb 1, 2021
@Yanhao
Copy link
Contributor Author

Yanhao commented Feb 2, 2021

When use etcd in Embed mode,the only way to know etcd leader changes is to poll the EtcdServer.Lead, and that way wastes some cpu cycles.
Why I want to know the current leader of etcd is because that I have another application level leader and I want the leader can follow etcd's easily so there will less network overhead, most request is made by the application level leader after all.
If leaderChangedNotify is exported, then application code can be notified after etcd leader changes, avoid wasteful pollings.
@ptabor

@@ -1689,7 +1689,7 @@ func (s *EtcdServer) getLead() uint64 {
return atomic.LoadUint64(&s.lead)
}

func (s *EtcdServer) leaderChangedNotify() <-chan struct{} {
func (s *EtcdServer) LeaderChangedNotify() <-chan struct{} {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add it to the 'Server' interface.

Please comment on the semantic:

  1. that this channel is being closed when the leadership changes.
  2. so the new channel needs to be obtained for each term.
  3. That you can loose some consecutive channel changes using this API.

@Yanhao Yanhao force-pushed the master branch 2 times, most recently from 895b9e5 to aedf370 Compare February 2, 2021 09:12
@ptabor
Copy link
Contributor

ptabor commented Feb 2, 2021

Thank you.

now PASSES="fmt" ./test.sh fails with:

% (cd server && 'go' 'vet' './...')
stderr: # go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp
stderr: vet: etcdserver/api/etcdhttp/peer_test.go:86:41: cannot use &(fakeServer literal) (value of type *fakeServer) as etcdserver.Server value in argument to newPeerHandler: missing method LeaderChangedNotify
stderr: # go.etcd.io/etcd/server/v3/etcdserver/api/v2http
stderr: vet: etcdserver/api/v2http/client_test.go:670:12: cannot use &(serverRecorder literal) (value of type *serverRecorder) as etcdserver.ServerV2 value in struct literal: missing method LeaderChangedNotify

@Yanhao
Copy link
Contributor Author

Yanhao commented Feb 2, 2021

Fixed

@Yanhao Yanhao requested a review from ptabor February 2, 2021 11:21
@ptabor ptabor merged commit 50ca440 into etcd-io:master Feb 2, 2021
@ptabor
Copy link
Contributor

ptabor commented Feb 2, 2021

Thank you.

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

Successfully merging this pull request may close these issues.

2 participants