Heal buckets upon init if needed, adding new disks and HUP works

master
Harshavardhana 10 years ago
parent 00a701a155
commit 5507a39840
  1. 1
      pkg/donut/donut-v2.go
  2. 28
      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) newBucket.partMetadata = make(map[string]map[int]PartMetadata)
a.storedBuckets.Set(k, newBucket) a.storedBuckets.Set(k, newBucket)
} }
a.Heal()
} }
return a, nil return a, nil
} }

@ -25,11 +25,15 @@ import (
"github.com/minio/minio/pkg/iodine" "github.com/minio/minio/pkg/iodine"
) )
// Heal heal an existing donut // healBuckets heal bucket slices
func (donut API) Heal() error { func (donut API) healBuckets() error {
if err := donut.listDonutBuckets(); err != nil { if err := donut.listDonutBuckets(); err != nil {
return iodine.New(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) disks := make(map[int]disk.Disk)
for _, node := range donut.nodes { for _, node := range donut.nodes {
nDisks, err := node.ListDisks() nDisks, err := node.ListDisks()
@ -40,20 +44,8 @@ func (donut API) Heal() error {
disks[k] = v disks[k] = v
} }
} }
missingDisks := make(map[int]disk.Disk)
for order, disk := range disks { for order, disk := range disks {
if !disk.IsUsable() { 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) disk.MakeDir(donut.config.DonutName)
bucketMetadataWriter, err := disk.CreateFile(filepath.Join(donut.config.DonutName, bucketMetadataConfig)) bucketMetadataWriter, err := disk.CreateFile(filepath.Join(donut.config.DonutName, bucketMetadataConfig))
if err != nil { if err != nil {
@ -64,9 +56,6 @@ func (donut API) Heal() error {
if err := jenc.Encode(bucketMetadata); err != nil { if err := jenc.Encode(bucketMetadata); err != nil {
return iodine.New(err, nil) return iodine.New(err, nil)
} }
}
for order, disk := range missingDisks {
for bucket := range bucketMetadata.Buckets { for bucket := range bucketMetadata.Buckets {
bucketSlice := fmt.Sprintf("%s$0$%d", bucket, order) // TODO handle node slices bucketSlice := fmt.Sprintf("%s$0$%d", bucket, order) // TODO handle node slices
err := disk.MakeDir(filepath.Join(donut.config.DonutName, bucketSlice)) err := disk.MakeDir(filepath.Join(donut.config.DonutName, bucketSlice))
@ -75,7 +64,6 @@ func (donut API) Heal() error {
} }
} }
} }
}
return nil return nil
// TODO heal data
} }

@ -73,3 +73,9 @@ func (donut API) DetachNode(hostname string) error {
func (donut API) Rebalance() error { func (donut API) Rebalance() error {
return iodine.New(APINotImplemented{API: "management.Rebalance"}, nil) 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