Skip to content

Commit 7b064d4

Browse files
committed
ShardHealthCheckFn renamed to HeartbeatFn
1 parent 61baaf5 commit 7b064d4

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

ring.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222

2323
var errRingShardsDown = errors.New("redis: all ring shards are down")
2424

25-
// defaultShardHealthCheckFn is the default function used to check the shard liveness
26-
var defaultShardHealthCheckFn = func(ctx context.Context, client *Client) bool {
25+
// defaultHeartbeatFn is the default function used to check the shard liveness
26+
var defaultHeartbeatFn = func(ctx context.Context, client *Client) bool {
2727
err := client.Ping(ctx).Err()
2828
return err == nil || err == pool.ErrPoolTimeout
2929
}
@@ -34,8 +34,6 @@ type ConsistentHash interface {
3434
Get(string) string
3535
}
3636

37-
type ShardHealthCheckFn func(ctx context.Context, client *Client) bool
38-
3937
type rendezvousWrapper struct {
4038
*rendezvous.Rendezvous
4139
}
@@ -62,13 +60,13 @@ type RingOptions struct {
6260
// ClientName will execute the `CLIENT SETNAME ClientName` command for each conn.
6361
ClientName string
6462

65-
// Frequency of executing ShardHealthCheckFn to check shards availability.
63+
// Frequency of executing HeartbeatFn to check shards availability.
6664
// Shard is considered down after 3 subsequent failed checks.
6765
HeartbeatFrequency time.Duration
6866

6967
// A function used to check the shard liveness
70-
// if not set, defaults to defaultShardHealthCheckFn
71-
ShardHealthCheckFn ShardHealthCheckFn
68+
// if not set, defaults to defaultHeartbeatFn
69+
HeartbeatFn func(ctx context.Context, client *Client) bool
7270

7371
// NewConsistentHash returns a consistent hash that is used
7472
// to distribute keys across the shards.
@@ -125,8 +123,8 @@ func (opt *RingOptions) init() {
125123
opt.HeartbeatFrequency = 500 * time.Millisecond
126124
}
127125

128-
if opt.ShardHealthCheckFn == nil {
129-
opt.ShardHealthCheckFn = defaultShardHealthCheckFn
126+
if opt.HeartbeatFn == nil {
127+
opt.HeartbeatFn = defaultHeartbeatFn
130128
}
131129

132130
if opt.NewConsistentHash == nil {
@@ -424,7 +422,7 @@ func (c *ringSharding) Heartbeat(ctx context.Context, frequency time.Duration) {
424422
var rebalance bool
425423

426424
for _, shard := range c.List() {
427-
isUp := c.opt.ShardHealthCheckFn(ctx, shard.Client)
425+
isUp := c.opt.HeartbeatFn(ctx, shard.Client)
428426
if shard.Vote(isUp) {
429427
internal.Logger.Printf(ctx, "ring shard state changed: %s", shard)
430428
rebalance = true

0 commit comments

Comments
 (0)