@@ -22,8 +22,8 @@ import (
22
22
23
23
var errRingShardsDown = errors .New ("redis: all ring shards are down" )
24
24
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 {
27
27
err := client .Ping (ctx ).Err ()
28
28
return err == nil || err == pool .ErrPoolTimeout
29
29
}
@@ -34,8 +34,6 @@ type ConsistentHash interface {
34
34
Get (string ) string
35
35
}
36
36
37
- type ShardHealthCheckFn func (ctx context.Context , client * Client ) bool
38
-
39
37
type rendezvousWrapper struct {
40
38
* rendezvous.Rendezvous
41
39
}
@@ -62,13 +60,13 @@ type RingOptions struct {
62
60
// ClientName will execute the `CLIENT SETNAME ClientName` command for each conn.
63
61
ClientName string
64
62
65
- // Frequency of executing ShardHealthCheckFn to check shards availability.
63
+ // Frequency of executing HeartbeatFn to check shards availability.
66
64
// Shard is considered down after 3 subsequent failed checks.
67
65
HeartbeatFrequency time.Duration
68
66
69
67
// 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
72
70
73
71
// NewConsistentHash returns a consistent hash that is used
74
72
// to distribute keys across the shards.
@@ -125,8 +123,8 @@ func (opt *RingOptions) init() {
125
123
opt .HeartbeatFrequency = 500 * time .Millisecond
126
124
}
127
125
128
- if opt .ShardHealthCheckFn == nil {
129
- opt .ShardHealthCheckFn = defaultShardHealthCheckFn
126
+ if opt .HeartbeatFn == nil {
127
+ opt .HeartbeatFn = defaultHeartbeatFn
130
128
}
131
129
132
130
if opt .NewConsistentHash == nil {
@@ -424,7 +422,7 @@ func (c *ringSharding) Heartbeat(ctx context.Context, frequency time.Duration) {
424
422
var rebalance bool
425
423
426
424
for _ , shard := range c .List () {
427
- isUp := c .opt .ShardHealthCheckFn (ctx , shard .Client )
425
+ isUp := c .opt .HeartbeatFn (ctx , shard .Client )
428
426
if shard .Vote (isUp ) {
429
427
internal .Logger .Printf (ctx , "ring shard state changed: %s" , shard )
430
428
rebalance = true
0 commit comments