Esempio n. 1
0
// getBucketMetadataWriters -
func (xl API) getBucketMetadataWriters() ([]io.WriteCloser, *probe.Error) {
	var writers []io.WriteCloser
	for _, node := range xl.nodes {
		disks, err := node.ListDisks()
		if err != nil {
			return nil, err.Trace()
		}
		writers = make([]io.WriteCloser, len(disks))
		for order, disk := range disks {
			bucketMetaDataWriter, err := disk.CreateFile(filepath.Join(xl.config.XLName, bucketMetadataConfig))
			if err != nil {
				return nil, err.Trace()
			}
			writers[order] = bucketMetaDataWriter
		}
	}
	return writers, nil
}
Esempio n. 2
0
// healBuckets heal bucket slices
func (xl API) healBuckets() *probe.Error {
	if err := xl.listXLBuckets(); err != nil {
		return err.Trace()
	}
	bucketMetadata, err := xl.getXLBucketMetadata()
	if err != nil {
		return err.Trace()
	}
	disks := make(map[int]disk.Disk)
	for _, node := range xl.nodes {
		nDisks, err := node.ListDisks()
		if err != nil {
			return err.Trace()
		}
		for k, v := range nDisks {
			disks[k] = v
		}
	}
	for order, disk := range disks {
		if disk.IsUsable() {
			disk.MakeDir(xl.config.XLName)
			bucketMetadataWriter, err := disk.CreateFile(filepath.Join(xl.config.XLName, bucketMetadataConfig))
			if err != nil {
				return err.Trace()
			}
			defer bucketMetadataWriter.Close()
			jenc := json.NewEncoder(bucketMetadataWriter)
			if err := jenc.Encode(bucketMetadata); err != nil {
				return probe.NewError(err)
			}
			for bucket := range bucketMetadata.Buckets {
				bucketSlice := fmt.Sprintf("%s$0$%d", bucket, order) // TODO handle node slices
				err := disk.MakeDir(filepath.Join(xl.config.XLName, bucketSlice))
				if err != nil {
					return err.Trace()
				}
			}
		}
	}
	return nil
}
Esempio n. 3
0
// getObjectWriters -
func (b bucket) getObjectWriters(objectName, objectMeta string) ([]io.WriteCloser, *probe.Error) {
	var writers []io.WriteCloser
	nodeSlice := 0
	for _, node := range b.nodes {
		disks, err := node.ListDisks()
		if err != nil {
			return nil, err.Trace()
		}
		writers = make([]io.WriteCloser, len(disks))
		for order, disk := range disks {
			bucketSlice := fmt.Sprintf("%s$%d$%d", b.name, nodeSlice, order)
			objectPath := filepath.Join(b.xlName, bucketSlice, objectName, objectMeta)
			objectSlice, err := disk.CreateFile(objectPath)
			if err != nil {
				return nil, err.Trace()
			}
			writers[order] = objectSlice
		}
		nodeSlice = nodeSlice + 1
	}
	return writers, nil
}