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
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)
}
}

View File

@ -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 {

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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()

View File

@ -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)

View File

@ -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)