@@ -12,8 +12,7 @@ import (
1212)
1313
1414const (
15- // DefaultEtcdTimeout is the default etcd timeout
16- DefaultEtcdTimeout time.Duration = 5 * time .Second
15+ defaultEtcdTimeout time.Duration = 5 * time .Second
1716)
1817
1918// EtcdClient is used by pserver client that is a part of trainer process.
@@ -48,7 +47,7 @@ func (p *EtcdClient) Desired() int {
4847
4948 psDesired , err = strconv .Atoi (string (resp .Kvs [0 ].Value ))
5049 if err != nil {
51- log .Errorf ("psDesired %s invalid %v" , psDesired , err )
50+ log .Errorf ("psDesired %d invalid %v" , psDesired , err )
5251 time .Sleep (p .timeout )
5352 continue
5453 }
@@ -67,12 +66,12 @@ func (p *EtcdClient) List() []Server {
6766 for {
6867 for i := 0 ; i < psDesired ; i ++ {
6968 ctx , cancel := context .WithTimeout (context .Background (), p .timeout )
69+ cancel ()
7070 psKey := pserver .PsPath + strconv .Itoa (i )
7171 log .Debugf ("checking %s" , psKey )
7272 resp , err := p .client .Get (ctx , psKey )
73- cancel ()
7473 if err != nil {
75- log .Infof ("Get psKey=%s error, %v" , psKey , err )
74+ log .Infof ("Get psKey= %s error, %v" , psKey , err )
7675 time .Sleep (p .timeout )
7776 continue
7877 }
@@ -107,19 +106,19 @@ func NewEtcd(endpoints string) *EtcdClient {
107106 for {
108107 cli , err = clientv3 .New (clientv3.Config {
109108 Endpoints : ep ,
110- DialTimeout : DefaultEtcdTimeout ,
109+ DialTimeout : defaultEtcdTimeout ,
111110 })
112111 if err != nil {
113112 log .Errorf ("Init etcd connection failed: %v" , err )
114- time .Sleep (DefaultEtcdTimeout )
113+ time .Sleep (defaultEtcdTimeout )
115114 continue
116115 }
117116 break
118117 }
119118 log .Infof ("Connected to etcd: %s\n " , endpoints )
120119 client := & EtcdClient {
121120 client : cli ,
122- timeout : DefaultEtcdTimeout ,
121+ timeout : defaultEtcdTimeout ,
123122 endpoints : ep ,
124123 }
125124 return client
0 commit comments