From fc1ec6ada25125691cd21b0a76d4ceb933e73fd5 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 24 Dec 2014 18:34:59 +0000 Subject: [PATCH] refactor: go straight to PeerCache for fetching topology There is no need to go via Topology. Fetching does not access or modify the Topology state, and none of the functions on Topology update the PeerCache. So there is no point serialising the fetching with RebuildRoutes (or anything else). This does mean the connections' receiveTCP goroutines will take a direct lock on PeerCache, but a) it is only a read lock, and b) they already take a write lock in another code path. There may be some extra load on the PeerCache as a result of this change, due to the topology fetching of multiple connections no longer being funneled through the single Topology goroutine. Consequently, write locks on the PeerCache may take a little longer to acquire. Until we encounter this as a genuine problem though it's better to stick with the simpler code. --- router/connection.go | 2 +- router/topology.go | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/router/connection.go b/router/connection.go index ff79fbf5..0bf360ef 100644 --- a/router/connection.go +++ b/router/connection.go @@ -493,7 +493,7 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder, usingPassword bool // the payload are not included // - elements where the payload was older than the // receiver's version are updated - conn.SendTCP(Concat(ProtocolUpdateByte, conn.Router.Topology.FetchAll())) + conn.SendTCP(Concat(ProtocolUpdateByte, conn.Router.Peers.EncodeAllPeers())) } else if msg[0] == ProtocolUpdate { newUpdate, err := conn.Router.Peers.ApplyUpdate(msg[1:], conn.Router) if _, ok := err.(UnknownPeersError); err != nil && ok { diff --git a/router/topology.go b/router/topology.go index b8578f6b..02c3dcbf 100644 --- a/router/topology.go +++ b/router/topology.go @@ -54,19 +54,9 @@ func StartTopology(router *Router) *Topology { // ACTOR client API const ( - TFetchAll = iota TRebuildRoutes = iota ) -func (topo *Topology) FetchAll() []byte { - resultChan := make(chan interface{}, 0) - topo.queryChan <- &Interaction{ - code: TFetchAll, - resultChan: resultChan} - result := <-resultChan - return result.([]byte) -} - // Async. func (topo *Topology) RebuildRoutes() { topo.queryChan <- &Interaction{code: TRebuildRoutes} @@ -88,8 +78,6 @@ func (topo *Topology) queryLoop(queryChan <-chan *Interaction) { topo.unicast = unicast topo.broadcast = broadcast topo.Unlock() - case TFetchAll: - query.resultChan <- topo.router.Peers.EncodeAllPeers() default: log.Fatal("Unexpected topology query:", query) }