// rebalance removes dead shards from the ring. func (ring *Ring) rebalance() { defer ring.mx.Unlock() ring.mx.Lock() ring.hash = consistenthash.New(ring.nreplicas, ring.hasher) for name, shard := range ring.shards { if shard.IsUp() { ring.hash.Add(name) } } }
func NewRing(opt *RingOptions) *Ring { ring := &Ring{ opt: opt, nreplicas: DefaultRingReplicas, shards: make(map[string]*ringShard), } ring.commandable.process = ring.process if opt.NReplicas != 0 { ring.nreplicas = opt.NReplicas } if opt.Hasher != nil { ring.hasher = opt.Hasher } ring.hash = consistenthash.New(ring.nreplicas, ring.hasher) for name, addr := range opt.Addrs { clopt := opt.clientOptions() clopt.Addr = addr ring.addClient(name, NewClient(clopt)) } go ring.heartbeat() return ring }