etcd: fix proxy
1. move proxy datadir to /proxy subdir. 2. delay update proxy's cluster after validation.
This commit is contained in:
parent
bdcae31638
commit
fbabcedcc9
2
Procfile
2
Procfile
@ -2,4 +2,4 @@
|
|||||||
etcd1: bin/etcd -name infra1 -listen-client-urls http://localhost:4001 -advertise-client-urls http://localhost:4001 -listen-peer-urls http://localhost:7001 -initial-advertise-peer-urls http://localhost:7001 -initial-cluster-token etcd-cluster-1 -initial-cluster 'infra1=http://localhost:7001,infra2=http://localhost:7002,infra3=http://localhost:7003' -initial-cluster-state new
|
etcd1: bin/etcd -name infra1 -listen-client-urls http://localhost:4001 -advertise-client-urls http://localhost:4001 -listen-peer-urls http://localhost:7001 -initial-advertise-peer-urls http://localhost:7001 -initial-cluster-token etcd-cluster-1 -initial-cluster 'infra1=http://localhost:7001,infra2=http://localhost:7002,infra3=http://localhost:7003' -initial-cluster-state new
|
||||||
etcd2: bin/etcd -name infra2 -listen-client-urls http://localhost:4002 -advertise-client-urls http://localhost:4002 -listen-peer-urls http://localhost:7002 -initial-advertise-peer-urls http://localhost:7002 -initial-cluster-token etcd-cluster-1 -initial-cluster 'infra1=http://localhost:7001,infra2=http://localhost:7002,infra3=http://localhost:7003' -initial-cluster-state new
|
etcd2: bin/etcd -name infra2 -listen-client-urls http://localhost:4002 -advertise-client-urls http://localhost:4002 -listen-peer-urls http://localhost:7002 -initial-advertise-peer-urls http://localhost:7002 -initial-cluster-token etcd-cluster-1 -initial-cluster 'infra1=http://localhost:7001,infra2=http://localhost:7002,infra3=http://localhost:7003' -initial-cluster-state new
|
||||||
etcd3: bin/etcd -name infra3 -listen-client-urls http://localhost:4003 -advertise-client-urls http://localhost:4003 -listen-peer-urls http://localhost:7003 -initial-advertise-peer-urls http://localhost:7003 -initial-cluster-token etcd-cluster-1 -initial-cluster 'infra1=http://localhost:7001,infra2=http://localhost:7002,infra3=http://localhost:7003' -initial-cluster-state new
|
etcd3: bin/etcd -name infra3 -listen-client-urls http://localhost:4003 -advertise-client-urls http://localhost:4003 -listen-peer-urls http://localhost:7003 -initial-advertise-peer-urls http://localhost:7003 -initial-cluster-token etcd-cluster-1 -initial-cluster 'infra1=http://localhost:7001,infra2=http://localhost:7002,infra3=http://localhost:7003' -initial-cluster-state new
|
||||||
proxy: bin/etcd -proxy=on -bind-addr 127.0.0.1:8080 -initial-cluster 'infra1=http://localhost:7001,infra2=http://localhost:7002,infra3=http://localhost:7003'
|
proxy: bin/etcd -name proxy1 -proxy=on -bind-addr 127.0.0.1:8080 -initial-cluster 'infra1=http://localhost:7001,infra2=http://localhost:7002,infra3=http://localhost:7003'
|
||||||
|
@ -221,9 +221,10 @@ func startProxy(cfg *config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cfg.dir == "" {
|
if cfg.dir == "" {
|
||||||
cfg.dir = fmt.Sprintf("%v.etcdproxy", cfg.name)
|
cfg.dir = fmt.Sprintf("%v.etcd", cfg.name)
|
||||||
log.Printf("no proxy data-dir provided, using default proxy data-dir ./%s", cfg.dir)
|
log.Printf("no proxy data-dir provided, using default proxy data-dir ./%s", cfg.dir)
|
||||||
}
|
}
|
||||||
|
cfg.dir = path.Join(cfg.dir, "proxy")
|
||||||
err = os.MkdirAll(cfg.dir, 0700)
|
err = os.MkdirAll(cfg.dir, 0700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -250,19 +251,23 @@ func startProxy(cfg *config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uf := func() []string {
|
uf := func() []string {
|
||||||
old := cls.PeerURLs()
|
gcls, err := etcdserver.GetClusterFromPeers(peerURLs, tr)
|
||||||
cls, err = etcdserver.GetClusterFromPeers(peerURLs, tr)
|
// TODO: remove the 2nd check when we fix GetClusterFromPeers
|
||||||
|
// GetClusterFromPeers should not return nil error with an invaild empty cluster
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("proxy: %v", err)
|
log.Printf("proxy: %v", err)
|
||||||
return []string{}
|
return []string{}
|
||||||
}
|
}
|
||||||
|
if len(gcls.Members()) == 0 {
|
||||||
|
return cls.ClientURLs()
|
||||||
|
}
|
||||||
|
cls = gcls
|
||||||
|
|
||||||
urls := struct{ PeerURLs []string }{cls.PeerURLs()}
|
urls := struct{ PeerURLs []string }{cls.PeerURLs()}
|
||||||
b, err := json.Marshal(urls)
|
b, err := json.Marshal(urls)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("proxy: error on marshal peer urls %s", err)
|
log.Printf("proxy: error on marshal peer urls %s", err)
|
||||||
return cls.ClientURLs()
|
return cls.ClientURLs()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ioutil.WriteFile(clusterfile+".bak", b, 0600)
|
err = ioutil.WriteFile(clusterfile+".bak", b, 0600)
|
||||||
@ -275,9 +280,10 @@ func startProxy(cfg *config) error {
|
|||||||
log.Printf("proxy: error on updating clusterfile %s", err)
|
log.Printf("proxy: error on updating clusterfile %s", err)
|
||||||
return cls.ClientURLs()
|
return cls.ClientURLs()
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(cls.PeerURLs(), old) {
|
if !reflect.DeepEqual(cls.PeerURLs(), peerURLs) {
|
||||||
log.Printf("proxy: updated peer urls in cluster file from %v to %v", old, cls.PeerURLs())
|
log.Printf("proxy: updated peer urls in cluster file from %v to %v", peerURLs, cls.PeerURLs())
|
||||||
}
|
}
|
||||||
|
peerURLs = cls.PeerURLs()
|
||||||
|
|
||||||
return cls.ClientURLs()
|
return cls.ClientURLs()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user