Exemple #1
0
func (t *Topology) PickForWrite(count int, option *VolumeGrowOption) (string, int, *DataNode, error) {
	vid, count, datanodes, err := t.GetVolumeLayout(option.Collection, option.ReplicaPlacement).PickForWrite(count, option)
	if err != nil || datanodes.Length() == 0 {
		return "", 0, nil, errors.New("No writable volumes avalable!")
	}
	fileId, count := t.Sequence.NextFileId(count)
	return storage.NewFileId(*vid, fileId, rand.Uint32()).String(), count, datanodes.Head(), nil
}
Exemple #2
0
func (t *Topology) PickForWrite(repType storage.ReplicationType, count int, dataCenter string) (string, int, *DataNode, error) {
	replicationTypeIndex := repType.GetReplicationLevelIndex()
	if t.replicaType2VolumeLayout[replicationTypeIndex] == nil {
		t.replicaType2VolumeLayout[replicationTypeIndex] = NewVolumeLayout(repType, t.volumeSizeLimit, t.pulse)
	}
	vid, count, datanodes, err := t.replicaType2VolumeLayout[replicationTypeIndex].PickForWrite(count, dataCenter)
	if err != nil || datanodes.Length() == 0 {
		return "", 0, nil, errors.New("No writable volumes avalable!")
	}
	fileId, count := t.sequence.NextFileId(count)
	return storage.NewFileId(*vid, fileId, rand.Uint32()).String(), count, datanodes.Head(), nil
}
Exemple #3
0
func walker(vid storage.VolumeId, n *storage.Needle, version storage.Version) (err error) {
	key := storage.NewFileId(vid, n.Id, n.Cookie).String()
	if tarFh != nil {
		fnTmplBuf.Reset()
		if err = fnTmpl.Execute(fnTmplBuf,
			nameParams{Name: string(n.Name),
				Id:   n.Id,
				Mime: string(n.Mime),
				Key:  key,
			},
		); err != nil {
			return err
		}
		nm := fnTmplBuf.String()

		if n.IsGzipped() && path.Ext(nm) != ".gz" {
			nm = nm + ".gz"
		}

		tarHeader.Name, tarHeader.Size = nm, int64(len(n.Data))
		if err = tarFh.WriteHeader(&tarHeader); err != nil {
			return err
		}
		_, err = tarFh.Write(n.Data)
	} else {
		size := n.DataSize
		if version == storage.Version1 {
			size = n.Size
		}
		fmt.Printf("key=%s Name=%s Size=%d gzip=%t mime=%s\n",
			key,
			n.Name,
			size,
			n.IsGzipped(),
			n.Mime,
		)
	}
	return
}