mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
client: protect httpClusterClient with RWMutex
This commit is contained in:
parent
0943831b8e
commit
99d63eb62e
@ -20,6 +20,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
|
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
|
||||||
@ -78,6 +79,7 @@ type httpClusterClient struct {
|
|||||||
transport CancelableTransport
|
transport CancelableTransport
|
||||||
endpoints []string
|
endpoints []string
|
||||||
clients []HTTPClient
|
clients []HTTPClient
|
||||||
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *httpClusterClient) reset(tr CancelableTransport, eps []string) error {
|
func (c *httpClusterClient) reset(tr CancelableTransport, eps []string) error {
|
||||||
@ -111,6 +113,9 @@ func (c *httpClusterClient) reset(tr CancelableTransport, eps []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *httpClusterClient) Do(ctx context.Context, act HTTPAction) (resp *http.Response, body []byte, err error) {
|
func (c *httpClusterClient) Do(ctx context.Context, act HTTPAction) (resp *http.Response, body []byte, err error) {
|
||||||
|
c.RLock()
|
||||||
|
defer c.RUnlock()
|
||||||
|
|
||||||
if len(c.clients) == 0 {
|
if len(c.clients) == 0 {
|
||||||
return nil, nil, ErrNoEndpoints
|
return nil, nil, ErrNoEndpoints
|
||||||
}
|
}
|
||||||
@ -131,10 +136,15 @@ func (c *httpClusterClient) Do(ctx context.Context, act HTTPAction) (resp *http.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *httpClusterClient) Endpoints() []string {
|
func (c *httpClusterClient) Endpoints() []string {
|
||||||
|
c.RLock()
|
||||||
|
defer c.RUnlock()
|
||||||
return c.endpoints
|
return c.endpoints
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *httpClusterClient) Sync(ctx context.Context) error {
|
func (c *httpClusterClient) Sync(ctx context.Context) error {
|
||||||
|
c.Lock()
|
||||||
|
defer c.Unlock()
|
||||||
|
|
||||||
mAPI := NewMembersAPI(c)
|
mAPI := NewMembersAPI(c)
|
||||||
ms, err := mAPI.List(ctx)
|
ms, err := mAPI.List(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user