mirror of
https://github.com/redis/go-redis.git
synced 2025-07-22 10:01:50 +03:00
More granular locking
This commit is contained in:
8
ring.go
8
ring.go
@ -273,16 +273,20 @@ func (c *ringShards) Heartbeat(frequency time.Duration) {
|
|||||||
|
|
||||||
// rebalance removes dead shards from the Ring.
|
// rebalance removes dead shards from the Ring.
|
||||||
func (c *ringShards) rebalance() {
|
func (c *ringShards) rebalance() {
|
||||||
|
c.mu.RLock()
|
||||||
|
shards := c.shards
|
||||||
|
c.mu.RUnlock()
|
||||||
|
|
||||||
hash := newConsistentHash(c.opt)
|
hash := newConsistentHash(c.opt)
|
||||||
var shardsNum int
|
var shardsNum int
|
||||||
c.mu.Lock()
|
for name, shard := range shards {
|
||||||
for name, shard := range c.shards {
|
|
||||||
if shard.IsUp() {
|
if shard.IsUp() {
|
||||||
hash.Add(name)
|
hash.Add(name)
|
||||||
shardsNum++
|
shardsNum++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.mu.Lock()
|
||||||
c.hash = hash
|
c.hash = hash
|
||||||
c.len = shardsNum
|
c.len = shardsNum
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
|
Reference in New Issue
Block a user