From 2ce33c3fea4f3205fb8211ce51f28ff59aacebc8 Mon Sep 17 00:00:00 2001 From: "Derrick J. Wippler" Date: Thu, 23 May 2019 12:40:01 -0500 Subject: [PATCH 1/2] Remove now inits peers if needed --- groupcache.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/groupcache.go b/groupcache.go index 586fb79..a781576 100644 --- a/groupcache.go +++ b/groupcache.go @@ -241,6 +241,8 @@ func (g *Group) Get(ctx Context, key string, dest Sink) error { // Remove clears the key from our cache then forwards the remove // request to all peers. func (g *Group) Remove(ctx Context, key string) error { + g.peersOnce.Do(g.initPeers) + _, err := g.removeGroup.Do(key, func() (interface{}, error) { // Remove from key owner first From 2e501aa9227e4dcd5a986a803361ddef5ce267cd Mon Sep 17 00:00:00 2001 From: "Derrick J. Wippler" Date: Thu, 23 May 2019 15:09:56 -0500 Subject: [PATCH 2/2] Remove() Now returns the body on non 200 response --- groupcache.go | 2 +- http.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/groupcache.go b/groupcache.go index a781576..e555eb3 100644 --- a/groupcache.go +++ b/groupcache.go @@ -252,7 +252,7 @@ func (g *Group) Remove(ctx Context, key string) error { return nil, err } } - // Remove from our cache first in case we are owner + // Remove from our cache next g.localRemove(key) wg := sync.WaitGroup{} errs := make(chan error) diff --git a/http.go b/http.go index 568da49..d45955e 100644 --- a/http.go +++ b/http.go @@ -20,6 +20,7 @@ import ( "bytes" "fmt" "io" + "io/ioutil" "net/http" "net/url" "strings" @@ -273,9 +274,14 @@ func (h *httpGetter) Remove(ctx Context, in *pb.GetRequest) error { if err := h.makeRequest(ctx, http.MethodDelete, in, &res); err != nil { return err } - res.Body.Close() + defer res.Body.Close() + if res.StatusCode != http.StatusOK { - return fmt.Errorf("server returned: %v", res.Status) + body, err := ioutil.ReadAll(res.Body) + if err != nil { + return fmt.Errorf("while reading body response: %v", res.Status) + } + return fmt.Errorf("server returned status %d: %s", res.StatusCode, body) } return nil }