rebalanceLocked removes dead shards from the Ring. Requires c.mu locked.
()
| 522 | // rebalanceLocked removes dead shards from the Ring. |
| 523 | // Requires c.mu locked. |
| 524 | func (c *ringSharding) rebalanceLocked() { |
| 525 | if c.closed { |
| 526 | return |
| 527 | } |
| 528 | if c.shards == nil { |
| 529 | return |
| 530 | } |
| 531 | |
| 532 | liveShards := make([]string, 0, len(c.shards.m)) |
| 533 | |
| 534 | for name, shard := range c.shards.m { |
| 535 | if shard.IsUp() { |
| 536 | liveShards = append(liveShards, name) |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | c.hash = c.opt.NewConsistentHash(liveShards) |
| 541 | c.numShard = len(liveShards) |
| 542 | } |
| 543 | |
| 544 | func (c *ringSharding) Len() int { |
| 545 | c.mu.RLock() |