func TestTinyPeer(t *testing.T) {
	pi := torus.PeerInfoList{
		&models.PeerInfo{
			UUID:        "a",
			TotalBlocks: 20 * 1024 * 1024 * 2,
		},
		&models.PeerInfo{
			UUID:        "b",
			TotalBlocks: 20 * 1024 * 1024 * 2,
		},
		&models.PeerInfo{
			UUID:        "c",
			TotalBlocks: 100 * 1024 * 2,
		},
	}
	k := &ketama{
		version: 1,
		peers:   pi,
		rep:     2,
		ring:    hashring.NewWithWeights(pi.GetWeights()),
	}
	l, err := k.GetPeers(torus.BlockRef{
		INodeRef: torus.NewINodeRef(3, 4),
		Index:    5,
	})
	if err != nil {
		t.Fatal(err)
	}
	t.Log(l.Peers)
}
Esempio n. 2
0
func (f *Feature) SetupRing() {
	if f.Enabled > 0.0 && f.Enabled < 1.0 {
		weights := make(map[string]int)
		weights["enabled"] = int(f.Enabled * 100)
		weights["disabled"] = int((1 - f.Enabled) * 100)
		f.ring = hashring.NewWithWeights(weights)
	}
}
Esempio n. 3
0
func (exp *Experiment) SetupRing() {
	weights := make(map[string]int)

	for _, alt := range exp.Alternatives {
		weights[alt.Name] = alt.Weight
	}

	exp.ring = hashring.NewWithWeights(weights)
}
func (k *ketama) AddPeers(peers torus.PeerInfoList) (torus.Ring, error) {
	newPeers := k.peers.Union(peers)
	if reflect.DeepEqual(newPeers.PeerList(), k.peers.PeerList()) {
		return nil, torus.ErrExists
	}
	newk := &ketama{
		version: k.version + 1,
		rep:     k.rep,
		peers:   newPeers,
		ring:    hashring.NewWithWeights(newPeers.GetWeights()),
	}
	return newk, nil
}
func (k *ketama) RemovePeers(pl torus.PeerList) (torus.Ring, error) {
	newPeers := k.peers.AndNot(pl)
	if len(newPeers) == len(k.Members()) {
		return nil, torus.ErrNotExist
	}

	newk := &ketama{
		version: k.version + 1,
		rep:     k.rep,
		peers:   newPeers,
		ring:    hashring.NewWithWeights(newPeers.GetWeights()),
	}
	return newk, nil
}
func makeKetama(r *models.Ring) (torus.Ring, error) {
	rep := int(r.ReplicationFactor)
	if rep == 0 {
		rep = 1
	}
	pi := torus.PeerInfoList(r.Peers)
	if rep > len(pi) {
		clog.Noticef("Using ring that requests replication level %d, but has only %d peers. Add nodes to match replication.", rep, len(pi))
	}
	return &ketama{
		version: int(r.Version),
		peers:   pi,
		rep:     rep,
		ring:    hashring.NewWithWeights(pi.GetWeights()),
	}, nil
}