mirror of
https://github.com/mailgun/groupcache.git
synced 2024-11-16 14:10:04 +00:00
fix(): get URL from httpGetter instead of httpPool
This commit is contained in:
parent
ae2e156f19
commit
fb2028f2ff
@ -353,7 +353,7 @@ func (g *Group) load(ctx context.Context, key string, dest Sink) (value ByteView
|
|||||||
"err": err,
|
"err": err,
|
||||||
"key": key,
|
"key": key,
|
||||||
"category": "groupcache",
|
"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)
|
g.Stats.PeerErrors.Add(1)
|
||||||
|
@ -271,6 +271,10 @@ func (p *fakePeer) Remove(_ context.Context, in *pb.GetRequest) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *fakePeer) GetURL() string {
|
||||||
|
return "fakePeer"
|
||||||
|
}
|
||||||
|
|
||||||
type fakePeers []ProtoGetter
|
type fakePeers []ProtoGetter
|
||||||
|
|
||||||
func (p fakePeers) PickPeer(key string) (peer ProtoGetter, ok bool) {
|
func (p fakePeers) PickPeer(key string) (peer ProtoGetter, ok bool) {
|
||||||
|
19
http.go
19
http.go
@ -157,20 +157,6 @@ func (p *HTTPPool) PickPeer(key string) (ProtoGetter, bool) {
|
|||||||
return nil, false
|
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) {
|
func (p *HTTPPool) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
// Parse request.
|
// Parse request.
|
||||||
if !strings.HasPrefix(r.URL.Path, p.opts.BasePath) {
|
if !strings.HasPrefix(r.URL.Path, p.opts.BasePath) {
|
||||||
@ -239,6 +225,11 @@ type httpGetter struct {
|
|||||||
baseURL string
|
baseURL string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetURL
|
||||||
|
func (p *httpGetter) GetURL() string {
|
||||||
|
return p.baseURL
|
||||||
|
}
|
||||||
|
|
||||||
var bufferPool = sync.Pool{
|
var bufferPool = sync.Pool{
|
||||||
New: func() interface{} { return new(bytes.Buffer) },
|
New: func() interface{} { return new(bytes.Buffer) },
|
||||||
}
|
}
|
||||||
|
6
peers.go
6
peers.go
@ -28,6 +28,8 @@ import (
|
|||||||
type ProtoGetter interface {
|
type ProtoGetter interface {
|
||||||
Get(context context.Context, in *pb.GetRequest, out *pb.GetResponse) error
|
Get(context context.Context, in *pb.GetRequest, out *pb.GetResponse) error
|
||||||
Remove(context context.Context, in *pb.GetRequest) 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
|
// PeerPicker is the interface that must be implemented to locate
|
||||||
@ -39,9 +41,6 @@ type PeerPicker interface {
|
|||||||
PickPeer(key string) (peer ProtoGetter, ok bool)
|
PickPeer(key string) (peer ProtoGetter, ok bool)
|
||||||
// GetAll returns all the peers in the group
|
// GetAll returns all the peers in the group
|
||||||
GetAll() []ProtoGetter
|
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.
|
// 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) PickPeer(key string) (peer ProtoGetter, ok bool) { return }
|
||||||
func (NoPeers) GetAll() []ProtoGetter { return []ProtoGetter{} }
|
func (NoPeers) GetAll() []ProtoGetter { return []ProtoGetter{} }
|
||||||
func (NoPeers) GetURL(key string) string { return "" }
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
portPicker func(groupName string) PeerPicker
|
portPicker func(groupName string) PeerPicker
|
||||||
|
Loading…
Reference in New Issue
Block a user