Rename c.consuls to c.consulServers

Prep for breaking out maintenance of consuls into a new goroutine.
pull/1873/head
Sean Chittenden 9 years ago
parent a92cda7bcd
commit cc86eb0a1a

@ -43,9 +43,9 @@ type Client struct {
// Connection pool to consul servers // Connection pool to consul servers
connPool *ConnPool connPool *ConnPool
// consuls tracks the locally known servers // consulServers tracks the locally known servers
consuls []*serverParts consulServers []*serverParts
consulLock sync.RWMutex consulLock sync.RWMutex
// eventCh is used to receive events from the // eventCh is used to receive events from the
// serf cluster in the datacenter // serf cluster in the datacenter
@ -254,9 +254,9 @@ func (c *Client) nodeJoin(me serf.MemberEvent) {
// Check if this server is known // Check if this server is known
found := false found := false
c.consulLock.Lock() c.consulLock.Lock()
for idx, existing := range c.consuls { for idx, existing := range c.consulServers {
if existing.Name == parts.Name { if existing.Name == parts.Name {
c.consuls[idx] = parts c.consulServers[idx] = parts
found = true found = true
break break
} }
@ -264,7 +264,7 @@ func (c *Client) nodeJoin(me serf.MemberEvent) {
// Add to the list if not known // Add to the list if not known
if !found { if !found {
c.consuls = append(c.consuls, parts) c.consulServers = append(c.consulServers, parts)
} }
c.consulLock.Unlock() c.consulLock.Unlock()
@ -286,11 +286,11 @@ func (c *Client) nodeFail(me serf.MemberEvent) {
// Remove the server if known // Remove the server if known
c.consulLock.Lock() c.consulLock.Lock()
n := len(c.consuls) n := len(c.consulServers)
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
if c.consuls[i].Name == parts.Name { if c.consulServers[i].Name == parts.Name {
c.consuls[i], c.consuls[n-1] = c.consuls[n-1], nil c.consulServers[i], c.consulServers[n-1] = c.consulServers[n-1], nil
c.consuls = c.consuls[:n-1] c.consulServers = c.consulServers[:n-1]
break break
} }
} }
@ -339,13 +339,14 @@ func (c *Client) RPC(method string, args interface{}, reply interface{}) error {
// Bail if we can't find any servers // Bail if we can't find any servers
c.consulLock.RLock() c.consulLock.RLock()
if len(c.consuls) == 0 { numConsulServers = len(c.consulServers)
if numConsulServers == 0 {
c.consulLock.RUnlock() c.consulLock.RUnlock()
return structs.ErrNoServers return structs.ErrNoServers
} }
// Select a random addr // Select a random addr
server = c.consuls[rand.Int31()%int32(len(c.consuls))] server = c.consulServers[rand.Int31n(int32(numConsulServers))]
c.consulLock.RUnlock() c.consulLock.RUnlock()
// Forward to remote Consul // Forward to remote Consul
@ -371,7 +372,7 @@ func (c *Client) Stats() map[string]map[string]string {
stats := map[string]map[string]string{ stats := map[string]map[string]string{
"consul": map[string]string{ "consul": map[string]string{
"server": "false", "server": "false",
"known_servers": toString(uint64(len(c.consuls))), "known_servers": toString(uint64(len(c.consulServers))),
}, },
"serf_lan": c.serf.Stats(), "serf_lan": c.serf.Stats(),
"runtime": runtimeStats(), "runtime": runtimeStats(),

Loading…
Cancel
Save