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
|
|
|
|
|
2015-06-25 05:34:20 +02:00
|
|
|
import (
|
|
|
|
"github.com/minio/minio/pkg/iodine"
|
|
|
|
"github.com/minio/minio/pkg/storage/donut/disk"
|
|
|
|
)
|
2015-04-05 10:53:41 +02:00
|
|
|
|
2015-04-09 01:28:14 +02:00
|
|
|
// donut struct internal data
|
2015-04-05 10:53:41 +02:00
|
|
|
type donut struct {
|
|
|
|
name string
|
2015-06-25 04:43:38 +02:00
|
|
|
buckets map[string]bucket
|
2015-04-05 10:53:41 +02:00
|
|
|
nodes map[string]Node
|
|
|
|
}
|
|
|
|
|
2015-04-09 01:28:14 +02:00
|
|
|
// config files used inside Donut
|
2015-04-08 00:55:44 +02:00
|
|
|
const (
|
2015-04-23 03:19:53 +02:00
|
|
|
// donut object metadata and config
|
2015-04-08 00:55:44 +02:00
|
|
|
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-08 00:55:44 +02:00
|
|
|
)
|
|
|
|
|
2015-04-05 10:53:41 +02:00
|
|
|
// attachDonutNode - wrapper function to instantiate a new node for associated donut
|
2015-04-09 01:28:14 +02:00
|
|
|
// 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 {
|
2015-04-08 00:55:44 +02:00
|
|
|
return iodine.New(err, nil)
|
2015-04-05 10:53:41 +02:00
|
|
|
}
|
2015-06-25 05:34:20 +02:00
|
|
|
donutName := d.name
|
|
|
|
for i, d := range disks {
|
2015-04-05 10:53:41 +02:00
|
|
|
// Order is necessary for maps, keep order number separately
|
2015-06-25 05:34:20 +02:00
|
|
|
newDisk, err := disk.New(d)
|
2015-04-05 10:53:41 +02:00
|
|
|
if err != nil {
|
2015-04-08 00:55:44 +02:00
|
|
|
return iodine.New(err, nil)
|
2015-04-05 10:53:41 +02:00
|
|
|
}
|
2015-06-25 05:34:20 +02:00
|
|
|
if err := newDisk.MakeDir(donutName); err != nil {
|
2015-04-08 00:55:44 +02:00
|
|
|
return iodine.New(err, nil)
|
2015-04-05 10:53:41 +02:00
|
|
|
}
|
2015-06-25 05:34:20 +02:00
|
|
|
if err := node.AttachDisk(newDisk, i); err != nil {
|
2015-04-08 00:55:44 +02:00
|
|
|
return iodine.New(err, nil)
|
2015-04-05 10:53:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := d.AttachNode(node); err != nil {
|
2015-04-08 00:55:44 +02:00
|
|
|
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 {
|
2015-06-23 20:44:32 +02:00
|
|
|
return nil, iodine.New(InvalidArgument{}, nil)
|
2015-04-05 10:53:41 +02:00
|
|
|
}
|
|
|
|
nodes := make(map[string]Node)
|
2015-06-25 04:43:38 +02:00
|
|
|
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 {
|
2015-06-23 20:44:32 +02:00
|
|
|
return nil, iodine.New(InvalidDisksArgument{}, nil)
|
2015-04-05 10:53:41 +02:00
|
|
|
}
|
|
|
|
err := d.attachDonutNode(k, v)
|
|
|
|
if err != nil {
|
2015-04-08 00:55:44 +02:00
|
|
|
return nil, iodine.New(err, nil)
|
2015-04-05 10:53:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return d, nil
|
|
|
|
}
|