Пример #1
0
// Heal heal an existing donut
func (donut API) Heal() error {
	if err := donut.listDonutBuckets(); err != nil {
		return iodine.New(err, nil)
	}
	disks := make(map[int]disk.Disk)
	for _, node := range donut.nodes {
		nDisks, err := node.ListDisks()
		if err != nil {
			return iodine.New(err, nil)
		}
		for k, v := range nDisks {
			disks[k] = v
		}
	}

	missingDisks := make(map[int]disk.Disk)
	for order, disk := range disks {
		if !disk.IsUsable() {
			missingDisks[order] = disk
		}
	}

	bucketMetadata, err := donut.getDonutBucketMetadata()
	if err != nil {
		return iodine.New(err, nil)
	}

	for _, disk := range missingDisks {
		disk.MakeDir(donut.config.DonutName)
		bucketMetadataWriter, err := disk.CreateFile(filepath.Join(donut.config.DonutName, bucketMetadataConfig))
		if err != nil {
			return iodine.New(err, nil)
		}
		defer bucketMetadataWriter.Close()
		jenc := json.NewEncoder(bucketMetadataWriter)
		if err := jenc.Encode(bucketMetadata); err != nil {
			return iodine.New(err, nil)
		}
	}

	for order, disk := range missingDisks {
		for bucket := range bucketMetadata.Buckets {
			bucketSlice := fmt.Sprintf("%s$0$%d", bucket, order) // TODO handle node slices
			err := disk.MakeDir(filepath.Join(donut.config.DonutName, bucketSlice))
			if err != nil {
				return iodine.New(err, nil)
			}
		}
	}

	return nil
	// TODO heal data
}
Пример #2
0
// makeDonutBucket -
func (donut API) makeDonutBucket(bucketName, acl string) *probe.Error {
	if err := donut.listDonutBuckets(); err != nil {
		return err.Trace()
	}
	if _, ok := donut.buckets[bucketName]; ok {
		return probe.NewError(BucketExists{Bucket: bucketName})
	}
	bkt, bucketMetadata, err := newBucket(bucketName, acl, donut.config.DonutName, donut.nodes)
	if err != nil {
		return err.Trace()
	}
	nodeNumber := 0
	donut.buckets[bucketName] = bkt
	for _, node := range donut.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(donut.config.DonutName, bucketSlice))
			if err != nil {
				return err.Trace()
			}
		}
		nodeNumber = nodeNumber + 1
	}
	var metadata *AllBuckets
	metadata, err = donut.getDonutBucketMetadata()
	if err != nil {
		if os.IsNotExist(err.ToGoError()) {
			metadata = new(AllBuckets)
			metadata.Buckets = make(map[string]BucketMetadata)
			metadata.Buckets[bucketName] = bucketMetadata
			err = donut.setDonutBucketMetadata(metadata)
			if err != nil {
				return err.Trace()
			}
			return nil
		}
		return err.Trace()
	}
	metadata.Buckets[bucketName] = bucketMetadata
	err = donut.setDonutBucketMetadata(metadata)
	if err != nil {
		return err.Trace()
	}
	return nil
}
Пример #3
0
// makeDonutBucket -
func (donut API) makeDonutBucket(bucketName, acl string) error {
	if err := donut.listDonutBuckets(); err != nil {
		return iodine.New(err, nil)
	}
	if _, ok := donut.buckets[bucketName]; ok {
		return iodine.New(BucketExists{Bucket: bucketName}, nil)
	}
	bucket, bucketMetadata, err := newBucket(bucketName, acl, donut.config.DonutName, donut.nodes)
	if err != nil {
		return iodine.New(err, nil)
	}
	nodeNumber := 0
	donut.buckets[bucketName] = bucket
	for _, node := range donut.nodes {
		disks, err := node.ListDisks()
		if err != nil {
			return iodine.New(err, nil)
		}
		for order, disk := range disks {
			bucketSlice := fmt.Sprintf("%s$%d$%d", bucketName, nodeNumber, order)
			err := disk.MakeDir(filepath.Join(donut.config.DonutName, bucketSlice))
			if err != nil {
				return iodine.New(err, nil)
			}
		}
		nodeNumber = nodeNumber + 1
	}
	metadata, err := donut.getDonutBucketMetadata()
	if err != nil {
		if os.IsNotExist(iodine.ToError(err)) {
			metadata := new(AllBuckets)
			metadata.Buckets = make(map[string]BucketMetadata)
			metadata.Buckets[bucketName] = bucketMetadata
			err = donut.setDonutBucketMetadata(metadata)
			if err != nil {
				return iodine.New(err, nil)
			}
			return nil
		}
		return iodine.New(err, nil)
	}
	metadata.Buckets[bucketName] = bucketMetadata
	err = donut.setDonutBucketMetadata(metadata)
	if err != nil {
		return iodine.New(err, nil)
	}
	return nil
}