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)
}
示例#2
0
文件: peer.go 项目: coreos/torus
func peerChangePreRun(cmd *cobra.Command, args []string) {
	if allPeers && len(args) > 0 {
		die("can't have both --all-peers and a list of peers")
	}
	mds = mustConnectToMDS()
	peers, err := mds.GetPeers()
	if err != nil {
		die("couldn't get peer list: %v", err)
	}
	var out torus.PeerInfoList
	for _, arg := range args {
		found := false
		for _, p := range peers {
			if p.Address != "" {
				if p.Address == arg {
					out = out.Union(torus.PeerInfoList{p})
					found = true
				} else if p.UUID == arg {
					out = out.Union(torus.PeerInfoList{p})
					found = true
				}
			}
		}
		if !found {
			if !force {
				die("peer %s not currently healthy. To remove, use `--force`", arg)
			}
			out = out.Union(torus.PeerInfoList{&models.PeerInfo{
				UUID: arg,
			}})
		}
	}
	if allPeers {
		for _, p := range peers {
			if p.Address != "" {
				out = out.Union(torus.PeerInfoList{p})
			}
		}
	}
	newPeers = out
}