From a2c205ff2e9ea296e01c0659c912deaa9fa5a015 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 24 Jun 2015 20:34:20 -0700 Subject: [PATCH] Use external package disk for donut. --- pkg/storage/donut/donut.go | 14 ++++++++---- pkg/storage/donut/donut_bucket.go | 4 ++-- pkg/storage/donut/donut_bucket_internal.go | 14 ++++++------ pkg/storage/donut/donut_node.go | 21 +++++++++-------- pkg/storage/donut/donut_public_interfaces.go | 24 ++++---------------- pkg/storage/donut/donut_rebalance.go | 3 ++- pkg/storage/donut/management.go | 10 ++++---- pkg/storage/donut/objectstorage_internal.go | 14 ++++++------ 8 files changed, 49 insertions(+), 55 deletions(-) diff --git a/pkg/storage/donut/donut.go b/pkg/storage/donut/donut.go index 23a0231fb..cbdcb0093 100644 --- a/pkg/storage/donut/donut.go +++ b/pkg/storage/donut/donut.go @@ -16,7 +16,10 @@ package donut -import "github.com/minio/minio/pkg/iodine" +import ( + "github.com/minio/minio/pkg/iodine" + "github.com/minio/minio/pkg/storage/donut/disk" +) // donut struct internal data type donut struct { @@ -47,16 +50,17 @@ func (d donut) attachDonutNode(hostname string, disks []string) error { if err != nil { return iodine.New(err, nil) } - for i, disk := range disks { + donutName := d.name + for i, d := range disks { // Order is necessary for maps, keep order number separately - newDisk, err := NewDisk(disk, i) + newDisk, err := disk.New(d) if err != nil { return iodine.New(err, nil) } - if err := newDisk.MakeDir(d.name); err != nil { + if err := newDisk.MakeDir(donutName); err != nil { return iodine.New(err, nil) } - if err := node.AttachDisk(newDisk); err != nil { + if err := node.AttachDisk(newDisk, i); err != nil { return iodine.New(err, nil) } } diff --git a/pkg/storage/donut/donut_bucket.go b/pkg/storage/donut/donut_bucket.go index e94ff6de4..f12d6fe18 100644 --- a/pkg/storage/donut/donut_bucket.go +++ b/pkg/storage/donut/donut_bucket.go @@ -73,8 +73,8 @@ func (b bucket) ListObjects() (map[string]object, error) { if err != nil { return nil, iodine.New(err, nil) } - for _, disk := range disks { - bucketSlice := fmt.Sprintf("%s$%d$%d", b.name, nodeSlice, disk.GetOrder()) + for order, disk := range disks { + bucketSlice := fmt.Sprintf("%s$%d$%d", b.name, nodeSlice, order) bucketPath := filepath.Join(b.donutName, bucketSlice) objects, err := disk.ListDir(bucketPath) if err != nil { diff --git a/pkg/storage/donut/donut_bucket_internal.go b/pkg/storage/donut/donut_bucket_internal.go index deb6b898e..b383545a3 100644 --- a/pkg/storage/donut/donut_bucket_internal.go +++ b/pkg/storage/donut/donut_bucket_internal.go @@ -273,14 +273,14 @@ func (b bucket) getDiskReaders(objectName, objectMeta string) ([]io.ReadCloser, return nil, iodine.New(err, nil) } readers = make([]io.ReadCloser, len(disks)) - for _, disk := range disks { - bucketSlice := fmt.Sprintf("%s$%d$%d", b.name, nodeSlice, disk.GetOrder()) + 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.OpenFile(objectPath) if err != nil { return nil, iodine.New(err, nil) } - readers[disk.GetOrder()] = objectSlice + readers[order] = objectSlice } nodeSlice = nodeSlice + 1 } @@ -297,14 +297,14 @@ func (b bucket) getDiskWriters(objectName, objectMeta string) ([]io.WriteCloser, return nil, iodine.New(err, nil) } writers = make([]io.WriteCloser, len(disks)) - for _, disk := range disks { - bucketSlice := fmt.Sprintf("%s$%d$%d", b.name, nodeSlice, disk.GetOrder()) + 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.MakeFile(objectPath) + objectSlice, err := disk.CreateFile(objectPath) if err != nil { return nil, iodine.New(err, nil) } - writers[disk.GetOrder()] = objectSlice + writers[order] = objectSlice } nodeSlice = nodeSlice + 1 } diff --git a/pkg/storage/donut/donut_node.go b/pkg/storage/donut/donut_node.go index ffb49ff59..7b55df81b 100644 --- a/pkg/storage/donut/donut_node.go +++ b/pkg/storage/donut/donut_node.go @@ -16,12 +16,15 @@ package donut -import "github.com/minio/minio/pkg/iodine" +import ( + "github.com/minio/minio/pkg/iodine" + "github.com/minio/minio/pkg/storage/donut/disk" +) // node struct internal type node struct { hostname string - disks map[string]Disk + disks map[int]disk.Disk } // NewNode - instantiates a new node @@ -29,7 +32,7 @@ func NewNode(hostname string) (Node, error) { if hostname == "" { return nil, iodine.New(InvalidArgument{}, nil) } - disks := make(map[string]Disk) + disks := make(map[int]disk.Disk) n := node{ hostname: hostname, disks: disks, @@ -43,22 +46,22 @@ func (n node) GetNodeName() string { } // ListDisks - return number of disks -func (n node) ListDisks() (map[string]Disk, error) { +func (n node) ListDisks() (map[int]disk.Disk, error) { return n.disks, nil } // AttachDisk - attach a disk -func (n node) AttachDisk(disk Disk) error { - if disk == nil { +func (n node) AttachDisk(disk disk.Disk, diskOrder int) error { + if diskOrder < 0 { return iodine.New(InvalidArgument{}, nil) } - n.disks[disk.GetPath()] = disk + n.disks[diskOrder] = disk return nil } // DetachDisk - detach a disk -func (n node) DetachDisk(disk Disk) error { - delete(n.disks, disk.GetPath()) +func (n node) DetachDisk(diskOrder int) error { + delete(n.disks, diskOrder) return nil } diff --git a/pkg/storage/donut/donut_public_interfaces.go b/pkg/storage/donut/donut_public_interfaces.go index 5e513b7e8..582b36e1d 100644 --- a/pkg/storage/donut/donut_public_interfaces.go +++ b/pkg/storage/donut/donut_public_interfaces.go @@ -18,7 +18,8 @@ package donut import ( "io" - "os" + + "github.com/minio/minio/pkg/storage/donut/disk" ) // Collection of Donut specification interfaces @@ -61,26 +62,11 @@ type Management interface { // Node interface for node management type Node interface { - ListDisks() (map[string]Disk, error) - AttachDisk(disk Disk) error - DetachDisk(disk Disk) error + ListDisks() (map[int]disk.Disk, error) + AttachDisk(disk disk.Disk, diskOrder int) error + DetachDisk(diskOrder int) error GetNodeName() string SaveConfig() error LoadConfig() error } - -// Disk interface for disk management -type Disk interface { - MakeDir(dirname string) error - - ListDir(dirname string) ([]os.FileInfo, error) - ListFiles(dirname string) ([]os.FileInfo, error) - - MakeFile(path string) (*os.File, error) - OpenFile(path string) (*os.File, error) - - GetPath() string - GetOrder() int - GetFSInfo() map[string]string -} diff --git a/pkg/storage/donut/donut_rebalance.go b/pkg/storage/donut/donut_rebalance.go index 4c4a85583..3d47f2a32 100644 --- a/pkg/storage/donut/donut_rebalance.go +++ b/pkg/storage/donut/donut_rebalance.go @@ -22,12 +22,13 @@ import ( "strings" "github.com/minio/minio/pkg/iodine" + "github.com/minio/minio/pkg/storage/donut/disk" ) // Rebalance - func (d donut) Rebalance() error { var totalOffSetLength int - var newDisks []Disk + var newDisks []disk.Disk var existingDirs []os.FileInfo for _, node := range d.nodes { disks, err := node.ListDisks() diff --git a/pkg/storage/donut/management.go b/pkg/storage/donut/management.go index 0f287d0fe..8bdb2a8ff 100644 --- a/pkg/storage/donut/management.go +++ b/pkg/storage/donut/management.go @@ -21,8 +21,8 @@ func (d donut) Info() (nodeDiskMap map[string][]string, err error) { return nil, iodine.New(err, nil) } diskList := make([]string, len(disks)) - for diskName, disk := range disks { - diskList[disk.GetOrder()] = diskName + for diskOrder, disk := range disks { + diskList[diskOrder] = disk.GetPath() } nodeDiskMap[nodeName] = diskList } @@ -52,14 +52,14 @@ func (d donut) SaveConfig() error { if err != nil { return iodine.New(err, nil) } - for _, disk := range disks { + for order, disk := range disks { donutConfigPath := filepath.Join(d.name, donutConfig) - donutConfigWriter, err := disk.MakeFile(donutConfigPath) + donutConfigWriter, err := disk.CreateFile(donutConfigPath) defer donutConfigWriter.Close() if err != nil { return iodine.New(err, nil) } - nodeDiskMap[hostname][disk.GetOrder()] = disk.GetPath() + nodeDiskMap[hostname][order] = disk.GetPath() jenc := json.NewEncoder(donutConfigWriter) if err := jenc.Encode(nodeDiskMap); err != nil { return iodine.New(err, nil) diff --git a/pkg/storage/donut/objectstorage_internal.go b/pkg/storage/donut/objectstorage_internal.go index 5a44c252d..107f271b9 100644 --- a/pkg/storage/donut/objectstorage_internal.go +++ b/pkg/storage/donut/objectstorage_internal.go @@ -38,12 +38,12 @@ func (d donut) getBucketMetadataWriters() ([]io.WriteCloser, error) { return nil, iodine.New(err, nil) } writers = make([]io.WriteCloser, len(disks)) - for _, disk := range disks { - bucketMetaDataWriter, err := disk.MakeFile(filepath.Join(d.name, bucketMetadataConfig)) + for order, disk := range disks { + bucketMetaDataWriter, err := disk.CreateFile(filepath.Join(d.name, bucketMetadataConfig)) if err != nil { return nil, iodine.New(err, nil) } - writers[disk.GetOrder()] = bucketMetaDataWriter + writers[order] = bucketMetaDataWriter } } return writers, nil @@ -57,12 +57,12 @@ func (d donut) getBucketMetadataReaders() ([]io.ReadCloser, error) { return nil, iodine.New(err, nil) } readers = make([]io.ReadCloser, len(disks)) - for _, disk := range disks { + for order, disk := range disks { bucketMetaDataReader, err := disk.OpenFile(filepath.Join(d.name, bucketMetadataConfig)) if err != nil { return nil, iodine.New(err, nil) } - readers[disk.GetOrder()] = bucketMetaDataReader + readers[order] = bucketMetaDataReader } } return readers, nil @@ -123,8 +123,8 @@ func (d donut) makeDonutBucket(bucketName, acl string) error { if err != nil { return iodine.New(err, nil) } - for _, disk := range disks { - bucketSlice := fmt.Sprintf("%s$%d$%d", bucketName, nodeNumber, disk.GetOrder()) + for order, disk := range disks { + bucketSlice := fmt.Sprintf("%s$%d$%d", bucketName, nodeNumber, order) err := disk.MakeDir(filepath.Join(d.name, bucketSlice)) if err != nil { return iodine.New(err, nil)