Remove unnecessary interfaces from donut, cleanup

master
Harshavardhana 10 years ago
parent b915cc3611
commit 1682c748ac
  1. 4
      pkg/storage/donut/donut.go
  2. 10
      pkg/storage/donut/donut_bucket.go
  3. 4
      pkg/storage/donut/donut_bucket_internal.go
  4. 6
      pkg/storage/donut/donut_encoder.go
  5. 69
      pkg/storage/donut/donut_internal_interfaces.go
  6. 4
      pkg/storage/donut/donut_object.go
  7. 39
      pkg/storage/donut/donut_public_interfaces.go

@ -21,7 +21,7 @@ import "github.com/minio/minio/pkg/iodine"
// donut struct internal data // donut struct internal data
type donut struct { type donut struct {
name string name string
buckets map[string]Bucket buckets map[string]bucket
nodes map[string]Node nodes map[string]Node
} }
@ -72,7 +72,7 @@ func NewDonut(donutName string, nodeDiskMap map[string][]string) (Donut, error)
return nil, iodine.New(InvalidArgument{}, nil) return nil, iodine.New(InvalidArgument{}, nil)
} }
nodes := make(map[string]Node) nodes := make(map[string]Node)
buckets := make(map[string]Bucket) buckets := make(map[string]bucket)
d := donut{ d := donut{
name: donutName, name: donutName,
nodes: nodes, nodes: nodes,

@ -38,18 +38,18 @@ type bucket struct {
time time.Time time time.Time
donutName string donutName string
nodes map[string]Node nodes map[string]Node
objects map[string]Object objects map[string]object
} }
// NewBucket - instantiate a new bucket // NewBucket - instantiate a new bucket
func NewBucket(bucketName, aclType, donutName string, nodes map[string]Node) (Bucket, map[string]string, error) { func NewBucket(bucketName, aclType, donutName string, nodes map[string]Node) (bucket, map[string]string, error) {
errParams := map[string]string{ errParams := map[string]string{
"bucketName": bucketName, "bucketName": bucketName,
"donutName": donutName, "donutName": donutName,
"aclType": aclType, "aclType": aclType,
} }
if strings.TrimSpace(bucketName) == "" || strings.TrimSpace(donutName) == "" { if strings.TrimSpace(bucketName) == "" || strings.TrimSpace(donutName) == "" {
return nil, nil, iodine.New(InvalidArgument{}, errParams) return bucket{}, nil, iodine.New(InvalidArgument{}, errParams)
} }
bucketMetadata := make(map[string]string) bucketMetadata := make(map[string]string)
bucketMetadata["acl"] = aclType bucketMetadata["acl"] = aclType
@ -60,13 +60,13 @@ func NewBucket(bucketName, aclType, donutName string, nodes map[string]Node) (Bu
b.acl = aclType b.acl = aclType
b.time = t b.time = t
b.donutName = donutName b.donutName = donutName
b.objects = make(map[string]Object) b.objects = make(map[string]object)
b.nodes = nodes b.nodes = nodes
return b, bucketMetadata, nil return b, bucketMetadata, nil
} }
// ListObjects - list all objects // ListObjects - list all objects
func (b bucket) ListObjects() (map[string]Object, error) { func (b bucket) ListObjects() (map[string]object, error) {
nodeSlice := 0 nodeSlice := 0
for _, node := range b.nodes { for _, node := range b.nodes {
disks, err := node.ListDisks() disks, err := node.ListDisks()

@ -32,7 +32,7 @@ import (
"github.com/minio/minio/pkg/utils/split" "github.com/minio/minio/pkg/utils/split"
) )
/// This file contains all the internal functions used by Bucket interface /// This file contains all the internal functions
// isMD5SumEqual - returns error if md5sum mismatches, other its `nil` // isMD5SumEqual - returns error if md5sum mismatches, other its `nil`
func (b bucket) isMD5SumEqual(expectedMD5Sum, actualMD5Sum string) error { func (b bucket) isMD5SumEqual(expectedMD5Sum, actualMD5Sum string) error {
@ -211,7 +211,7 @@ func (b bucket) readEncodedData(objectName string, writer *io.PipeWriter, donutO
} }
// decodeEncodedData - // decodeEncodedData -
func (b bucket) decodeEncodedData(totalLeft, blockSize int64, readers []io.ReadCloser, encoder Encoder, writer *io.PipeWriter) ([]byte, error) { func (b bucket) decodeEncodedData(totalLeft, blockSize int64, readers []io.ReadCloser, encoder encoder, writer *io.PipeWriter) ([]byte, error) {
var curBlockSize int64 var curBlockSize int64
if blockSize < totalLeft { if blockSize < totalLeft {
curBlockSize = blockSize curBlockSize = blockSize

@ -43,7 +43,7 @@ func getErasureTechnique(technique string) (encoding.Technique, error) {
} }
// NewEncoder - instantiate a new encoder // NewEncoder - instantiate a new encoder
func NewEncoder(k, m uint8, technique string) (Encoder, error) { func NewEncoder(k, m uint8, technique string) (encoder, error) {
errParams := map[string]string{ errParams := map[string]string{
"k": strconv.FormatUint(uint64(k), 10), "k": strconv.FormatUint(uint64(k), 10),
"m": strconv.FormatUint(uint64(m), 10), "m": strconv.FormatUint(uint64(m), 10),
@ -52,11 +52,11 @@ func NewEncoder(k, m uint8, technique string) (Encoder, error) {
e := encoder{} e := encoder{}
t, err := getErasureTechnique(technique) t, err := getErasureTechnique(technique)
if err != nil { if err != nil {
return nil, iodine.New(err, errParams) return encoder{}, iodine.New(err, errParams)
} }
params, err := encoding.ValidateParams(k, m, t) params, err := encoding.ValidateParams(k, m, t)
if err != nil { if err != nil {
return nil, iodine.New(err, errParams) return encoder{}, iodine.New(err, errParams)
} }
e.encoder = encoding.NewErasure(params) e.encoder = encoding.NewErasure(params)
e.k = k e.k = k

@ -1,69 +0,0 @@
/*
* Minimalist Object Storage, (C) 2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package donut
import (
"io"
"os"
)
// Encoder interface
type Encoder interface {
GetEncodedBlockLen(dataLength int) (int, error)
Encode(data []byte) (encodedData [][]byte, err error)
Decode(encodedData [][]byte, dataLength int) (data []byte, err error)
}
// Bucket interface
type Bucket interface {
ListObjects() (map[string]Object, error)
GetObject(object string) (io.ReadCloser, int64, error)
PutObject(object string, contents io.Reader, expectedMD5Sum string, metadata map[string]string) (string, error)
}
// Object interface
type Object interface {
GetObjectMetadata() (map[string]string, error)
GetDonutObjectMetadata() (map[string]string, error)
}
// Node interface
type Node interface {
ListDisks() (map[string]Disk, error)
AttachDisk(disk Disk) error
DetachDisk(disk Disk) error
GetNodeName() string
SaveConfig() error
LoadConfig() error
}
// Disk interface
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
}

@ -33,9 +33,9 @@ type object struct {
} }
// NewObject - instantiate a new object // NewObject - instantiate a new object
func NewObject(objectName, p string) (Object, error) { func NewObject(objectName, p string) (object, error) {
if objectName == "" { if objectName == "" {
return nil, iodine.New(InvalidArgument{}, nil) return object{}, iodine.New(InvalidArgument{}, nil)
} }
o := object{} o := object{}
o.name = objectName o.name = objectName

@ -16,7 +16,10 @@
package donut package donut
import "io" import (
"io"
"os"
)
// Collection of Donut specification interfaces // Collection of Donut specification interfaces
@ -28,16 +31,16 @@ type Donut interface {
// ObjectStorage is a donut object storage interface // ObjectStorage is a donut object storage interface
type ObjectStorage interface { type ObjectStorage interface {
// Storage service Operations // Storage service operations
GetBucketMetadata(bucket string) (map[string]string, error) GetBucketMetadata(bucket string) (map[string]string, error)
SetBucketMetadata(bucket string, metadata map[string]string) error SetBucketMetadata(bucket string, metadata map[string]string) error
ListBuckets() (map[string]map[string]string, error) ListBuckets() (map[string]map[string]string, error)
MakeBucket(bucket, acl string) error MakeBucket(bucket, acl string) error
// Bucket Operations // Bucket operations
ListObjects(bucket, prefix, marker, delim string, maxKeys int) (result []string, prefixes []string, isTruncated bool, err error) ListObjects(bucket, prefix, marker, delim string, maxKeys int) (objects []string, prefixes []string, isTruncated bool, err error)
// Object Operations // Object operations
GetObject(bucket, object string) (io.ReadCloser, int64, error) GetObject(bucket, object string) (io.ReadCloser, int64, error)
GetObjectMetadata(bucket, object string) (map[string]string, error) GetObjectMetadata(bucket, object string) (map[string]string, error)
PutObject(bucket, object, expectedMD5Sum string, reader io.ReadCloser, metadata map[string]string) (string, error) PutObject(bucket, object, expectedMD5Sum string, reader io.ReadCloser, metadata map[string]string) (string, error)
@ -55,3 +58,29 @@ type Management interface {
SaveConfig() error SaveConfig() error
LoadConfig() error LoadConfig() error
} }
// Node interface for node management
type Node interface {
ListDisks() (map[string]Disk, error)
AttachDisk(disk Disk) error
DetachDisk(disk Disk) 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
}

Loading…
Cancel
Save