Пример #1
0
func NewClient(cfg torus.Config, srv *Server) *Client {
	return &Client{
		cfg:  cfg,
		uuid: metadata.MakeUUID(),
		srv:  srv,
	}
}
Пример #2
0
func main() {
	var err error
	flag.Parse()
	if *replicationEnd == 0 {
		*replicationEnd = *replication
	}
	nPeers := *nodes + *delta
	if *delta <= 0 {
		nPeers = *nodes
	}
	peers = make([]*models.PeerInfo, nPeers)
	for i := 0; i < nPeers; i++ {
		peers[i] = &models.PeerInfo{
			UUID:        metadata.MakeUUID(),
			TotalBlocks: 100 * 1024 * 1024 * 1024, // 100giga-blocks for testing
		}
	}
	blockSize, err = humanize.ParseBytes(*blockSizeStr)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error parsing block-size: %s\n", err)
		os.Exit(1)
	}
	totalData, err = humanize.ParseBytes(*totalDataStr)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error parsing total-data: %s\n", err)
		os.Exit(1)
	}
	nblocks := totalData / blockSize
	var blocks []torus.BlockRef
	inode := torus.INodeID(1)
	part := float64(*partition) / 100.0
	for len(blocks) < int(nblocks) {
		perFile := rand.Intn(1000) + 1
		f := rand.NormFloat64()
		var out []torus.BlockRef
		if f < part {
			out, inode = generateRewrittenFile(torus.VolumeID(1), inode, perFile)
		} else {
			out, inode = generateLinearFile(torus.VolumeID(1), inode, perFile)
		}
		blocks = append(blocks, out...)
	}
	r1, r2 := createRings()
	fmt.Printf("Unique blocks: %d\n", len(blocks))
	cluster := assignData(blocks, r1)
	fmt.Println("@START *****")
	cluster.printBalance()
	newc, rebalance := cluster.Rebalance(r1, r2)
	fmt.Println("@END *****")
	newc.printBalance()
	fmt.Println("Changes:")
	rebalance.printStats()
}
Пример #3
0
func newEtcdMetadata(cfg torus.Config) (torus.MetadataService, error) {
	var uuid string
	var err error
	if cfg.DataDir == "" {
		uuid = metadata.MakeUUID()
	} else {
		uuid, err = metadata.GetUUID(cfg.DataDir)
	}
	if err != nil {
		return nil, err
	}

	v3cfg := etcdv3.Config{Endpoints: []string{cfg.MetadataAddress}, TLS: cfg.TLS}
	client, err := etcdv3.New(v3cfg)
	if err != nil {
		return nil, err
	}

	e := &Etcd{
		cfg:          cfg,
		Client:       client,
		volumesCache: make(map[string]*models.Volume),
		uuid:         uuid,
	}
	// We do this so that referring to e, you can either call the functions
	// directly (with a nil context) or, create another reference using
	// WithContext(), below.
	e.etcdCtx.etcd = e
	err = e.getGlobalMetadata()
	if err != nil {
		return nil, err
	}
	if err = e.watchRingUpdates(); err != nil {
		return nil, err
	}
	return e, nil
}