forked from mirror/redis
More granular locking
This commit is contained in:
parent
be4c4f3f38
commit
a46b053aa6
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()
|
||||||
|
|
Loading…
Reference in New Issue