mirror of https://github.com/status-im/consul.git
Rename `lastServer` to `preferredServer`
Expanding the domain of lastServer beyond RPC() changes the meaning of this variable. Rename accordingly to match the intent coming in a subsequent commit: a background thread will be in charge of rotating preferredServer.
This commit is contained in:
parent
fb0bfcc3cf
commit
6af781d9d5
|
@ -9,6 +9,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/consul/consul/structs"
|
||||
|
@ -61,9 +62,9 @@ type Client struct {
|
|||
// serf cluster in the datacenter
|
||||
eventCh chan serf.Event
|
||||
|
||||
// lastServer is the last server we made an RPC call to,
|
||||
// preferredServer is the last server we made an RPC call to,
|
||||
// this is used to re-use the last connection
|
||||
lastServer *serverParts
|
||||
preferredServer *serverParts
|
||||
|
||||
// Logger uses the provided LogOutput
|
||||
logger *log.Logger
|
||||
|
@ -347,8 +348,8 @@ func (c *Client) RPC(method string, args interface{}, reply interface{}) error {
|
|||
// single server
|
||||
now := time.Now()
|
||||
if !c.connRebalanceTime.IsZero() && now.After(c.connRebalanceTime) {
|
||||
c.logger.Printf("[DEBUG] consul: connection time to server %s exceeded, rotating server connection", c.lastServer.Addr)
|
||||
c.lastServer = nil
|
||||
c.logger.Printf("[DEBUG] consul: connection time to server %s exceeded, rotating server connection", c.preferredServer.Addr)
|
||||
c.preferredServer = nil
|
||||
}
|
||||
|
||||
// Allocate these vars on the stack before the goto
|
||||
|
@ -358,12 +359,10 @@ func (c *Client) RPC(method string, args interface{}, reply interface{}) error {
|
|||
var numLANMembers int
|
||||
|
||||
var server *serverParts
|
||||
if c.lastServer != nil {
|
||||
server = c.lastServer
|
||||
if server != nil {
|
||||
if c.preferredServer != nil {
|
||||
server = c.preferredServer
|
||||
goto TRY_RPC
|
||||
}
|
||||
}
|
||||
|
||||
// Bail if we can't find any servers
|
||||
c.consulLock.RLock()
|
||||
|
@ -381,13 +380,12 @@ func (c *Client) RPC(method string, args interface{}, reply interface{}) error {
|
|||
TRY_RPC:
|
||||
if err := c.connPool.RPC(c.config.Datacenter, server.Addr, server.Version, method, args, reply); err != nil {
|
||||
c.connRebalanceTime = time.Time{}
|
||||
c.lastServer = nil
|
||||
c.lastRPCTime = time.Time{}
|
||||
c.preferredServer = nil
|
||||
return err
|
||||
}
|
||||
|
||||
// Cache the last server
|
||||
c.lastServer = server
|
||||
// Cache the last server as our preferred server
|
||||
_ = atomic.StorePointer(&c.preferredServer, server)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue