Use external package disk for donut.

This commit is contained in:
Harshavardhana 2015-06-24 20:34:20 -07:00
parent 841ff01412
commit a2c205ff2e
8 changed files with 49 additions and 55 deletions

View File

@ -16,7 +16,10 @@
package donut 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 // donut struct internal data
type donut struct { type donut struct {
@ -47,16 +50,17 @@ func (d donut) attachDonutNode(hostname string, disks []string) error {
if err != nil { if err != nil {
return iodine.New(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 // Order is necessary for maps, keep order number separately
newDisk, err := NewDisk(disk, i) newDisk, err := disk.New(d)
if err != nil { if err != nil {
return iodine.New(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) 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) return iodine.New(err, nil)
} }
} }

View File

@ -73,8 +73,8 @@ func (b bucket) ListObjects() (map[string]object, error) {
if err != nil { if err != nil {
return nil, iodine.New(err, nil) return nil, iodine.New(err, nil)
} }
for _, disk := range disks { for order, disk := range disks {
bucketSlice := fmt.Sprintf("%s$%d$%d", b.name, nodeSlice, disk.GetOrder()) bucketSlice := fmt.Sprintf("%s$%d$%d", b.name, nodeSlice, order)
bucketPath := filepath.Join(b.donutName, bucketSlice) bucketPath := filepath.Join(b.donutName, bucketSlice)
objects, err := disk.ListDir(bucketPath) objects, err := disk.ListDir(bucketPath)
if err != nil { if err != nil {

View File

@ -273,14 +273,14 @@ func (b bucket) getDiskReaders(objectName, objectMeta string) ([]io.ReadCloser,
return nil, iodine.New(err, nil) return nil, iodine.New(err, nil)
} }
readers = make([]io.ReadCloser, len(disks)) readers = make([]io.ReadCloser, len(disks))
for _, disk := range disks { for order, disk := range disks {
bucketSlice := fmt.Sprintf("%s$%d$%d", b.name, nodeSlice, disk.GetOrder()) bucketSlice := fmt.Sprintf("%s$%d$%d", b.name, nodeSlice, order)
objectPath := filepath.Join(b.donutName, bucketSlice, objectName, objectMeta) objectPath := filepath.Join(b.donutName, bucketSlice, objectName, objectMeta)
objectSlice, err := disk.OpenFile(objectPath) objectSlice, err := disk.OpenFile(objectPath)
if err != nil { if err != nil {
return nil, iodine.New(err, nil) return nil, iodine.New(err, nil)
} }
readers[disk.GetOrder()] = objectSlice readers[order] = objectSlice
} }
nodeSlice = nodeSlice + 1 nodeSlice = nodeSlice + 1
} }
@ -297,14 +297,14 @@ func (b bucket) getDiskWriters(objectName, objectMeta string) ([]io.WriteCloser,
return nil, iodine.New(err, nil) return nil, iodine.New(err, nil)
} }
writers = make([]io.WriteCloser, len(disks)) writers = make([]io.WriteCloser, len(disks))
for _, disk := range disks { for order, disk := range disks {
bucketSlice := fmt.Sprintf("%s$%d$%d", b.name, nodeSlice, disk.GetOrder()) bucketSlice := fmt.Sprintf("%s$%d$%d", b.name, nodeSlice, order)
objectPath := filepath.Join(b.donutName, bucketSlice, objectName, objectMeta) objectPath := filepath.Join(b.donutName, bucketSlice, objectName, objectMeta)
objectSlice, err := disk.MakeFile(objectPath) objectSlice, err := disk.CreateFile(objectPath)
if err != nil { if err != nil {
return nil, iodine.New(err, nil) return nil, iodine.New(err, nil)
} }
writers[disk.GetOrder()] = objectSlice writers[order] = objectSlice
} }
nodeSlice = nodeSlice + 1 nodeSlice = nodeSlice + 1
} }

View File

@ -16,12 +16,15 @@
package donut 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 // node struct internal
type node struct { type node struct {
hostname string hostname string
disks map[string]Disk disks map[int]disk.Disk
} }
// NewNode - instantiates a new node // NewNode - instantiates a new node
@ -29,7 +32,7 @@ func NewNode(hostname string) (Node, error) {
if hostname == "" { if hostname == "" {
return nil, iodine.New(InvalidArgument{}, nil) return nil, iodine.New(InvalidArgument{}, nil)
} }
disks := make(map[string]Disk) disks := make(map[int]disk.Disk)
n := node{ n := node{
hostname: hostname, hostname: hostname,
disks: disks, disks: disks,
@ -43,22 +46,22 @@ func (n node) GetNodeName() string {
} }
// ListDisks - return number of disks // 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 return n.disks, nil
} }
// AttachDisk - attach a disk // AttachDisk - attach a disk
func (n node) AttachDisk(disk Disk) error { func (n node) AttachDisk(disk disk.Disk, diskOrder int) error {
if disk == nil { if diskOrder < 0 {
return iodine.New(InvalidArgument{}, nil) return iodine.New(InvalidArgument{}, nil)
} }
n.disks[disk.GetPath()] = disk n.disks[diskOrder] = disk
return nil return nil
} }
// DetachDisk - detach a disk // DetachDisk - detach a disk
func (n node) DetachDisk(disk Disk) error { func (n node) DetachDisk(diskOrder int) error {
delete(n.disks, disk.GetPath()) delete(n.disks, diskOrder)
return nil return nil
} }

View File

@ -18,7 +18,8 @@ package donut
import ( import (
"io" "io"
"os"
"github.com/minio/minio/pkg/storage/donut/disk"
) )
// Collection of Donut specification interfaces // Collection of Donut specification interfaces
@ -61,26 +62,11 @@ type Management interface {
// Node interface for node management // Node interface for node management
type Node interface { type Node interface {
ListDisks() (map[string]Disk, error) ListDisks() (map[int]disk.Disk, error)
AttachDisk(disk Disk) error AttachDisk(disk disk.Disk, diskOrder int) error
DetachDisk(disk Disk) error DetachDisk(diskOrder int) error
GetNodeName() string GetNodeName() string
SaveConfig() error SaveConfig() error
LoadConfig() 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
}

View File

@ -22,12 +22,13 @@ import (
"strings" "strings"
"github.com/minio/minio/pkg/iodine" "github.com/minio/minio/pkg/iodine"
"github.com/minio/minio/pkg/storage/donut/disk"
) )
// Rebalance - // Rebalance -
func (d donut) Rebalance() error { func (d donut) Rebalance() error {
var totalOffSetLength int var totalOffSetLength int
var newDisks []Disk var newDisks []disk.Disk
var existingDirs []os.FileInfo var existingDirs []os.FileInfo
for _, node := range d.nodes { for _, node := range d.nodes {
disks, err := node.ListDisks() disks, err := node.ListDisks()

View File

@ -21,8 +21,8 @@ func (d donut) Info() (nodeDiskMap map[string][]string, err error) {
return nil, iodine.New(err, nil) return nil, iodine.New(err, nil)
} }
diskList := make([]string, len(disks)) diskList := make([]string, len(disks))
for diskName, disk := range disks { for diskOrder, disk := range disks {
diskList[disk.GetOrder()] = diskName diskList[diskOrder] = disk.GetPath()
} }
nodeDiskMap[nodeName] = diskList nodeDiskMap[nodeName] = diskList
} }
@ -52,14 +52,14 @@ func (d donut) SaveConfig() error {
if err != nil { if err != nil {
return iodine.New(err, nil) return iodine.New(err, nil)
} }
for _, disk := range disks { for order, disk := range disks {
donutConfigPath := filepath.Join(d.name, donutConfig) donutConfigPath := filepath.Join(d.name, donutConfig)
donutConfigWriter, err := disk.MakeFile(donutConfigPath) donutConfigWriter, err := disk.CreateFile(donutConfigPath)
defer donutConfigWriter.Close() defer donutConfigWriter.Close()
if err != nil { if err != nil {
return iodine.New(err, nil) return iodine.New(err, nil)
} }
nodeDiskMap[hostname][disk.GetOrder()] = disk.GetPath() nodeDiskMap[hostname][order] = disk.GetPath()
jenc := json.NewEncoder(donutConfigWriter) jenc := json.NewEncoder(donutConfigWriter)
if err := jenc.Encode(nodeDiskMap); err != nil { if err := jenc.Encode(nodeDiskMap); err != nil {
return iodine.New(err, nil) return iodine.New(err, nil)

View File

@ -38,12 +38,12 @@ func (d donut) getBucketMetadataWriters() ([]io.WriteCloser, error) {
return nil, iodine.New(err, nil) return nil, iodine.New(err, nil)
} }
writers = make([]io.WriteCloser, len(disks)) writers = make([]io.WriteCloser, len(disks))
for _, disk := range disks { for order, disk := range disks {
bucketMetaDataWriter, err := disk.MakeFile(filepath.Join(d.name, bucketMetadataConfig)) bucketMetaDataWriter, err := disk.CreateFile(filepath.Join(d.name, bucketMetadataConfig))
if err != nil { if err != nil {
return nil, iodine.New(err, nil) return nil, iodine.New(err, nil)
} }
writers[disk.GetOrder()] = bucketMetaDataWriter writers[order] = bucketMetaDataWriter
} }
} }
return writers, nil return writers, nil
@ -57,12 +57,12 @@ func (d donut) getBucketMetadataReaders() ([]io.ReadCloser, error) {
return nil, iodine.New(err, nil) return nil, iodine.New(err, nil)
} }
readers = make([]io.ReadCloser, len(disks)) readers = make([]io.ReadCloser, len(disks))
for _, disk := range disks { for order, disk := range disks {
bucketMetaDataReader, err := disk.OpenFile(filepath.Join(d.name, bucketMetadataConfig)) bucketMetaDataReader, err := disk.OpenFile(filepath.Join(d.name, bucketMetadataConfig))
if err != nil { if err != nil {
return nil, iodine.New(err, nil) return nil, iodine.New(err, nil)
} }
readers[disk.GetOrder()] = bucketMetaDataReader readers[order] = bucketMetaDataReader
} }
} }
return readers, nil return readers, nil
@ -123,8 +123,8 @@ func (d donut) makeDonutBucket(bucketName, acl string) error {
if err != nil { if err != nil {
return iodine.New(err, nil) return iodine.New(err, nil)
} }
for _, disk := range disks { for order, disk := range disks {
bucketSlice := fmt.Sprintf("%s$%d$%d", bucketName, nodeNumber, disk.GetOrder()) bucketSlice := fmt.Sprintf("%s$%d$%d", bucketName, nodeNumber, order)
err := disk.MakeDir(filepath.Join(d.name, bucketSlice)) err := disk.MakeDir(filepath.Join(d.name, bucketSlice))
if err != nil { if err != nil {
return iodine.New(err, nil) return iodine.New(err, nil)