forked from mirror/redis
parent
17c058513b
commit
7f69d5e320
18
sentinel.go
18
sentinel.go
|
@ -245,7 +245,9 @@ func (c *sentinelFailover) MasterAddr() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *sentinelFailover) masterAddr() (string, error) {
|
func (c *sentinelFailover) masterAddr() (string, error) {
|
||||||
|
c.mu.RLock()
|
||||||
addr := c.getMasterAddr()
|
addr := c.getMasterAddr()
|
||||||
|
c.mu.RUnlock()
|
||||||
if addr != "" {
|
if addr != "" {
|
||||||
return addr, nil
|
return addr, nil
|
||||||
}
|
}
|
||||||
|
@ -253,6 +255,15 @@ func (c *sentinelFailover) masterAddr() (string, error) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
|
||||||
|
addr = c.getMasterAddr()
|
||||||
|
if addr != "" {
|
||||||
|
return addr, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.sentinel != nil {
|
||||||
|
c.closeSentinel()
|
||||||
|
}
|
||||||
|
|
||||||
for i, sentinelAddr := range c.sentinelAddrs {
|
for i, sentinelAddr := range c.sentinelAddrs {
|
||||||
sentinel := NewSentinelClient(&Options{
|
sentinel := NewSentinelClient(&Options{
|
||||||
Addr: sentinelAddr,
|
Addr: sentinelAddr,
|
||||||
|
@ -291,9 +302,7 @@ func (c *sentinelFailover) masterAddr() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *sentinelFailover) getMasterAddr() string {
|
func (c *sentinelFailover) getMasterAddr() string {
|
||||||
c.mu.RLock()
|
|
||||||
sentinel := c.sentinel
|
sentinel := c.sentinel
|
||||||
c.mu.RUnlock()
|
|
||||||
|
|
||||||
if sentinel == nil {
|
if sentinel == nil {
|
||||||
return ""
|
return ""
|
||||||
|
@ -303,11 +312,6 @@ func (c *sentinelFailover) getMasterAddr() string {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
internal.Logf("sentinel: GetMasterAddrByName name=%q failed: %s",
|
internal.Logf("sentinel: GetMasterAddrByName name=%q failed: %s",
|
||||||
c.masterName, err)
|
c.masterName, err)
|
||||||
c.mu.Lock()
|
|
||||||
if c.sentinel == sentinel {
|
|
||||||
c.closeSentinel()
|
|
||||||
}
|
|
||||||
c.mu.Unlock()
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue