Skip to content

Commit a46b053

Browse files
committed
More granular locking
1 parent be4c4f3 commit a46b053

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ring.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,20 @@ func (c *ringShards) Heartbeat(frequency time.Duration) {
273273

274274
// rebalance removes dead shards from the Ring.
275275
func (c *ringShards) rebalance() {
276+
c.mu.RLock()
277+
shards := c.shards
278+
c.mu.RUnlock()
279+
276280
hash := newConsistentHash(c.opt)
277281
var shardsNum int
278-
c.mu.Lock()
279-
for name, shard := range c.shards {
282+
for name, shard := range shards {
280283
if shard.IsUp() {
281284
hash.Add(name)
282285
shardsNum++
283286
}
284287
}
285288

289+
c.mu.Lock()
286290
c.hash = hash
287291
c.len = shardsNum
288292
c.mu.Unlock()

0 commit comments

Comments
 (0)