From 1682c748ac708db4e5883c120db70c3f635d388a Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 24 Jun 2015 19:43:38 -0700 Subject: [PATCH] Remove unnecessary interfaces from donut, cleanup --- pkg/storage/donut/donut.go | 4 +- pkg/storage/donut/donut_bucket.go | 10 +-- pkg/storage/donut/donut_bucket_internal.go | 4 +- pkg/storage/donut/donut_encoder.go | 6 +- .../donut/donut_internal_interfaces.go | 69 ------------------- pkg/storage/donut/donut_object.go | 4 +- pkg/storage/donut/donut_public_interfaces.go | 39 +++++++++-- 7 files changed, 48 insertions(+), 88 deletions(-) delete mode 100644 pkg/storage/donut/donut_internal_interfaces.go diff --git a/pkg/storage/donut/donut.go b/pkg/storage/donut/donut.go index 9e6aca2c4..23a0231fb 100644 --- a/pkg/storage/donut/donut.go +++ b/pkg/storage/donut/donut.go @@ -21,7 +21,7 @@ import "github.com/minio/minio/pkg/iodine" // donut struct internal data type donut struct { name string - buckets map[string]Bucket + buckets map[string]bucket nodes map[string]Node } @@ -72,7 +72,7 @@ func NewDonut(donutName string, nodeDiskMap map[string][]string) (Donut, error) return nil, iodine.New(InvalidArgument{}, nil) } nodes := make(map[string]Node) - buckets := make(map[string]Bucket) + buckets := make(map[string]bucket) d := donut{ name: donutName, nodes: nodes, diff --git a/pkg/storage/donut/donut_bucket.go b/pkg/storage/donut/donut_bucket.go index ef90146bc..e94ff6de4 100644 --- a/pkg/storage/donut/donut_bucket.go +++ b/pkg/storage/donut/donut_bucket.go @@ -38,18 +38,18 @@ type bucket struct { time time.Time donutName string nodes map[string]Node - objects map[string]Object + objects map[string]object } // 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{ "bucketName": bucketName, "donutName": donutName, "aclType": aclType, } 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["acl"] = aclType @@ -60,13 +60,13 @@ func NewBucket(bucketName, aclType, donutName string, nodes map[string]Node) (Bu b.acl = aclType b.time = t b.donutName = donutName - b.objects = make(map[string]Object) + b.objects = make(map[string]object) b.nodes = nodes return b, bucketMetadata, nil } // ListObjects - list all objects -func (b bucket) ListObjects() (map[string]Object, error) { +func (b bucket) ListObjects() (map[string]object, error) { nodeSlice := 0 for _, node := range b.nodes { disks, err := node.ListDisks() diff --git a/pkg/storage/donut/donut_bucket_internal.go b/pkg/storage/donut/donut_bucket_internal.go index 39a35a016..deb6b898e 100644 --- a/pkg/storage/donut/donut_bucket_internal.go +++ b/pkg/storage/donut/donut_bucket_internal.go @@ -32,7 +32,7 @@ import ( "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` func (b bucket) isMD5SumEqual(expectedMD5Sum, actualMD5Sum string) error { @@ -211,7 +211,7 @@ func (b bucket) readEncodedData(objectName string, writer *io.PipeWriter, donutO } // 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 if blockSize < totalLeft { curBlockSize = blockSize diff --git a/pkg/storage/donut/donut_encoder.go b/pkg/storage/donut/donut_encoder.go index 18fa4cadb..1d62f4fdf 100644 --- a/pkg/storage/donut/donut_encoder.go +++ b/pkg/storage/donut/donut_encoder.go @@ -43,7 +43,7 @@ func getErasureTechnique(technique string) (encoding.Technique, error) { } // 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{ "k": strconv.FormatUint(uint64(k), 10), "m": strconv.FormatUint(uint64(m), 10), @@ -52,11 +52,11 @@ func NewEncoder(k, m uint8, technique string) (Encoder, error) { e := encoder{} t, err := getErasureTechnique(technique) if err != nil { - return nil, iodine.New(err, errParams) + return encoder{}, iodine.New(err, errParams) } params, err := encoding.ValidateParams(k, m, t) if err != nil { - return nil, iodine.New(err, errParams) + return encoder{}, iodine.New(err, errParams) } e.encoder = encoding.NewErasure(params) e.k = k diff --git a/pkg/storage/donut/donut_internal_interfaces.go b/pkg/storage/donut/donut_internal_interfaces.go deleted file mode 100644 index 3cb02240b..000000000 --- a/pkg/storage/donut/donut_internal_interfaces.go +++ /dev/null @@ -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 -} diff --git a/pkg/storage/donut/donut_object.go b/pkg/storage/donut/donut_object.go index 9cd466397..d394c132f 100644 --- a/pkg/storage/donut/donut_object.go +++ b/pkg/storage/donut/donut_object.go @@ -33,9 +33,9 @@ type object struct { } // NewObject - instantiate a new object -func NewObject(objectName, p string) (Object, error) { +func NewObject(objectName, p string) (object, error) { if objectName == "" { - return nil, iodine.New(InvalidArgument{}, nil) + return object{}, iodine.New(InvalidArgument{}, nil) } o := object{} o.name = objectName diff --git a/pkg/storage/donut/donut_public_interfaces.go b/pkg/storage/donut/donut_public_interfaces.go index 77e7cd7b5..5e513b7e8 100644 --- a/pkg/storage/donut/donut_public_interfaces.go +++ b/pkg/storage/donut/donut_public_interfaces.go @@ -16,7 +16,10 @@ package donut -import "io" +import ( + "io" + "os" +) // Collection of Donut specification interfaces @@ -28,16 +31,16 @@ type Donut interface { // ObjectStorage is a donut object storage interface type ObjectStorage interface { - // Storage service Operations + // Storage service operations GetBucketMetadata(bucket string) (map[string]string, error) SetBucketMetadata(bucket string, metadata map[string]string) error ListBuckets() (map[string]map[string]string, error) MakeBucket(bucket, acl string) error - // Bucket Operations - ListObjects(bucket, prefix, marker, delim string, maxKeys int) (result []string, prefixes []string, isTruncated bool, err error) + // Bucket operations + 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) GetObjectMetadata(bucket, object string) (map[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 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 +}