mirror of https://github.com/go-redis/redis.git
Remove Redis Cluster state check
This commit is contained in:
parent
78a66f0e5f
commit
17e8439f2f
23
cluster.go
23
cluster.go
|
@ -582,13 +582,6 @@ func (c *clusterState) slotNodes(slot int) []*clusterNode {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *clusterState) IsConsistent() bool {
|
||||
if c.nodes.opt.ClusterSlots != nil {
|
||||
return true
|
||||
}
|
||||
return len(c.Masters) <= len(c.Slaves)
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
type clusterStateHolder struct {
|
||||
|
@ -613,9 +606,6 @@ func (c *clusterStateHolder) Reload() (*clusterState, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !state.IsConsistent() {
|
||||
time.AfterFunc(time.Second, c.LazyReload)
|
||||
}
|
||||
return state, nil
|
||||
}
|
||||
|
||||
|
@ -640,16 +630,11 @@ func (c *clusterStateHolder) LazyReload() {
|
|||
go func() {
|
||||
defer atomic.StoreUint32(&c.reloading, 0)
|
||||
|
||||
for {
|
||||
state, err := c.reload()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
if state.IsConsistent() {
|
||||
return
|
||||
}
|
||||
_, err := c.reload()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}()
|
||||
}
|
||||
|
||||
|
|
|
@ -49,8 +49,6 @@ func (s *clusterScenario) addrs() []string {
|
|||
}
|
||||
|
||||
func (s *clusterScenario) clusterClient(opt *redis.ClusterOptions) *redis.ClusterClient {
|
||||
var errBadState = fmt.Errorf("cluster state is not consistent")
|
||||
|
||||
opt.Addrs = s.addrs()
|
||||
client := redis.NewClusterClient(opt)
|
||||
|
||||
|
@ -65,27 +63,7 @@ func (s *clusterScenario) clusterClient(opt *redis.ClusterOptions) *redis.Cluste
|
|||
}
|
||||
|
||||
if !state.IsConsistent() {
|
||||
return errBadState
|
||||
}
|
||||
|
||||
if len(state.Masters) < 3 {
|
||||
return errBadState
|
||||
}
|
||||
for _, master := range state.Masters {
|
||||
s := master.Client.Info("replication").Val()
|
||||
if !strings.Contains(s, "role:master") {
|
||||
return errBadState
|
||||
}
|
||||
}
|
||||
|
||||
if len(state.Slaves) < 3 {
|
||||
return errBadState
|
||||
}
|
||||
for _, slave := range state.Slaves {
|
||||
s := slave.Client.Info("replication").Val()
|
||||
if !strings.Contains(s, "role:slave") {
|
||||
return errBadState
|
||||
}
|
||||
return fmt.Errorf("cluster state is not consistent")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -3,6 +3,7 @@ package redis
|
|||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/go-redis/redis/internal/hashtag"
|
||||
"github.com/go-redis/redis/internal/pool"
|
||||
|
@ -55,3 +56,27 @@ func (c *ClusterClient) SwapNodes(key string) error {
|
|||
nodes[0], nodes[1] = nodes[1], nodes[0]
|
||||
return nil
|
||||
}
|
||||
|
||||
func (state *clusterState) IsConsistent() bool {
|
||||
if len(state.Masters) < 3 {
|
||||
return false
|
||||
}
|
||||
for _, master := range state.Masters {
|
||||
s := master.Client.Info("replication").Val()
|
||||
if !strings.Contains(s, "role:master") {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if len(state.Slaves) < 3 {
|
||||
return false
|
||||
}
|
||||
for _, slave := range state.Slaves {
|
||||
s := slave.Client.Info("replication").Val()
|
||||
if !strings.Contains(s, "role:slave") {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue