Example #1
0
func (t *Topology) PickForWrite(repType storage.ReplicationType, count int) (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)
	if err != nil {
		return "", 0, nil, errors.New("No writable volumes avalable!")
	}
	fileId, count := t.sequence.NextFileId(count)
	return directory.NewFileId(*vid, fileId, rand.Uint32()).String(), count, datanodes.Head(), nil
}
Example #2
0
func walker(vid storage.VolumeId, n *storage.Needle, version storage.Version) (err error) {
	key := directory.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
}