Skip to content

Commit 6c3765b

Browse files
committed
add comments
1 parent 1c02c68 commit 6c3765b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

ring.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ func (c *ringSharding) Heartbeat(ctx context.Context, frequency time.Duration) {
422422
case <-ticker.C:
423423
var rebalance bool
424424

425+
// note: `c.List()` return a shadow copy of `[]*ringShard`.
425426
for _, shard := range c.List() {
426427
err := shard.Client.Ping(ctx).Err()
427428
isUp := err == nil || err == pool.ErrPoolTimeout
@@ -581,6 +582,7 @@ func (c *Ring) retryBackoff(attempt int) time.Duration {
581582

582583
// PoolStats returns accumulated connection pool stats.
583584
func (c *Ring) PoolStats() *PoolStats {
585+
// note: `c.List()` return a shadow copy of `[]*ringShard`.
584586
shards := c.sharding.List()
585587
var acc PoolStats
586588
for _, shard := range shards {
@@ -650,6 +652,7 @@ func (c *Ring) ForEachShard(
650652
ctx context.Context,
651653
fn func(ctx context.Context, client *Client) error,
652654
) error {
655+
// note: `c.List()` return a shadow copy of `[]*ringShard`.
653656
shards := c.sharding.List()
654657
var wg sync.WaitGroup
655658
errCh := make(chan error, 1)
@@ -681,6 +684,7 @@ func (c *Ring) ForEachShard(
681684
}
682685

683686
func (c *Ring) cmdsInfo(ctx context.Context) (map[string]*CommandInfo, error) {
687+
// note: `c.List()` return a shadow copy of `[]*ringShard`.
684688
shards := c.sharding.List()
685689
var firstErr error
686690
for _, shard := range shards {

0 commit comments

Comments
 (0)