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 (
|
2015-06-25 19:43:36 +02:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
2015-06-26 11:10:47 +02:00
|
|
|
"time"
|
2015-06-25 19:43:36 +02:00
|
|
|
|
2015-06-25 05:34:20 +02:00
|
|
|
"github.com/minio/minio/pkg/iodine"
|
|
|
|
)
|
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-06-25 21:55:13 +02:00
|
|
|
nodes map[string]node
|
2015-06-25 19:43:36 +02:00
|
|
|
lock *sync.RWMutex
|
2015-04-05 10:53:41 +02:00
|
|
|
}
|
|
|
|
|
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-06-25 21:55:13 +02:00
|
|
|
// attachDonutNode - wrapper function to instantiate a new node for associatedt donut
|
2015-04-09 01:28:14 +02:00
|
|
|
// based on the provided configuration
|
2015-06-25 21:55:13 +02:00
|
|
|
func (dt donut) attachDonutNode(hostname string, disks []string) error {
|
|
|
|
if err := dt.AttachNode(hostname, disks); 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
|
|
|
}
|
2015-06-25 21:55:13 +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,
|
2015-06-25 19:43:36 +02:00
|
|
|
lock: new(sync.RWMutex),
|
2015-04-05 10:53:41 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
2015-06-25 19:43:36 +02:00
|
|
|
|
|
|
|
// MakeBucket - make a new bucket
|
2015-06-25 21:55:13 +02:00
|
|
|
func (dt donut) MakeBucket(bucket, acl string) error {
|
|
|
|
dt.lock.Lock()
|
|
|
|
defer dt.lock.Unlock()
|
2015-06-25 19:43:36 +02:00
|
|
|
if bucket == "" || strings.TrimSpace(bucket) == "" {
|
|
|
|
return iodine.New(InvalidArgument{}, nil)
|
|
|
|
}
|
2015-06-25 21:55:13 +02:00
|
|
|
return dt.makeDonutBucket(bucket, acl)
|
2015-06-25 19:43:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetBucketMetadata - get bucket metadata
|
2015-06-25 21:55:13 +02:00
|
|
|
func (dt donut) GetBucketMetadata(bucket string) (map[string]string, error) {
|
|
|
|
dt.lock.RLock()
|
|
|
|
defer dt.lock.RUnlock()
|
2015-06-26 00:03:34 +02:00
|
|
|
if err := dt.listDonutBuckets(); err != nil {
|
2015-06-25 19:43:36 +02:00
|
|
|
return nil, iodine.New(err, nil)
|
|
|
|
}
|
2015-06-25 21:55:13 +02:00
|
|
|
if _, ok := dt.buckets[bucket]; !ok {
|
2015-06-25 19:43:36 +02:00
|
|
|
return nil, iodine.New(BucketNotFound{Bucket: bucket}, nil)
|
|
|
|
}
|
2015-06-25 21:55:13 +02:00
|
|
|
metadata, err := dt.getDonutBucketMetadata()
|
2015-06-25 19:43:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
return metadata[bucket], nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetBucketMetadata - set bucket metadata
|
2015-06-25 21:55:13 +02:00
|
|
|
func (dt donut) SetBucketMetadata(bucket string, bucketMetadata map[string]string) error {
|
|
|
|
dt.lock.Lock()
|
|
|
|
defer dt.lock.Unlock()
|
2015-06-26 00:03:34 +02:00
|
|
|
if err := dt.listDonutBuckets(); err != nil {
|
2015-06-25 19:43:36 +02:00
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
2015-06-25 21:55:13 +02:00
|
|
|
metadata, err := dt.getDonutBucketMetadata()
|
2015-06-25 19:43:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
oldBucketMetadata := metadata[bucket]
|
|
|
|
// TODO ignore rest of the keys for now, only mutable data is "acl"
|
|
|
|
oldBucketMetadata["acl"] = bucketMetadata["acl"]
|
|
|
|
metadata[bucket] = oldBucketMetadata
|
2015-06-25 21:55:13 +02:00
|
|
|
return dt.setDonutBucketMetadata(metadata)
|
2015-06-25 19:43:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListBuckets - return list of buckets
|
2015-06-25 21:55:13 +02:00
|
|
|
func (dt donut) ListBuckets() (metadata map[string]map[string]string, err error) {
|
|
|
|
dt.lock.RLock()
|
|
|
|
defer dt.lock.RUnlock()
|
2015-06-26 00:03:34 +02:00
|
|
|
if err := dt.listDonutBuckets(); err != nil {
|
2015-06-25 19:43:36 +02:00
|
|
|
return nil, iodine.New(err, nil)
|
|
|
|
}
|
2015-06-25 21:55:13 +02:00
|
|
|
metadata, err = dt.getDonutBucketMetadata()
|
2015-06-25 19:43:36 +02:00
|
|
|
if err != nil {
|
|
|
|
// intentionally left out the error when Donut is empty
|
|
|
|
// but we need to revisit this area in future - since we need
|
|
|
|
// to figure out between acceptable and unacceptable errors
|
2015-06-25 21:55:13 +02:00
|
|
|
return make(map[string]map[string]string), nil
|
2015-06-25 19:43:36 +02:00
|
|
|
}
|
|
|
|
return metadata, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListObjects - return list of objects
|
2015-06-25 21:55:13 +02:00
|
|
|
func (dt donut) ListObjects(bucket, prefix, marker, delimiter string, maxkeys int) ([]string, []string, bool, error) {
|
|
|
|
dt.lock.RLock()
|
|
|
|
defer dt.lock.RUnlock()
|
2015-06-25 19:43:36 +02:00
|
|
|
errParams := map[string]string{
|
|
|
|
"bucket": bucket,
|
|
|
|
"prefix": prefix,
|
|
|
|
"marker": marker,
|
|
|
|
"delimiter": delimiter,
|
|
|
|
"maxkeys": strconv.Itoa(maxkeys),
|
|
|
|
}
|
2015-06-26 00:03:34 +02:00
|
|
|
if err := dt.listDonutBuckets(); err != nil {
|
2015-06-25 19:43:36 +02:00
|
|
|
return nil, nil, false, iodine.New(err, errParams)
|
|
|
|
}
|
2015-06-25 21:55:13 +02:00
|
|
|
if _, ok := dt.buckets[bucket]; !ok {
|
2015-06-25 19:43:36 +02:00
|
|
|
return nil, nil, false, iodine.New(BucketNotFound{Bucket: bucket}, errParams)
|
|
|
|
}
|
2015-06-26 00:03:34 +02:00
|
|
|
objects, commonPrefixes, isTruncated, err := dt.buckets[bucket].ListObjects(prefix, marker, delimiter, maxkeys)
|
2015-06-25 19:43:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, false, iodine.New(err, errParams)
|
|
|
|
}
|
2015-06-26 00:03:34 +02:00
|
|
|
return objects, commonPrefixes, isTruncated, nil
|
2015-06-25 19:43:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// PutObject - put object
|
2015-06-25 21:55:13 +02:00
|
|
|
func (dt donut) PutObject(bucket, object, expectedMD5Sum string, reader io.ReadCloser, metadata map[string]string) (string, error) {
|
|
|
|
dt.lock.Lock()
|
|
|
|
defer dt.lock.Unlock()
|
2015-06-25 19:43:36 +02:00
|
|
|
errParams := map[string]string{
|
|
|
|
"bucket": bucket,
|
|
|
|
"object": object,
|
|
|
|
}
|
|
|
|
if bucket == "" || strings.TrimSpace(bucket) == "" {
|
|
|
|
return "", iodine.New(InvalidArgument{}, errParams)
|
|
|
|
}
|
|
|
|
if object == "" || strings.TrimSpace(object) == "" {
|
|
|
|
return "", iodine.New(InvalidArgument{}, errParams)
|
|
|
|
}
|
2015-06-26 00:03:34 +02:00
|
|
|
if err := dt.listDonutBuckets(); err != nil {
|
2015-06-25 19:43:36 +02:00
|
|
|
return "", iodine.New(err, errParams)
|
|
|
|
}
|
2015-06-25 21:55:13 +02:00
|
|
|
if _, ok := dt.buckets[bucket]; !ok {
|
2015-06-25 19:43:36 +02:00
|
|
|
return "", iodine.New(BucketNotFound{Bucket: bucket}, nil)
|
|
|
|
}
|
2015-06-26 03:52:07 +02:00
|
|
|
objectList, _, _, err := dt.buckets[bucket].ListObjects("", "", "", 1000)
|
2015-06-25 19:43:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return "", iodine.New(err, nil)
|
|
|
|
}
|
2015-06-26 00:03:34 +02:00
|
|
|
for _, objectName := range objectList {
|
2015-06-25 19:43:36 +02:00
|
|
|
if objectName == object {
|
|
|
|
return "", iodine.New(ObjectExists{Object: object}, nil)
|
|
|
|
}
|
|
|
|
}
|
2015-06-25 21:55:13 +02:00
|
|
|
md5sum, err := dt.buckets[bucket].WriteObject(object, reader, expectedMD5Sum, metadata)
|
2015-06-25 19:43:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return "", iodine.New(err, errParams)
|
|
|
|
}
|
|
|
|
return md5sum, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetObject - get object
|
2015-06-25 21:55:13 +02:00
|
|
|
func (dt donut) GetObject(bucket, object string) (reader io.ReadCloser, size int64, err error) {
|
|
|
|
dt.lock.RLock()
|
|
|
|
defer dt.lock.RUnlock()
|
2015-06-25 19:43:36 +02:00
|
|
|
errParams := map[string]string{
|
|
|
|
"bucket": bucket,
|
|
|
|
"object": object,
|
|
|
|
}
|
|
|
|
if bucket == "" || strings.TrimSpace(bucket) == "" {
|
|
|
|
return nil, 0, iodine.New(InvalidArgument{}, errParams)
|
|
|
|
}
|
|
|
|
if object == "" || strings.TrimSpace(object) == "" {
|
|
|
|
return nil, 0, iodine.New(InvalidArgument{}, errParams)
|
|
|
|
}
|
2015-06-26 00:03:34 +02:00
|
|
|
if err := dt.listDonutBuckets(); err != nil {
|
2015-06-25 19:43:36 +02:00
|
|
|
return nil, 0, iodine.New(err, nil)
|
|
|
|
}
|
2015-06-25 21:55:13 +02:00
|
|
|
if _, ok := dt.buckets[bucket]; !ok {
|
2015-06-25 19:43:36 +02:00
|
|
|
return nil, 0, iodine.New(BucketNotFound{Bucket: bucket}, errParams)
|
|
|
|
}
|
2015-06-25 21:55:13 +02:00
|
|
|
return dt.buckets[bucket].ReadObject(object)
|
2015-06-25 19:43:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetObjectMetadata - get object metadata
|
2015-06-25 21:55:13 +02:00
|
|
|
func (dt donut) GetObjectMetadata(bucket, object string) (map[string]string, error) {
|
|
|
|
dt.lock.RLock()
|
|
|
|
defer dt.lock.RUnlock()
|
2015-06-25 19:43:36 +02:00
|
|
|
errParams := map[string]string{
|
|
|
|
"bucket": bucket,
|
|
|
|
"object": object,
|
|
|
|
}
|
2015-06-26 00:03:34 +02:00
|
|
|
if err := dt.listDonutBuckets(); err != nil {
|
2015-06-25 19:43:36 +02:00
|
|
|
return nil, iodine.New(err, errParams)
|
|
|
|
}
|
2015-06-25 21:55:13 +02:00
|
|
|
if _, ok := dt.buckets[bucket]; !ok {
|
2015-06-25 19:43:36 +02:00
|
|
|
return nil, iodine.New(BucketNotFound{Bucket: bucket}, errParams)
|
|
|
|
}
|
2015-06-26 03:52:07 +02:00
|
|
|
//
|
|
|
|
// there is a potential issue here, if the object comes after the truncated list
|
|
|
|
// below GetObjectMetadata would fail as ObjectNotFound{}
|
|
|
|
//
|
|
|
|
// will fix it when we bring in persistent json into Donut - TODO
|
|
|
|
objectList, _, _, err := dt.buckets[bucket].ListObjects("", "", "", 1000)
|
2015-06-25 19:43:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, iodine.New(err, errParams)
|
|
|
|
}
|
2015-06-26 00:03:34 +02:00
|
|
|
for _, objectName := range objectList {
|
|
|
|
if objectName == object {
|
2015-06-26 11:10:47 +02:00
|
|
|
objectMetadataMap := make(map[string]string)
|
|
|
|
objectMetadata, err := dt.buckets[bucket].GetObjectMetadata(object)
|
|
|
|
if err != nil {
|
|
|
|
return nil, iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
objectMetadataMap["created"] = objectMetadata.Created.Format(time.RFC3339Nano)
|
|
|
|
objectMetadataMap["size"] = strconv.FormatInt(objectMetadata.Size, 10)
|
|
|
|
objectMetadataMap["md5"] = objectMetadata.MD5Sum
|
|
|
|
objectMetadataMap["version"] = objectMetadata.Version
|
|
|
|
for k, v := range objectMetadata.Metadata {
|
|
|
|
objectMetadataMap[k] = v
|
|
|
|
}
|
|
|
|
return objectMetadataMap, nil
|
2015-06-26 00:03:34 +02:00
|
|
|
}
|
2015-06-25 19:43:36 +02:00
|
|
|
}
|
2015-06-26 00:03:34 +02:00
|
|
|
return nil, iodine.New(ObjectNotFound{Object: object}, errParams)
|
2015-06-25 19:43:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// getDiskWriters -
|
2015-06-25 21:55:13 +02:00
|
|
|
func (dt donut) getBucketMetadataWriters() ([]io.WriteCloser, error) {
|
2015-06-25 19:43:36 +02:00
|
|
|
var writers []io.WriteCloser
|
2015-06-25 21:55:13 +02:00
|
|
|
for _, node := range dt.nodes {
|
2015-06-25 19:43:36 +02:00
|
|
|
disks, err := node.ListDisks()
|
|
|
|
if err != nil {
|
|
|
|
return nil, iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
writers = make([]io.WriteCloser, len(disks))
|
2015-06-25 21:55:13 +02:00
|
|
|
for order, d := range disks {
|
|
|
|
bucketMetaDataWriter, err := d.CreateFile(filepath.Join(dt.name, bucketMetadataConfig))
|
2015-06-25 19:43:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
writers[order] = bucketMetaDataWriter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return writers, nil
|
|
|
|
}
|
|
|
|
|
2015-06-25 21:55:13 +02:00
|
|
|
func (dt donut) getBucketMetadataReaders() ([]io.ReadCloser, error) {
|
2015-06-25 19:43:36 +02:00
|
|
|
var readers []io.ReadCloser
|
2015-06-25 21:55:13 +02:00
|
|
|
for _, node := range dt.nodes {
|
2015-06-25 19:43:36 +02:00
|
|
|
disks, err := node.ListDisks()
|
|
|
|
if err != nil {
|
|
|
|
return nil, iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
readers = make([]io.ReadCloser, len(disks))
|
2015-06-25 21:55:13 +02:00
|
|
|
for order, d := range disks {
|
|
|
|
bucketMetaDataReader, err := d.OpenFile(filepath.Join(dt.name, bucketMetadataConfig))
|
2015-06-25 19:43:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
readers[order] = bucketMetaDataReader
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return readers, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2015-06-25 21:55:13 +02:00
|
|
|
func (dt donut) setDonutBucketMetadata(metadata map[string]map[string]string) error {
|
|
|
|
writers, err := dt.getBucketMetadataWriters()
|
2015-06-25 19:43:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
for _, writer := range writers {
|
|
|
|
defer writer.Close()
|
|
|
|
}
|
|
|
|
for _, writer := range writers {
|
|
|
|
jenc := json.NewEncoder(writer)
|
|
|
|
if err := jenc.Encode(metadata); err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-06-25 21:55:13 +02:00
|
|
|
func (dt donut) getDonutBucketMetadata() (map[string]map[string]string, error) {
|
2015-06-25 19:43:36 +02:00
|
|
|
metadata := make(map[string]map[string]string)
|
2015-06-25 21:55:13 +02:00
|
|
|
readers, err := dt.getBucketMetadataReaders()
|
2015-06-25 19:43:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
for _, reader := range readers {
|
|
|
|
defer reader.Close()
|
|
|
|
}
|
|
|
|
for _, reader := range readers {
|
|
|
|
jenc := json.NewDecoder(reader)
|
|
|
|
if err := jenc.Decode(&metadata); err != nil {
|
|
|
|
return nil, iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return metadata, nil
|
|
|
|
}
|
|
|
|
|
2015-06-25 21:55:13 +02:00
|
|
|
func (dt donut) makeDonutBucket(bucketName, acl string) error {
|
2015-06-26 00:03:34 +02:00
|
|
|
if err := dt.listDonutBuckets(); err != nil {
|
2015-06-25 19:43:36 +02:00
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
2015-06-25 21:55:13 +02:00
|
|
|
if _, ok := dt.buckets[bucketName]; ok {
|
2015-06-25 19:43:36 +02:00
|
|
|
return iodine.New(BucketExists{Bucket: bucketName}, nil)
|
|
|
|
}
|
2015-06-25 21:55:13 +02:00
|
|
|
bucket, bucketMetadata, err := newBucket(bucketName, acl, dt.name, dt.nodes)
|
2015-06-25 19:43:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
nodeNumber := 0
|
2015-06-25 21:55:13 +02:00
|
|
|
dt.buckets[bucketName] = bucket
|
|
|
|
for _, node := range dt.nodes {
|
2015-06-25 19:43:36 +02:00
|
|
|
disks, err := node.ListDisks()
|
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
for order, disk := range disks {
|
|
|
|
bucketSlice := fmt.Sprintf("%s$%d$%d", bucketName, nodeNumber, order)
|
2015-06-25 21:55:13 +02:00
|
|
|
err := disk.MakeDir(filepath.Join(dt.name, bucketSlice))
|
2015-06-25 19:43:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nodeNumber = nodeNumber + 1
|
|
|
|
}
|
2015-06-25 21:55:13 +02:00
|
|
|
metadata, err := dt.getDonutBucketMetadata()
|
2015-06-25 19:43:36 +02:00
|
|
|
if err != nil {
|
2015-06-26 00:03:34 +02:00
|
|
|
if os.IsNotExist(iodine.ToError(err)) {
|
2015-06-25 19:43:36 +02:00
|
|
|
metadata := make(map[string]map[string]string)
|
|
|
|
metadata[bucketName] = bucketMetadata
|
2015-06-25 21:55:13 +02:00
|
|
|
err = dt.setDonutBucketMetadata(metadata)
|
2015-06-25 19:43:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
metadata[bucketName] = bucketMetadata
|
2015-06-25 21:55:13 +02:00
|
|
|
err = dt.setDonutBucketMetadata(metadata)
|
2015-06-25 19:43:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-06-26 00:03:34 +02:00
|
|
|
func (dt donut) listDonutBuckets() error {
|
2015-06-25 21:55:13 +02:00
|
|
|
for _, node := range dt.nodes {
|
2015-06-25 19:43:36 +02:00
|
|
|
disks, err := node.ListDisks()
|
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
for _, disk := range disks {
|
2015-06-25 21:55:13 +02:00
|
|
|
dirs, err := disk.ListDir(dt.name)
|
2015-06-25 19:43:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
for _, dir := range dirs {
|
|
|
|
splitDir := strings.Split(dir.Name(), "$")
|
|
|
|
if len(splitDir) < 3 {
|
|
|
|
return iodine.New(CorruptedBackend{Backend: dir.Name()}, nil)
|
|
|
|
}
|
|
|
|
bucketName := splitDir[0]
|
2015-06-25 21:55:13 +02:00
|
|
|
// we dont need this once we cache from makeDonutBucket()
|
|
|
|
bucket, _, err := newBucket(bucketName, "private", dt.name, dt.nodes)
|
2015-06-25 19:43:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
2015-06-25 21:55:13 +02:00
|
|
|
dt.buckets[bucketName] = bucket
|
2015-06-25 19:43:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|