15
15
package cmd
16
16
17
17
import (
18
- "context"
19
18
"crypto/rand"
20
19
"fmt"
21
20
"os"
@@ -29,44 +28,11 @@ import (
29
28
)
30
29
31
30
var (
32
- // dialTotal counts the number of mustCreateConn calls so that endpoint
33
- // connections can be handed out in round-robin order
34
- dialTotal int
35
-
36
- // leaderEps is a cache for holding endpoints of a leader node
37
- leaderEps []string
38
-
39
31
// cache the username and password for multiple connections
40
32
globalUserName string
41
33
globalPassword string
42
34
)
43
35
44
- func mustFindLeaderEndpoints (c * clientv3.Client ) {
45
- resp , lerr := c .MemberList (context .TODO ())
46
- if lerr != nil {
47
- fmt .Fprintf (os .Stderr , "failed to get a member list: %s\n " , lerr )
48
- os .Exit (1 )
49
- }
50
-
51
- leaderID := uint64 (0 )
52
- for _ , ep := range c .Endpoints () {
53
- if sresp , serr := c .Status (context .TODO (), ep ); serr == nil {
54
- leaderID = sresp .Leader
55
- break
56
- }
57
- }
58
-
59
- for _ , m := range resp .Members {
60
- if m .ID == leaderID {
61
- leaderEps = m .ClientURLs
62
- return
63
- }
64
- }
65
-
66
- fmt .Fprint (os .Stderr , "failed to find a leader endpoint\n " )
67
- os .Exit (1 )
68
- }
69
-
70
36
func getUsernamePassword (usernameFlag string ) (string , string , error ) {
71
37
if globalUserName != "" && globalPassword != "" {
72
38
return globalUserName , globalPassword , nil
@@ -88,14 +54,9 @@ func getUsernamePassword(usernameFlag string) (string, string, error) {
88
54
}
89
55
90
56
func mustCreateConn () * clientv3.Client {
91
- connEndpoints := leaderEps
92
- if len (connEndpoints ) == 0 {
93
- connEndpoints = []string {endpoints [dialTotal % len (endpoints )]}
94
- dialTotal ++
95
- }
96
57
cfg := clientv3.Config {
97
58
AutoSyncInterval : autoSyncInterval ,
98
- Endpoints : connEndpoints ,
59
+ Endpoints : endpoints ,
99
60
DialTimeout : dialTimeout ,
100
61
}
101
62
if ! tls .Empty () || tls .TrustedCAFile != "" {
@@ -118,12 +79,6 @@ func mustCreateConn() *clientv3.Client {
118
79
}
119
80
120
81
client , err := clientv3 .New (cfg )
121
- if targetLeader && len (leaderEps ) == 0 {
122
- mustFindLeaderEndpoints (client )
123
- client .Close ()
124
- return mustCreateConn ()
125
- }
126
-
127
82
grpclog .SetLoggerV2 (grpclog .NewLoggerV2 (os .Stderr , os .Stderr , os .Stderr ))
128
83
129
84
if err != nil {
0 commit comments