示例#1
0
文件: ring.go 项目: ckeyer/go-ci
// rebalance removes dead shards from the c.
func (c *Ring) rebalance() {
	defer c.mu.Unlock()
	c.mu.Lock()

	c.hash = consistenthash.New(c.nreplicas, nil)
	for name, shard := range c.shards {
		if shard.IsUp() {
			c.hash.Add(name)
		}
	}
}
示例#2
0
文件: ring.go 项目: ckeyer/go-ci
func NewRing(opt *RingOptions) *Ring {
	const nreplicas = 100
	opt.init()
	ring := &Ring{
		opt:       opt,
		nreplicas: nreplicas,

		hash:   consistenthash.New(nreplicas, nil),
		shards: make(map[string]*ringShard),

		cmdsInfoOnce: new(sync.Once),
	}
	ring.cmdable.process = ring.Process
	for name, addr := range opt.Addrs {
		clopt := opt.clientOptions()
		clopt.Addr = addr
		ring.addClient(name, NewClient(clopt))
	}
	go ring.heartbeat()
	return ring
}