From 11295b1a3403f411223098896ae667fa224e264e Mon Sep 17 00:00:00 2001 From: yz1509 Date: Tue, 9 Feb 2021 16:39:15 +0800 Subject: [PATCH 1/3] Fix the bug that healthy sentinel displays ERROR on the codis-fe --- pkg/utils/redis/client.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/utils/redis/client.go b/pkg/utils/redis/client.go index 4ef8be235..0ca4fc2a7 100644 --- a/pkg/utils/redis/client.go +++ b/pkg/utils/redis/client.go @@ -30,6 +30,10 @@ type Client struct { Pipeline struct { Send, Recv uint64 } + + ExecCmd struct { + Do, Done uint64 + } } func NewClientNoAuth(addr string, timeout time.Duration) (*Client, error) { @@ -61,6 +65,8 @@ func (c *Client) isRecyclable() bool { return false case c.Pipeline.Send != c.Pipeline.Recv: return false + case c.ExecCmd.Do != c.ExecCmd.Done: + return false case c.Timeout != 0 && c.Timeout <= time.Since(c.LastUse): return false } @@ -68,7 +74,9 @@ func (c *Client) isRecyclable() bool { } func (c *Client) Do(cmd string, args ...interface{}) (interface{}, error) { + c.ExecCmd.Do++ r, err := c.conn.Do(cmd, args...) + c.ExecCmd.Done++ if err != nil { c.Close() return nil, errors.Trace(err) From 86e02f106731b3bd9d14c4c833d76c0480689436 Mon Sep 17 00:00:00 2001 From: yz1509 Date: Fri, 18 Jun 2021 16:59:34 +0800 Subject: [PATCH 2/3] Revert "Fix the bug that healthy sentinel displays ERROR on the codis-fe" This reverts commit 11295b1a3403f411223098896ae667fa224e264e. --- pkg/utils/redis/client.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pkg/utils/redis/client.go b/pkg/utils/redis/client.go index 0ca4fc2a7..4ef8be235 100644 --- a/pkg/utils/redis/client.go +++ b/pkg/utils/redis/client.go @@ -30,10 +30,6 @@ type Client struct { Pipeline struct { Send, Recv uint64 } - - ExecCmd struct { - Do, Done uint64 - } } func NewClientNoAuth(addr string, timeout time.Duration) (*Client, error) { @@ -65,8 +61,6 @@ func (c *Client) isRecyclable() bool { return false case c.Pipeline.Send != c.Pipeline.Recv: return false - case c.ExecCmd.Do != c.ExecCmd.Done: - return false case c.Timeout != 0 && c.Timeout <= time.Since(c.LastUse): return false } @@ -74,9 +68,7 @@ func (c *Client) isRecyclable() bool { } func (c *Client) Do(cmd string, args ...interface{}) (interface{}, error) { - c.ExecCmd.Do++ r, err := c.conn.Do(cmd, args...) - c.ExecCmd.Done++ if err != nil { c.Close() return nil, errors.Trace(err) From 74ee23d01ce9cc7bb0f0a9e177132ab48f352afb Mon Sep 17 00:00:00 2001 From: yz1509 Date: Fri, 18 Jun 2021 17:05:13 +0800 Subject: [PATCH 3/3] Fix the bug that healthy sentinel displays ERROR on the codis-fe --- pkg/topom/topom_stats.go | 2 ++ pkg/utils/redis/client.go | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/pkg/topom/topom_stats.go b/pkg/topom/topom_stats.go index 429a89df7..9ee17273d 100644 --- a/pkg/topom/topom_stats.go +++ b/pkg/topom/topom_stats.go @@ -82,11 +82,13 @@ func (s *Topom) RefreshRedisStats(timeout time.Duration) (*sync2.Future, error) defer s.ha.redisp.PutClient(c) m, err := c.Info() if err != nil { + c.ShouldClose = true return nil, err } sentinel := redis.NewSentinel(s.config.ProductName, s.config.ProductAuth) p, err := sentinel.MastersAndSlavesClient(c) if err != nil { + c.ShouldClose = true return nil, err } return &RedisStats{Stats: m, Sentinel: p}, nil diff --git a/pkg/utils/redis/client.go b/pkg/utils/redis/client.go index 4ef8be235..a6b01ca45 100644 --- a/pkg/utils/redis/client.go +++ b/pkg/utils/redis/client.go @@ -30,6 +30,8 @@ type Client struct { Pipeline struct { Send, Recv uint64 } + + ShouldClose bool } func NewClientNoAuth(addr string, timeout time.Duration) (*Client, error) { @@ -48,6 +50,7 @@ func NewClient(addr string, auth string, timeout time.Duration) (*Client, error) return &Client{ conn: c, Addr: addr, Auth: auth, LastUse: time.Now(), Timeout: timeout, + ShouldClose: false, }, nil } @@ -57,6 +60,8 @@ func (c *Client) Close() error { func (c *Client) isRecyclable() bool { switch { + case c.ShouldClose: + return false case c.conn.Err() != nil: return false case c.Pipeline.Send != c.Pipeline.Recv: