Skip to content

Commit

Permalink
etcd: fix proxy
Browse files Browse the repository at this point in the history
1. move proxy datadir to /proxy subdir.
2. delay update proxy's cluster after validation.
  • Loading branch information
xiang90 committed Feb 2, 2015
1 parent bdcae31 commit fbabced
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
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'
18 changes: 12 additions & 6 deletions etcdmain/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,10 @@ func startProxy(cfg *config) error {
}

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)
}
cfg.dir = path.Join(cfg.dir, "proxy")
err = os.MkdirAll(cfg.dir, 0700)
if err != nil {
return err
Expand All @@ -250,19 +251,23 @@ func startProxy(cfg *config) error {
}

uf := func() []string {
old := cls.PeerURLs()
cls, err = etcdserver.GetClusterFromPeers(peerURLs, tr)
gcls, 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 {
log.Printf("proxy: %v", err)
return []string{}
}
if len(gcls.Members()) == 0 {
return cls.ClientURLs()
}
cls = gcls

urls := struct{ PeerURLs []string }{cls.PeerURLs()}
b, err := json.Marshal(urls)
if err != nil {
log.Printf("proxy: error on marshal peer urls %s", err)
return cls.ClientURLs()

}

err = ioutil.WriteFile(clusterfile+".bak", b, 0600)
Expand All @@ -275,9 +280,10 @@ func startProxy(cfg *config) error {
log.Printf("proxy: error on updating clusterfile %s", err)
return cls.ClientURLs()
}
if !reflect.DeepEqual(cls.PeerURLs(), old) {
log.Printf("proxy: updated peer urls in cluster file from %v to %v", old, cls.PeerURLs())
if !reflect.DeepEqual(cls.PeerURLs(), peerURLs) {
log.Printf("proxy: updated peer urls in cluster file from %v to %v", peerURLs, cls.PeerURLs())
}
peerURLs = cls.PeerURLs()

return cls.ClientURLs()
}
Expand Down

0 comments on commit fbabced

Please sign in to comment.