mirror of
https://github.com/mailgun/groupcache.git
synced 2024-11-16 14:10:04 +00:00
Merge pull request #4 from mailgun/thrawn/develop
Remove() now inits peers if needed
This commit is contained in:
commit
9dade9087a
@ -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
|
||||
@ -250,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)
|
||||
|
10
http.go
10
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user