Skip to content

Commit

Permalink
etcdserver: stop worrying about scheme
Browse files Browse the repository at this point in the history
Stop worrying about the scheme. This puts a TODO on adding validation to
the schemes if TLS is specified. But we can worry about that later.
  • Loading branch information
Brandon Philips committed Oct 1, 2014
1 parent 7639752 commit 04bd48f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
6 changes: 3 additions & 3 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use goreman to run `go get github.com/mattn/goreman`
etcd1: bin/etcd -name node1 -bind-addr 127.0.0.1:4001 -peer-bind-addr :7001 -bootstrap-config 'node1=localhost:7001,node2=localhost:7002,node3=localhost:7003'
etcd2: bin/etcd -name node2 -bind-addr 127.0.0.1:4002 -peer-bind-addr :7002 -bootstrap-config 'node1=localhost:7001,node2=localhost:7002,node3=localhost:7003'
etcd3: bin/etcd -name node3 -bind-addr 127.0.0.1:4003 -peer-bind-addr :7003 -bootstrap-config 'node1=localhost:7001,node2=localhost:7002,node3=localhost:7003'
etcd1: bin/etcd -name node1 -listen-client-urls http://127.0.0.1:4001 -advertise-client-urls http://127.0.0.1:4001 -listen-peer-urls http://127.0.0.1:7001 -advertise-peer-urls http://127.0.0.1:7001 -bootstrap-config 'node1=http://localhost:7001,node2=http://localhost:7002,node3=http://localhost:7003'
etcd2: bin/etcd -name node2 -listen-client-urls http://127.0.0.1:4002 -advertise-client-urls http://127.0.0.1:4002 -listen-peer-urls http://127.0.0.1:7002 -advertise-peer-urls http://127.0.0.1:7002 -bootstrap-config 'node1=http://localhost:7001,node2=http://localhost:7002,node3=http://localhost:7003'
etcd3: bin/etcd -name node3 -listen-client-urls http://127.0.0.1:4003 -advertise-client-urls http://127.0.0.1:4003 -listen-peer-urls http://127.0.0.1:7003 -advertise-peer-urls http://127.0.0.1:7003 -bootstrap-config 'node1=http://localhost:7001,node2=http://localhost:7002,node3=http://localhost:7003'
#proxy: bin/etcd -proxy=on -bind-addr 127.0.0.1:8080 -peers 'localhost:7001,localhost:7002,localhost:7003'
6 changes: 3 additions & 3 deletions etcdserver/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func (c *Cluster) AddSlice(mems []Member) error {
// an addressible URI. If the given member does not exist, an empty string is returned.
func (c Cluster) Pick(id int64) string {
if m := c.FindID(id); m != nil {
addrs := m.PeerURLs
if len(addrs) == 0 {
urls := m.PeerURLs
if len(urls) == 0 {
return ""
}
return addrs[rand.Intn(len(addrs))]
return urls[rand.Intn(len(urls))]
}

return ""
Expand Down
17 changes: 6 additions & 11 deletions etcdserver/cluster_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,28 @@ func (s *clusterStore) Delete(id int64) {
func Sender(t *http.Transport, cls ClusterStore) func(msgs []raftpb.Message) {
c := &http.Client{Transport: t}

scheme := "http"
if t.TLSClientConfig != nil {
scheme = "https"
}

return func(msgs []raftpb.Message) {
for _, m := range msgs {
// TODO: reuse go routines
// limit the number of outgoing connections for the same receiver
go send(c, scheme, cls, m)
go send(c, cls, m)
}
}
}

func send(c *http.Client, scheme string, cls ClusterStore, m raftpb.Message) {
func send(c *http.Client, cls ClusterStore, m raftpb.Message) {
// TODO (xiangli): reasonable retry logic
for i := 0; i < 3; i++ {
addr := cls.Get().Pick(m.To)
if addr == "" {
u := cls.Get().Pick(m.To)
if u == "" {
// TODO: unknown peer id.. what do we do? I
// don't think his should ever happen, need to
// look into this further.
log.Printf("etcdhttp: no addr for %d", m.To)
return
}

url := fmt.Sprintf("%s://%s%s", scheme, addr, raftPrefix)
u = fmt.Sprintf("%s%s", u, raftPrefix)

// TODO: don't block. we should be able to have 1000s
// of messages out at a time.
Expand All @@ -113,7 +108,7 @@ func send(c *http.Client, scheme string, cls ClusterStore, m raftpb.Message) {
log.Println("etcdhttp: dropping message:", err)
return // drop bad message
}
if httpPost(c, url, data) {
if httpPost(c, u, data) {
return // success
}
// TODO: backoff
Expand Down

0 comments on commit 04bd48f

Please sign in to comment.