Exemplo n.º 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
}
Exemplo n.º 2
0
// getBucketMetadataWriters -
func (donut API) getBucketMetadataWriters() ([]io.WriteCloser, *probe.Error) {
	var writers []io.WriteCloser
	for _, node := range donut.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(donut.config.DonutName, bucketMetadataConfig))
			if err != nil {
				return nil, err.Trace()
			}
			writers[order] = bucketMetaDataWriter
		}
	}
	return writers, nil
}
Exemplo 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.donutName, bucketSlice, objectName, objectMeta)
			objectSlice, err := disk.CreateFile(objectPath)
			if err != nil {
				return nil, err.Trace()
			}
			writers[order] = objectSlice
		}
		nodeSlice = nodeSlice + 1
	}
	return writers, nil
}
Exemplo n.º 4
0
// SaveConfig - save donut configuration
func (donut API) SaveConfig() error {
	nodeDiskMap := make(map[string][]string)
	for hostname, node := range donut.nodes {
		disks, err := node.ListDisks()
		if err != nil {
			return iodine.New(err, nil)
		}
		for order, disk := range disks {
			donutConfigPath := filepath.Join(donut.config.DonutName, donutConfig)
			donutConfigWriter, err := disk.CreateFile(donutConfigPath)
			defer donutConfigWriter.Close()
			if err != nil {
				return iodine.New(err, nil)
			}
			nodeDiskMap[hostname][order] = disk.GetPath()
			jenc := json.NewEncoder(donutConfigWriter)
			if err := jenc.Encode(nodeDiskMap); err != nil {
				return iodine.New(err, nil)
			}
		}
	}
	return nil
}