From 5507a3984051406cfb8f23d35bea9eb27e9f7546 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 16 Jul 2015 09:46:38 -0700 Subject: [PATCH] Heal buckets upon init if needed, adding new disks and HUP works --- pkg/donut/donut-v2.go | 1 + pkg/donut/heal.go | 54 ++++++++++++++++------------------------- pkg/donut/management.go | 6 +++++ 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/pkg/donut/donut-v2.go b/pkg/donut/donut-v2.go index 944967fb7..7f65d3ab2 100644 --- a/pkg/donut/donut-v2.go +++ b/pkg/donut/donut-v2.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 } diff --git a/pkg/donut/heal.go b/pkg/donut/heal.go index 12662b25e..acaaf39e2 100644 --- a/pkg/donut/heal.go +++ b/pkg/donut/heal.go @@ -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 } diff --git a/pkg/donut/management.go b/pkg/donut/management.go index 8d8a7834e..4428f75e8 100644 --- a/pkg/donut/management.go +++ b/pkg/donut/management.go @@ -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() +}