mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
concurrency: return v3.GetResponse for Election.Leader()
The full information about the leader's key is necessary to safely use elections with transactions. Instead of returning only the value on Leader(), return the entire GetResposne.
This commit is contained in:
parent
a6cab69c88
commit
4b5bb7f212
@ -122,16 +122,16 @@ func (e *Election) Resign(ctx context.Context) (err error) {
|
||||
}
|
||||
|
||||
// Leader returns the leader value for the current election.
|
||||
func (e *Election) Leader(ctx context.Context) (string, error) {
|
||||
func (e *Election) Leader(ctx context.Context) (*v3.GetResponse, error) {
|
||||
client := e.session.Client()
|
||||
resp, err := client.Get(ctx, e.keyPrefix, v3.WithFirstCreate()...)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
} else if len(resp.Kvs) == 0 {
|
||||
// no leader currently elected
|
||||
return "", ErrElectionNoLeader
|
||||
return nil, ErrElectionNoLeader
|
||||
}
|
||||
return string(resp.Kvs[0].Value), nil
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// Observe returns a channel that observes all leader proposal values as
|
||||
|
Loading…
x
Reference in New Issue
Block a user