minio/pkg/storage/donut/donut.go

92 lines
2.4 KiB
Go
Raw Normal View History

2015-04-05 10:53:41 +02:00
/*
* 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 "github.com/minio/minio/pkg/iodine"
2015-04-05 10:53:41 +02:00
// donut struct internal data
2015-04-05 10:53:41 +02:00
type donut struct {
name string
buckets map[string]bucket
2015-04-05 10:53:41 +02:00
nodes map[string]Node
}
// config files used inside Donut
const (
2015-04-23 03:19:53 +02:00
// donut object metadata and config
donutObjectMetadataConfig = "donutObjectMetadata.json"
donutConfig = "donutMetadata.json"
2015-04-23 03:19:53 +02:00
// bucket, object metadata
bucketMetadataConfig = "bucketMetadata.json"
objectMetadataConfig = "objectMetadata.json"
2015-05-20 03:32:50 +02:00
// versions
objectMetadataVersion = "1.0"
donutObjectMetadataVersion = "1.0"
)
2015-04-05 10:53:41 +02:00
// attachDonutNode - wrapper function to instantiate a new node for associated donut
// based on the provided configuration
2015-04-05 10:53:41 +02:00
func (d donut) attachDonutNode(hostname string, disks []string) error {
node, err := NewNode(hostname)
if err != nil {
return iodine.New(err, nil)
2015-04-05 10:53:41 +02:00
}
for i, disk := range disks {
// Order is necessary for maps, keep order number separately
newDisk, err := NewDisk(disk, i)
if err != nil {
return iodine.New(err, nil)
2015-04-05 10:53:41 +02:00
}
if err := newDisk.MakeDir(d.name); err != nil {
return iodine.New(err, nil)
2015-04-05 10:53:41 +02:00
}
if err := node.AttachDisk(newDisk); err != nil {
return iodine.New(err, nil)
2015-04-05 10:53:41 +02:00
}
}
if err := d.AttachNode(node); err != nil {
return iodine.New(err, nil)
2015-04-05 10:53:41 +02:00
}
return nil
}
// NewDonut - instantiate a new donut
func NewDonut(donutName string, nodeDiskMap map[string][]string) (Donut, error) {
if donutName == "" || len(nodeDiskMap) == 0 {
return nil, iodine.New(InvalidArgument{}, nil)
2015-04-05 10:53:41 +02:00
}
nodes := make(map[string]Node)
buckets := make(map[string]bucket)
2015-04-05 10:53:41 +02:00
d := donut{
name: donutName,
nodes: nodes,
buckets: buckets,
}
for k, v := range nodeDiskMap {
if len(v) == 0 {
return nil, iodine.New(InvalidDisksArgument{}, nil)
2015-04-05 10:53:41 +02:00
}
err := d.attachDonutNode(k, v)
if err != nil {
return nil, iodine.New(err, nil)
2015-04-05 10:53:41 +02:00
}
}
return d, nil
}