diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index b92416f4..ed8adb71 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -28,7 +28,7 @@ }, { "ImportPath": "github.com/minio-io/donut", - "Rev": "aac8dddef7aebd6e2e5953038b2f4a0cb08768ee" + "Rev": "f1350882976ab553b241d86cdb8b992e7c9d9c63" }, { "ImportPath": "github.com/minio-io/erasure", diff --git a/Godeps/_workspace/src/github.com/minio-io/donut/bucket.go b/Godeps/_workspace/src/github.com/minio-io/donut/bucket.go index cc2efe40..4bb3e6b9 100644 --- a/Godeps/_workspace/src/github.com/minio-io/donut/bucket.go +++ b/Godeps/_workspace/src/github.com/minio-io/donut/bucket.go @@ -56,10 +56,6 @@ func (b bucket) ListNodes() (map[string]Node, error) { return b.nodes, nil } -func (b bucket) GetBucketName() string { - return b.name -} - func (b bucket) ListObjects() (map[string]Object, error) { nodeSlice := 0 for _, node := range b.nodes { @@ -117,7 +113,7 @@ func (b bucket) WriteObjectMetadata(objectName string, objectMetadata map[string if len(objectMetadata) == 0 { return errors.New("invalid argument") } - objectMetadataWriters, err := b.getDiskWriters(objectName, "objectMetadata.json") + objectMetadataWriters, err := b.getDiskWriters(objectName, objectMetadataConfig) if err != nil { return err } @@ -137,7 +133,7 @@ func (b bucket) WriteDonutObjectMetadata(objectName string, donutObjectMetadata if len(donutObjectMetadata) == 0 { return errors.New("invalid argument") } - donutObjectMetadataWriters, err := b.getDiskWriters(objectName, "donutObjectMetadata.json") + donutObjectMetadataWriters, err := b.getDiskWriters(objectName, donutObjectMetadataConfig) if err != nil { return err } diff --git a/Godeps/_workspace/src/github.com/minio-io/donut/cmd/donut-cli/donut-cmd-common.go b/Godeps/_workspace/src/github.com/minio-io/donut/cmd/donut-cli/donut-cmd-common.go index 1105f9d4..d79243df 100644 --- a/Godeps/_workspace/src/github.com/minio-io/donut/cmd/donut-cli/donut-cmd-common.go +++ b/Godeps/_workspace/src/github.com/minio-io/donut/cmd/donut-cli/donut-cmd-common.go @@ -99,3 +99,12 @@ func isValidDonutName(donutName string) bool { } return true } + +// getNodeMap - get a node and disk map through nodeConfig struct +func getNodeMap(node map[string]nodeConfig) map[string][]string { + nodes := make(map[string][]string) + for k, v := range node { + nodes[k] = v.ActiveDisks + } + return nodes +} diff --git a/Godeps/_workspace/src/github.com/minio-io/donut/cmd/donut-cli/donut-cmd-info.go b/Godeps/_workspace/src/github.com/minio-io/donut/cmd/donut-cli/donut-cmd-info.go index 06b0074b..2db70f5c 100644 --- a/Godeps/_workspace/src/github.com/minio-io/donut/cmd/donut-cli/donut-cmd-info.go +++ b/Godeps/_workspace/src/github.com/minio-io/donut/cmd/donut-cli/donut-cmd-info.go @@ -71,11 +71,7 @@ func doInfoDonutCmd(c *cli.Context) { if _, ok := mcDonutConfigData.Donuts[donutName]; !ok { log.Fatalln("donut does not exist") } - nodes := make(map[string][]string) - for k, v := range mcDonutConfigData.Donuts[donutName].Node { - nodes[k] = v.ActiveDisks - } - d, err := donut.NewDonut(donutName, nodes) + d, err := donut.NewDonut(donutName, getNodeMap(mcDonutConfigData.Donuts[donutName].Node)) if err != nil { log.Fatalln(err) } diff --git a/Godeps/_workspace/src/github.com/minio-io/donut/cmd/donut-cli/donut-cmd-options.go b/Godeps/_workspace/src/github.com/minio-io/donut/cmd/donut-cli/donut-cmd-options.go index 291eb869..5fa40d48 100644 --- a/Godeps/_workspace/src/github.com/minio-io/donut/cmd/donut-cli/donut-cmd-options.go +++ b/Godeps/_workspace/src/github.com/minio-io/donut/cmd/donut-cli/donut-cmd-options.go @@ -93,6 +93,3 @@ var donutOptions = []cli.Command{ func doHealDonutCmd(c *cli.Context) { } - -func doRebalanceDonutCmd(c *cli.Context) { -} diff --git a/Godeps/_workspace/src/github.com/minio-io/donut/cmd/donut-cli/donut-cmd-rebalance.go b/Godeps/_workspace/src/github.com/minio-io/donut/cmd/donut-cli/donut-cmd-rebalance.go new file mode 100644 index 00000000..fcfa5779 --- /dev/null +++ b/Godeps/_workspace/src/github.com/minio-io/donut/cmd/donut-cli/donut-cmd-rebalance.go @@ -0,0 +1,32 @@ +package main + +import ( + "log" + + "github.com/minio-io/cli" + "github.com/minio-io/donut" +) + +func doRebalanceDonutCmd(c *cli.Context) { + if !c.Args().Present() { + log.Fatalln("no args?") + } + donutName := c.Args().First() + if !isValidDonutName(donutName) { + log.Fatalln("Invalid donutName") + } + mcDonutConfigData, err := loadDonutConfig() + if err != nil { + log.Fatalln(err) + } + if _, ok := mcDonutConfigData.Donuts[donutName]; !ok { + log.Fatalln("donut does not exist") + } + d, err := donut.NewDonut(donutName, getNodeMap(mcDonutConfigData.Donuts[donutName].Node)) + if err != nil { + log.Fatalln(err) + } + if err := d.Rebalance(); err != nil { + log.Fatalln(err) + } +} diff --git a/Godeps/_workspace/src/github.com/minio-io/donut/donut.go b/Godeps/_workspace/src/github.com/minio-io/donut/donut.go index c9955078..0fba7fdd 100644 --- a/Godeps/_workspace/src/github.com/minio-io/donut/donut.go +++ b/Godeps/_workspace/src/github.com/minio-io/donut/donut.go @@ -17,17 +17,13 @@ package donut import ( + "encoding/json" "errors" "fmt" "path" "strings" ) -// Total allowed disks per node -const ( - disksPerNode = 16 -) - type donut struct { name string buckets map[string]Bucket @@ -63,7 +59,7 @@ func (d donut) attachDonutNode(hostname string, disks []string) error { // NewDonut - instantiate a new donut func NewDonut(donutName string, nodeDiskMap map[string][]string) (Donut, error) { if donutName == "" || len(nodeDiskMap) == 0 { - return nil, errors.New("invalid arguments") + return nil, errors.New("invalid argument") } nodes := make(map[string]Node) buckets := make(map[string]Bucket) @@ -73,7 +69,7 @@ func NewDonut(donutName string, nodeDiskMap map[string][]string) (Donut, error) buckets: buckets, } for k, v := range nodeDiskMap { - if len(v) > disksPerNode || len(v) == 0 { + if len(v) == 0 { return nil, errors.New("invalid number of disks per node") } err := d.attachDonutNode(k, v) @@ -130,12 +126,13 @@ func (d donut) ListBuckets() (map[string]Bucket, error) { if len(splitDir) < 3 { return nil, errors.New("corrupted backend") } + bucketName := splitDir[0] // we dont need this NewBucket once we cache these - bucket, err := NewBucket(splitDir[0], d.name, d.nodes) + bucket, err := NewBucket(bucketName, d.name, d.nodes) if err != nil { return nil, err } - d.buckets[bucket.GetBucketName()] = bucket + d.buckets[bucketName] = bucket } } } @@ -174,10 +171,30 @@ func (d donut) DetachNode(node Node) error { return nil } -func (d donut) SaveConfig() ([]byte, error) { - return nil, errors.New("Not Implemented") +func (d donut) SaveConfig() error { + nodeDiskMap := make(map[string][]string) + for hostname, node := range d.nodes { + disks, err := node.ListDisks() + if err != nil { + return err + } + for _, disk := range disks { + donutConfigPath := path.Join(d.name, donutConfig) + donutConfigWriter, err := disk.MakeFile(donutConfigPath) + defer donutConfigWriter.Close() + if err != nil { + return err + } + nodeDiskMap[hostname][disk.GetOrder()] = disk.GetPath() + jenc := json.NewEncoder(donutConfigWriter) + if err := jenc.Encode(nodeDiskMap); err != nil { + return err + } + } + } + return nil } -func (d donut) LoadConfig([]byte) error { +func (d donut) LoadConfig() error { return errors.New("Not Implemented") } diff --git a/Godeps/_workspace/src/github.com/minio-io/donut/interfaces.go b/Godeps/_workspace/src/github.com/minio-io/donut/interfaces.go index 5f613db0..96392cda 100644 --- a/Godeps/_workspace/src/github.com/minio-io/donut/interfaces.go +++ b/Godeps/_workspace/src/github.com/minio-io/donut/interfaces.go @@ -25,9 +25,18 @@ import ( // Donut interface type Donut interface { + Storage + Management +} + +// Storage object storage interface +type Storage interface { MakeBucket(bucket string) error ListBuckets() (map[string]Bucket, error) +} +// Management is a donut management system interface +type Management interface { Heal() error Rebalance() error Info() (map[string][]string, error) @@ -35,8 +44,8 @@ type Donut interface { AttachNode(node Node) error DetachNode(node Node) error - SaveConfig() ([]byte, error) - LoadConfig([]byte) error + SaveConfig() error + LoadConfig() error } // Encoder interface @@ -48,8 +57,6 @@ type Encoder interface { // Bucket interface type Bucket interface { - GetBucketName() string - ListNodes() (map[string]Node, error) ListObjects() (map[string]Object, error) @@ -62,7 +69,6 @@ type Bucket interface { // Object interface type Object interface { - GetObjectName() string GetObjectMetadata() (map[string]string, error) GetDonutObjectMetadata() (map[string]string, error) } @@ -94,3 +100,9 @@ type Disk interface { SaveConfig() ([]byte, error) LoadConfig([]byte) error } + +const ( + donutObjectMetadataConfig = "donutObjectMetadata.json" + objectMetadataConfig = "objectMetadata.json" + donutConfig = "donutMetadata.json" +) diff --git a/Godeps/_workspace/src/github.com/minio-io/donut/object.go b/Godeps/_workspace/src/github.com/minio-io/donut/object.go index 481d0b55..ecc2a884 100644 --- a/Godeps/_workspace/src/github.com/minio-io/donut/object.go +++ b/Godeps/_workspace/src/github.com/minio-io/donut/object.go @@ -42,13 +42,9 @@ func NewObject(objectName, p string) (Object, error) { return o, nil } -func (o object) GetObjectName() string { - return o.name -} - func (o object) GetObjectMetadata() (map[string]string, error) { objectMetadata := make(map[string]string) - objectMetadataBytes, err := ioutil.ReadFile(path.Join(o.objectPath, "objectMetadata.json")) + objectMetadataBytes, err := ioutil.ReadFile(path.Join(o.objectPath, objectMetadataConfig)) if err != nil { return nil, err } @@ -61,7 +57,7 @@ func (o object) GetObjectMetadata() (map[string]string, error) { func (o object) GetDonutObjectMetadata() (map[string]string, error) { donutObjectMetadata := make(map[string]string) - donutObjectMetadataBytes, err := ioutil.ReadFile(path.Join(o.objectPath, "donutObjectMetadata.json")) + donutObjectMetadataBytes, err := ioutil.ReadFile(path.Join(o.objectPath, donutObjectMetadataConfig)) if err != nil { return nil, err } diff --git a/Godeps/_workspace/src/github.com/minio-io/donut/rebalance.go b/Godeps/_workspace/src/github.com/minio-io/donut/rebalance.go index e3fc3ce6..6fe87f33 100644 --- a/Godeps/_workspace/src/github.com/minio-io/donut/rebalance.go +++ b/Godeps/_workspace/src/github.com/minio-io/donut/rebalance.go @@ -1,14 +1,37 @@ package donut -import "fmt" +import ( + "fmt" + "os" + "strings" +) func (d donut) Rebalance() error { + var totalOffSetLength int + var newDisks []Disk + var existingDirs []os.FileInfo for _, node := range d.nodes { disks, err := node.ListDisks() if err != nil { return err } - fmt.Println(len(disks)) + totalOffSetLength = len(disks) + fmt.Println(totalOffSetLength) + for _, disk := range disks { + dirs, err := disk.ListDir(d.name) + if err != nil { + return err + } + if len(dirs) == 0 { + newDisks = append(newDisks, disk) + } + existingDirs = append(existingDirs, dirs...) + } + } + for _, dir := range existingDirs { + splits := strings.Split(dir.Name(), "$") + bucketName, segment, offset := splits[0], splits[1], splits[2] + fmt.Println(bucketName, segment, offset) } return nil }