Merge pull request #759 from harshavardhana/pr_out_heal_buckets_upon_init_if_needed_adding_new_disks_and_hup_works

Heal buckets upon init if needed, adding new disks and HUP works
master
Harshavardhana 9 years ago
commit dc11a411c7
  1. 1
      pkg/donut/donut-v2.go
  2. 54
      pkg/donut/heal.go
  3. 6
      pkg/donut/management.go

@ -119,6 +119,7 @@ func New() (Interface, error) {
newBucket.partMetadata = make(map[string]map[int]PartMetadata)
a.storedBuckets.Set(k, newBucket)
}
a.Heal()
}
return a, nil
}

@ -25,11 +25,15 @@ import (
"github.com/minio/minio/pkg/iodine"
)
// Heal heal an existing donut
func (donut API) Heal() error {
// healBuckets heal bucket slices
func (donut API) healBuckets() error {
if err := donut.listDonutBuckets(); err != nil {
return iodine.New(err, nil)
}
bucketMetadata, err := donut.getDonutBucketMetadata()
if err != nil {
return iodine.New(err, nil)
}
disks := make(map[int]disk.Disk)
for _, node := range donut.nodes {
nDisks, err := node.ListDisks()
@ -40,42 +44,26 @@ func (donut API) Heal() error {
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 disk.IsUsable() {
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 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
}

@ -73,3 +73,9 @@ func (donut API) DetachNode(hostname string) error {
func (donut API) Rebalance() error {
return iodine.New(APINotImplemented{API: "management.Rebalance"}, nil)
}
// Heal - heal your donuts
func (donut API) Heal() error {
// TODO handle data heal
return donut.healBuckets()
}

Loading…
Cancel
Save