diff --git a/groupcache.go b/groupcache.go index 9b1578f..3238876 100644 --- a/groupcache.go +++ b/groupcache.go @@ -353,7 +353,7 @@ func (g *Group) load(ctx context.Context, key string, dest Sink) (value ByteView "err": err, "key": key, "category": "groupcache", - }).Errorf("error retrieving key from peer '%s'", g.peers.GetURL(key)) + }).Errorf("error retrieving key from peer '%s'", peer.GetURL()) } g.Stats.PeerErrors.Add(1) diff --git a/groupcache_test.go b/groupcache_test.go index 58f8c81..86a4df2 100644 --- a/groupcache_test.go +++ b/groupcache_test.go @@ -271,6 +271,10 @@ func (p *fakePeer) Remove(_ context.Context, in *pb.GetRequest) error { return nil } +func (p *fakePeer) GetURL() string { + return "fakePeer" +} + type fakePeers []ProtoGetter func (p fakePeers) PickPeer(key string) (peer ProtoGetter, ok bool) { diff --git a/http.go b/http.go index badc84c..3048afc 100644 --- a/http.go +++ b/http.go @@ -157,20 +157,6 @@ func (p *HTTPPool) PickPeer(key string) (ProtoGetter, bool) { return nil, false } -// GetURL -func (p *HTTPPool) GetURL(key string) string { - p.mu.Lock() - defer p.mu.Unlock() - - if p.peers.IsEmpty() { - return "" - } - if peer := p.peers.Get(key); peer != p.self { - return peer - } - return p.self -} - func (p *HTTPPool) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Parse request. if !strings.HasPrefix(r.URL.Path, p.opts.BasePath) { @@ -239,6 +225,11 @@ type httpGetter struct { baseURL string } +// GetURL +func (p *httpGetter) GetURL() string { + return p.baseURL +} + var bufferPool = sync.Pool{ New: func() interface{} { return new(bytes.Buffer) }, } diff --git a/peers.go b/peers.go index 9f36e6b..18d8659 100644 --- a/peers.go +++ b/peers.go @@ -28,6 +28,8 @@ import ( type ProtoGetter interface { Get(context context.Context, in *pb.GetRequest, out *pb.GetResponse) error Remove(context context.Context, in *pb.GetRequest) error + // GetURL returns the peer URL + GetURL() string } // PeerPicker is the interface that must be implemented to locate @@ -39,9 +41,6 @@ type PeerPicker interface { PickPeer(key string) (peer ProtoGetter, ok bool) // GetAll returns all the peers in the group GetAll() []ProtoGetter - // GetURL returns the peer URL that own the specific key - // It returns empty string if there is no peers - GetURL(key string) string } // NoPeers is an implementation of PeerPicker that never finds a peer. @@ -49,7 +48,6 @@ type NoPeers struct{} func (NoPeers) PickPeer(key string) (peer ProtoGetter, ok bool) { return } func (NoPeers) GetAll() []ProtoGetter { return []ProtoGetter{} } -func (NoPeers) GetURL(key string) string { return "" } var ( portPicker func(groupName string) PeerPicker