Пример #1
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
}
Пример #2
0
// makeXLBucket -
func (xl API) makeXLBucket(bucketName, acl string) *probe.Error {
	if err := xl.listXLBuckets(); err != nil {
		return err.Trace()
	}
	if _, ok := xl.buckets[bucketName]; ok {
		return probe.NewError(BucketExists{Bucket: bucketName})
	}
	bkt, bucketMetadata, err := newBucket(bucketName, acl, xl.config.XLName, xl.nodes)
	if err != nil {
		return err.Trace()
	}
	nodeNumber := 0
	xl.buckets[bucketName] = bkt
	for _, node := range xl.nodes {
		disks := make(map[int]disk.Disk)
		disks, err = node.ListDisks()
		if err != nil {
			return err.Trace()
		}
		for order, disk := range disks {
			bucketSlice := fmt.Sprintf("%s$%d$%d", bucketName, nodeNumber, order)
			err := disk.MakeDir(filepath.Join(xl.config.XLName, bucketSlice))
			if err != nil {
				return err.Trace()
			}
		}
		nodeNumber = nodeNumber + 1
	}
	var metadata *AllBuckets
	metadata, err = xl.getXLBucketMetadata()
	if err != nil {
		if os.IsNotExist(err.ToGoError()) {
			metadata = new(AllBuckets)
			metadata.Buckets = make(map[string]BucketMetadata)
			metadata.Buckets[bucketName] = bucketMetadata
			err = xl.setXLBucketMetadata(metadata)
			if err != nil {
				return err.Trace()
			}
			return nil
		}
		return err.Trace()
	}
	metadata.Buckets[bucketName] = bucketMetadata
	err = xl.setXLBucketMetadata(metadata)
	if err != nil {
		return err.Trace()
	}
	return nil
}