Skip to content

Commit

Permalink
vendor: update mesh
Browse files Browse the repository at this point in the history
Now, broadcast operations cannot fail. So, update various broadcast-y
methods to no longer return errors.
  • Loading branch information
peterbourgon committed Jan 28, 2016
1 parent 1a590b3 commit 0dff2e6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 39 deletions.
3 changes: 1 addition & 2 deletions ipam/testutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (m *mockGossipComms) String() string {
// that the contents of messages are never re-ordered. Which, for instance,
// requires they are not based off iterating through a map.

func (m *mockGossipComms) GossipBroadcast(update mesh.GossipData) error {
func (m *mockGossipComms) GossipBroadcast(update mesh.GossipData) {
m.Lock()
defer m.Unlock()
buf := []byte{}
Expand All @@ -63,7 +63,6 @@ func (m *mockGossipComms) GossipBroadcast(update mesh.GossipData) error {
// Swallow this message
m.messages = m.messages[1:]
}
return nil
}

func equalByteBuffer(a, b []byte) bool {
Expand Down
14 changes: 3 additions & 11 deletions nameserver/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,11 @@ func (n *Nameserver) HandleHTTP(router *mux.Router, dockerCli *docker.Client) {
return
}

if err := n.AddEntry(hostname, container, n.ourName, ip); err != nil {
n.badRequest(w, fmt.Errorf("Unable to add entry: %v", err))
return
}
n.AddEntry(hostname, container, n.ourName, ip)

if r.FormValue("check-alive") == "true" && dockerCli != nil && dockerCli.IsContainerNotRunning(container) {
n.infof("container '%s' is not running: removing", container)
if err := n.Delete(hostname, container, ipStr, ip); err != nil {
n.infof("failed to remove: %v", err)
}
n.Delete(hostname, container, ipStr, ip)
}

w.WriteHeader(204)
Expand Down Expand Up @@ -79,10 +74,7 @@ func (n *Nameserver) HandleHTTP(router *mux.Router, dockerCli *docker.Client) {
ipStr = "*"
}

if err := n.Delete(hostname, container, ipStr, ip); err != nil {
n.badRequest(w, fmt.Errorf("Unable to delete entries: %v", err))
return
}
n.Delete(hostname, container, ipStr, ip)
w.WriteHeader(204)
}
router.Methods("DELETE").Path("/name/{container}/{ip}").HandlerFunc(deleteHandler)
Expand Down
18 changes: 8 additions & 10 deletions nameserver/nameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ func (n *Nameserver) Stop() {
n.quit <- struct{}{}
}

func (n *Nameserver) broadcastEntries(es ...Entry) error {
func (n *Nameserver) broadcastEntries(es ...Entry) {
if n.gossip == nil || len(es) == 0 {
return nil
return
}
return n.gossip.GossipBroadcast(&GossipData{
n.gossip.GossipBroadcast(&GossipData{
Entries: Entries(es),
Timestamp: now(),
})
}

func (n *Nameserver) AddEntry(hostname, containerid string, origin mesh.PeerName, addr address.Address) error {
func (n *Nameserver) AddEntry(hostname, containerid string, origin mesh.PeerName, addr address.Address) {
n.infof("adding entry %s -> %s", hostname, addr.String())
n.Lock()
entry := n.entries.add(hostname, containerid, origin, addr)
n.Unlock()
return n.broadcastEntries(entry)
n.broadcastEntries(entry)
}

func (n *Nameserver) Lookup(hostname string) []address.Address {
Expand Down Expand Up @@ -134,9 +134,7 @@ func (n *Nameserver) ContainerDied(ident string) {
return false
})
n.Unlock()
if err := n.broadcastEntries(entries...); err != nil {
n.errorf("failed to broadcast container %s death: %v", ident, err)
}
n.broadcastEntries(entries...)
}

func (n *Nameserver) PeerGone(peer mesh.PeerName) {
Expand All @@ -148,7 +146,7 @@ func (n *Nameserver) PeerGone(peer mesh.PeerName) {
})
}

func (n *Nameserver) Delete(hostname, containerid, ipStr string, ip address.Address) error {
func (n *Nameserver) Delete(hostname, containerid, ipStr string, ip address.Address) {
n.Lock()
n.infof("tombstoning hostname=%s, container=%s, ip=%s", hostname, containerid, ipStr)
entries := n.entries.tombstone(n.ourName, func(e *Entry) bool {
Expand All @@ -168,7 +166,7 @@ func (n *Nameserver) Delete(hostname, containerid, ipStr string, ip address.Addr
return true
})
n.Unlock()
return n.broadcastEntries(entries...)
n.broadcastEntries(entries...)
}

func (n *Nameserver) deleteTombstones() {
Expand Down
18 changes: 7 additions & 11 deletions nameserver/nameserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestNameservers(t *testing.T) {
mapping := mapping{hostname, []pair{{nameserver.ourName, addr}}}
mappings = append(mappings, mapping)

require.Nil(t, nameserver.AddEntry(hostname, "", nameserver.ourName, addr))
nameserver.AddEntry(hostname, "", nameserver.ourName, addr)
check(nameserver, mapping)
}

Expand All @@ -132,7 +132,7 @@ func TestNameservers(t *testing.T) {
mapping.addrs = append(mapping.addrs, pair{nameserver.ourName, addr})
mappings[i] = mapping

require.Nil(t, nameserver.AddEntry(mapping.hostname, "", nameserver.ourName, addr))
nameserver.AddEntry(mapping.hostname, "", nameserver.ourName, addr)
check(nameserver, mapping)
}

Expand All @@ -157,7 +157,7 @@ func TestNameservers(t *testing.T) {
mappings[i] = mapping
nameserver := nameserversByName[pair.origin]

require.Nil(t, nameserver.Delete(mapping.hostname, "*", pair.addr.String(), pair.addr))
nameserver.Delete(mapping.hostname, "*", pair.addr.String(), pair.addr)
check(nameserver, mapping)
}

Expand Down Expand Up @@ -223,15 +223,13 @@ func TestContainerAndPeerDeath(t *testing.T) {
require.Nil(t, err)
nameserver := makeNameserver(peername)

err = nameserver.AddEntry("hostname", "containerid", peername, address.Address(0))
require.Nil(t, err)
nameserver.AddEntry("hostname", "containerid", peername, address.Address(0))
require.Equal(t, []address.Address{0}, nameserver.Lookup("hostname"))

nameserver.ContainerDied("containerid")
require.Equal(t, []address.Address{}, nameserver.Lookup("hostname"))

err = nameserver.AddEntry("hostname", "containerid", peername, address.Address(0))
require.Nil(t, err)
nameserver.AddEntry("hostname", "containerid", peername, address.Address(0))
require.Equal(t, []address.Address{0}, nameserver.Lookup("hostname"))

nameserver.PeerGone(peername)
Expand All @@ -247,15 +245,13 @@ func TestTombstoneDeletion(t *testing.T) {
require.Nil(t, err)
nameserver := makeNameserver(peername)

err = nameserver.AddEntry("hostname", "containerid", peername, address.Address(0))
require.Nil(t, err)
nameserver.AddEntry("hostname", "containerid", peername, address.Address(0))
require.Equal(t, []address.Address{0}, nameserver.Lookup("hostname"))

nameserver.deleteTombstones()
require.Equal(t, []address.Address{0}, nameserver.Lookup("hostname"))

err = nameserver.Delete("hostname", "containerid", "", address.Address(0))
require.Nil(t, err)
nameserver.Delete("hostname", "containerid", "", address.Address(0))
require.Equal(t, []address.Address{}, nameserver.Lookup("hostname"))
require.Equal(t, l(Entries{Entry{
ContainerID: "containerid",
Expand Down
7 changes: 3 additions & 4 deletions testing/gossip/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@ func (grouter *TestRouter) Stop() {
}
}

func (grouter *TestRouter) gossipBroadcast(sender mesh.PeerName, update mesh.GossipData) error {
func (grouter *TestRouter) gossipBroadcast(sender mesh.PeerName, update mesh.GossipData) {
for _, gossipChan := range grouter.gossipChans {
select {
case gossipChan <- broadcastMessage{sender: sender, data: update}:
default: // drop the message if we cannot send it
common.Log.Errorf("Dropping message")
}
}
return nil
}

func (grouter *TestRouter) gossip(sender mesh.PeerName, update mesh.GossipData) error {
Expand Down Expand Up @@ -174,6 +173,6 @@ func (client TestRouterClient) GossipUnicast(dstPeerName mesh.PeerName, buf []by
return nil
}

func (client TestRouterClient) GossipBroadcast(update mesh.GossipData) error {
return client.router.gossipBroadcast(client.sender, update)
func (client TestRouterClient) GossipBroadcast(update mesh.GossipData) {
client.router.gossipBroadcast(client.sender, update)
}

0 comments on commit 0dff2e6

Please sign in to comment.