2015-04-05 04:53:41 -04: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-24 23:34:20 -04:00
|
|
|
import (
|
2015-06-25 13:43:36 -04:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2015-06-24 23:34:20 -04:00
|
|
|
"github.com/minio/minio/pkg/iodine"
|
|
|
|
)
|
2015-04-05 04:53:41 -04:00
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// config files used inside Donut
|
2015-04-07 18:55:44 -04:00
|
|
|
const (
|
2015-06-26 18:32:24 -04:00
|
|
|
// donut system config
|
|
|
|
donutConfig = "donutConfig.json"
|
2015-04-22 21:19:53 -04:00
|
|
|
|
|
|
|
// bucket, object metadata
|
|
|
|
bucketMetadataConfig = "bucketMetadata.json"
|
|
|
|
objectMetadataConfig = "objectMetadata.json"
|
2015-05-19 21:32:50 -04:00
|
|
|
|
|
|
|
// versions
|
2015-06-26 20:54:19 -04:00
|
|
|
objectMetadataVersion = "1.0.0"
|
|
|
|
bucketMetadataVersion = "1.0.0"
|
2015-04-07 18:55:44 -04:00
|
|
|
)
|
|
|
|
|
2015-07-10 17:04:37 -04:00
|
|
|
/// v1 API functions
|
|
|
|
|
2015-07-02 23:31:22 -04:00
|
|
|
// makeBucket - make a new bucket
|
|
|
|
func (donut API) makeBucket(bucket string, acl BucketACL) error {
|
2015-06-25 13:43:36 -04:00
|
|
|
if bucket == "" || strings.TrimSpace(bucket) == "" {
|
|
|
|
return iodine.New(InvalidArgument{}, nil)
|
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
return donut.makeDonutBucket(bucket, acl.String())
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
|
|
|
|
2015-07-02 23:31:22 -04:00
|
|
|
// getBucketMetadata - get bucket metadata
|
|
|
|
func (donut API) getBucketMetadata(bucketName string) (BucketMetadata, error) {
|
|
|
|
if err := donut.listDonutBuckets(); err != nil {
|
2015-06-26 18:32:24 -04:00
|
|
|
return BucketMetadata{}, iodine.New(err, nil)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
if _, ok := donut.buckets[bucketName]; !ok {
|
2015-06-26 18:32:24 -04:00
|
|
|
return BucketMetadata{}, iodine.New(BucketNotFound{Bucket: bucketName}, nil)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
metadata, err := donut.getDonutBucketMetadata()
|
2015-06-25 13:43:36 -04:00
|
|
|
if err != nil {
|
2015-06-26 18:32:24 -04:00
|
|
|
return BucketMetadata{}, iodine.New(err, nil)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
2015-06-26 18:32:24 -04:00
|
|
|
return metadata.Buckets[bucketName], nil
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
|
|
|
|
2015-07-02 23:31:22 -04:00
|
|
|
// setBucketMetadata - set bucket metadata
|
|
|
|
func (donut API) setBucketMetadata(bucketName string, bucketMetadata map[string]string) error {
|
|
|
|
if err := donut.listDonutBuckets(); err != nil {
|
2015-06-25 13:43:36 -04:00
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
metadata, err := donut.getDonutBucketMetadata()
|
2015-06-25 13:43:36 -04:00
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
2015-06-26 18:32:24 -04:00
|
|
|
oldBucketMetadata := metadata.Buckets[bucketName]
|
|
|
|
acl, ok := bucketMetadata["acl"]
|
|
|
|
if !ok {
|
|
|
|
return iodine.New(InvalidArgument{}, nil)
|
|
|
|
}
|
2015-06-30 20:08:18 -04:00
|
|
|
oldBucketMetadata.ACL = BucketACL(acl)
|
2015-06-26 18:32:24 -04:00
|
|
|
metadata.Buckets[bucketName] = oldBucketMetadata
|
2015-07-02 23:31:22 -04:00
|
|
|
return donut.setDonutBucketMetadata(metadata)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
|
|
|
|
2015-07-02 23:31:22 -04:00
|
|
|
// listBuckets - return list of buckets
|
|
|
|
func (donut API) listBuckets() (map[string]BucketMetadata, error) {
|
|
|
|
if err := donut.listDonutBuckets(); err != nil {
|
2015-06-25 13:43:36 -04:00
|
|
|
return nil, iodine.New(err, nil)
|
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
metadata, err := donut.getDonutBucketMetadata()
|
2015-06-25 13:43:36 -04: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-26 18:32:24 -04:00
|
|
|
return make(map[string]BucketMetadata), nil
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
2015-06-26 18:32:24 -04:00
|
|
|
return metadata.Buckets, nil
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
|
|
|
|
2015-07-02 23:31:22 -04:00
|
|
|
// listObjects - return list of objects
|
|
|
|
func (donut API) listObjects(bucket, prefix, marker, delimiter string, maxkeys int) (ListObjectsResults, error) {
|
2015-06-25 13:43:36 -04:00
|
|
|
errParams := map[string]string{
|
|
|
|
"bucket": bucket,
|
|
|
|
"prefix": prefix,
|
|
|
|
"marker": marker,
|
|
|
|
"delimiter": delimiter,
|
|
|
|
"maxkeys": strconv.Itoa(maxkeys),
|
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
if err := donut.listDonutBuckets(); err != nil {
|
|
|
|
return ListObjectsResults{}, iodine.New(err, errParams)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
if _, ok := donut.buckets[bucket]; !ok {
|
|
|
|
return ListObjectsResults{}, iodine.New(BucketNotFound{Bucket: bucket}, errParams)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
listObjects, err := donut.buckets[bucket].ListObjects(prefix, marker, delimiter, maxkeys)
|
2015-06-25 13:43:36 -04:00
|
|
|
if err != nil {
|
2015-07-02 23:31:22 -04:00
|
|
|
return ListObjectsResults{}, iodine.New(err, errParams)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
2015-06-27 16:12:33 -04:00
|
|
|
return listObjects, nil
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
|
|
|
|
2015-07-02 23:31:22 -04:00
|
|
|
// putObject - put object
|
2015-07-10 14:47:04 -04:00
|
|
|
func (donut API) putObject(bucket, object, expectedMD5Sum string, reader io.Reader, metadata map[string]string, signature *Signature) (ObjectMetadata, error) {
|
2015-06-25 13:43:36 -04:00
|
|
|
errParams := map[string]string{
|
|
|
|
"bucket": bucket,
|
|
|
|
"object": object,
|
|
|
|
}
|
|
|
|
if bucket == "" || strings.TrimSpace(bucket) == "" {
|
2015-06-29 14:10:52 -04:00
|
|
|
return ObjectMetadata{}, iodine.New(InvalidArgument{}, errParams)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
|
|
|
if object == "" || strings.TrimSpace(object) == "" {
|
2015-06-29 14:10:52 -04:00
|
|
|
return ObjectMetadata{}, iodine.New(InvalidArgument{}, errParams)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
if err := donut.listDonutBuckets(); err != nil {
|
2015-06-29 14:10:52 -04:00
|
|
|
return ObjectMetadata{}, iodine.New(err, errParams)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
if _, ok := donut.buckets[bucket]; !ok {
|
2015-06-29 14:10:52 -04:00
|
|
|
return ObjectMetadata{}, iodine.New(BucketNotFound{Bucket: bucket}, nil)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
bucketMeta, err := donut.getDonutBucketMetadata()
|
2015-06-25 13:43:36 -04:00
|
|
|
if err != nil {
|
2015-06-29 14:10:52 -04:00
|
|
|
return ObjectMetadata{}, iodine.New(err, errParams)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
2015-06-27 02:22:30 -04:00
|
|
|
if _, ok := bucketMeta.Buckets[bucket].BucketObjects[object]; ok {
|
2015-06-29 14:10:52 -04:00
|
|
|
return ObjectMetadata{}, iodine.New(ObjectExists{Object: object}, errParams)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
2015-07-10 14:47:04 -04:00
|
|
|
objMetadata, err := donut.buckets[bucket].WriteObject(object, reader, expectedMD5Sum, metadata, signature)
|
2015-06-25 13:43:36 -04:00
|
|
|
if err != nil {
|
2015-06-29 14:10:52 -04:00
|
|
|
return ObjectMetadata{}, iodine.New(err, errParams)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
2015-06-27 02:22:30 -04:00
|
|
|
bucketMeta.Buckets[bucket].BucketObjects[object] = 1
|
2015-07-02 23:31:22 -04:00
|
|
|
if err := donut.setDonutBucketMetadata(bucketMeta); err != nil {
|
2015-06-29 14:10:52 -04:00
|
|
|
return ObjectMetadata{}, iodine.New(err, errParams)
|
2015-06-26 20:54:19 -04:00
|
|
|
}
|
2015-06-29 14:10:52 -04:00
|
|
|
return objMetadata, nil
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
|
|
|
|
2015-07-02 23:31:22 -04:00
|
|
|
// getObject - get object
|
|
|
|
func (donut API) getObject(bucket, object string) (reader io.ReadCloser, size int64, err error) {
|
2015-06-25 13:43:36 -04: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-07-02 23:31:22 -04:00
|
|
|
if err := donut.listDonutBuckets(); err != nil {
|
2015-06-25 13:43:36 -04:00
|
|
|
return nil, 0, iodine.New(err, nil)
|
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
if _, ok := donut.buckets[bucket]; !ok {
|
2015-06-25 13:43:36 -04:00
|
|
|
return nil, 0, iodine.New(BucketNotFound{Bucket: bucket}, errParams)
|
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
return donut.buckets[bucket].ReadObject(object)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
|
|
|
|
2015-07-02 23:31:22 -04:00
|
|
|
// getObjectMetadata - get object metadata
|
|
|
|
func (donut API) getObjectMetadata(bucket, object string) (ObjectMetadata, error) {
|
2015-06-25 13:43:36 -04:00
|
|
|
errParams := map[string]string{
|
|
|
|
"bucket": bucket,
|
|
|
|
"object": object,
|
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
if err := donut.listDonutBuckets(); err != nil {
|
2015-06-27 02:22:30 -04:00
|
|
|
return ObjectMetadata{}, iodine.New(err, errParams)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
if _, ok := donut.buckets[bucket]; !ok {
|
2015-06-27 02:22:30 -04:00
|
|
|
return ObjectMetadata{}, iodine.New(BucketNotFound{Bucket: bucket}, errParams)
|
2015-06-26 20:54:19 -04:00
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
bucketMeta, err := donut.getDonutBucketMetadata()
|
2015-06-25 13:43:36 -04:00
|
|
|
if err != nil {
|
2015-06-27 02:22:30 -04:00
|
|
|
return ObjectMetadata{}, iodine.New(err, errParams)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
2015-06-27 02:22:30 -04:00
|
|
|
if _, ok := bucketMeta.Buckets[bucket].BucketObjects[object]; !ok {
|
|
|
|
return ObjectMetadata{}, iodine.New(ObjectNotFound{Object: object}, errParams)
|
2015-06-26 20:54:19 -04:00
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
objectMetadata, err := donut.buckets[bucket].GetObjectMetadata(object)
|
2015-06-26 20:54:19 -04:00
|
|
|
if err != nil {
|
2015-06-27 02:22:30 -04:00
|
|
|
return ObjectMetadata{}, iodine.New(err, nil)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
2015-06-27 02:22:30 -04:00
|
|
|
return objectMetadata, nil
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
|
|
|
|
2015-07-10 17:04:37 -04:00
|
|
|
//// internal functions
|
|
|
|
|
|
|
|
// getBucketMetadataWriters -
|
2015-07-02 23:31:22 -04:00
|
|
|
func (donut API) getBucketMetadataWriters() ([]io.WriteCloser, error) {
|
2015-06-25 13:43:36 -04:00
|
|
|
var writers []io.WriteCloser
|
2015-07-02 23:31:22 -04:00
|
|
|
for _, node := range donut.nodes {
|
2015-06-25 13:43:36 -04:00
|
|
|
disks, err := node.ListDisks()
|
|
|
|
if err != nil {
|
|
|
|
return nil, iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
writers = make([]io.WriteCloser, len(disks))
|
2015-07-10 17:04:37 -04:00
|
|
|
for order, dd := range disks {
|
|
|
|
bucketMetaDataWriter, err := dd.CreateFile(filepath.Join(donut.config.DonutName, bucketMetadataConfig))
|
2015-06-25 13:43:36 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
writers[order] = bucketMetaDataWriter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return writers, nil
|
|
|
|
}
|
|
|
|
|
2015-07-10 17:04:37 -04:00
|
|
|
// getBucketMetadataReaders -
|
2015-07-02 23:31:22 -04:00
|
|
|
func (donut API) getBucketMetadataReaders() ([]io.ReadCloser, error) {
|
2015-06-25 13:43:36 -04:00
|
|
|
var readers []io.ReadCloser
|
2015-07-02 23:31:22 -04:00
|
|
|
for _, node := range donut.nodes {
|
2015-06-25 13:43:36 -04:00
|
|
|
disks, err := node.ListDisks()
|
|
|
|
if err != nil {
|
|
|
|
return nil, iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
readers = make([]io.ReadCloser, len(disks))
|
2015-06-25 15:55:13 -04:00
|
|
|
for order, d := range disks {
|
2015-07-02 23:31:22 -04:00
|
|
|
bucketMetaDataReader, err := d.OpenFile(filepath.Join(donut.config.DonutName, bucketMetadataConfig))
|
2015-06-25 13:43:36 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
readers[order] = bucketMetaDataReader
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return readers, nil
|
|
|
|
}
|
|
|
|
|
2015-07-10 17:04:37 -04:00
|
|
|
// setDonutBucketMetadata -
|
2015-07-02 23:31:22 -04:00
|
|
|
func (donut API) setDonutBucketMetadata(metadata *AllBuckets) error {
|
|
|
|
writers, err := donut.getBucketMetadataWriters()
|
2015-06-25 13:43:36 -04:00
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
for _, writer := range writers {
|
|
|
|
jenc := json.NewEncoder(writer)
|
|
|
|
if err := jenc.Encode(metadata); err != nil {
|
2015-07-10 17:04:37 -04:00
|
|
|
CleanupWritersOnError(writers)
|
2015-06-25 13:43:36 -04:00
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
}
|
2015-07-10 17:04:37 -04:00
|
|
|
for _, writer := range writers {
|
|
|
|
writer.Close()
|
|
|
|
}
|
2015-06-25 13:43:36 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-10 17:04:37 -04:00
|
|
|
// getDonutBucketMetadata -
|
2015-07-02 23:31:22 -04:00
|
|
|
func (donut API) getDonutBucketMetadata() (*AllBuckets, error) {
|
2015-06-26 18:32:24 -04:00
|
|
|
metadata := new(AllBuckets)
|
2015-07-02 23:31:22 -04:00
|
|
|
readers, err := donut.getBucketMetadataReaders()
|
2015-06-25 13:43:36 -04: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)
|
2015-06-26 18:32:24 -04:00
|
|
|
if err := jenc.Decode(metadata); err != nil {
|
2015-06-25 13:43:36 -04:00
|
|
|
return nil, iodine.New(err, nil)
|
|
|
|
}
|
2015-06-26 20:54:19 -04:00
|
|
|
return metadata, nil
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
2015-06-26 20:54:19 -04:00
|
|
|
return nil, iodine.New(InvalidArgument{}, nil)
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
|
|
|
|
2015-07-10 17:04:37 -04:00
|
|
|
// makeDonutBucket -
|
2015-07-02 23:31:22 -04:00
|
|
|
func (donut API) makeDonutBucket(bucketName, acl string) error {
|
|
|
|
if err := donut.listDonutBuckets(); err != nil {
|
2015-06-25 13:43:36 -04:00
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
if _, ok := donut.buckets[bucketName]; ok {
|
2015-06-25 13:43:36 -04:00
|
|
|
return iodine.New(BucketExists{Bucket: bucketName}, nil)
|
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
bucket, bucketMetadata, err := newBucket(bucketName, acl, donut.config.DonutName, donut.nodes)
|
2015-06-25 13:43:36 -04:00
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
nodeNumber := 0
|
2015-07-02 23:31:22 -04:00
|
|
|
donut.buckets[bucketName] = bucket
|
|
|
|
for _, node := range donut.nodes {
|
2015-06-25 13:43:36 -04: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-07-02 23:31:22 -04:00
|
|
|
err := disk.MakeDir(filepath.Join(donut.config.DonutName, bucketSlice))
|
2015-06-25 13:43:36 -04:00
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nodeNumber = nodeNumber + 1
|
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
metadata, err := donut.getDonutBucketMetadata()
|
2015-06-25 13:43:36 -04:00
|
|
|
if err != nil {
|
2015-06-25 18:03:34 -04:00
|
|
|
if os.IsNotExist(iodine.ToError(err)) {
|
2015-06-26 18:32:24 -04:00
|
|
|
metadata := new(AllBuckets)
|
|
|
|
metadata.Buckets = make(map[string]BucketMetadata)
|
|
|
|
metadata.Buckets[bucketName] = bucketMetadata
|
2015-07-02 23:31:22 -04:00
|
|
|
err = donut.setDonutBucketMetadata(metadata)
|
2015-06-25 13:43:36 -04:00
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
2015-06-26 18:32:24 -04:00
|
|
|
metadata.Buckets[bucketName] = bucketMetadata
|
2015-07-02 23:31:22 -04:00
|
|
|
err = donut.setDonutBucketMetadata(metadata)
|
2015-06-25 13:43:36 -04:00
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-10 17:04:37 -04:00
|
|
|
// listDonutBuckets -
|
2015-07-02 23:31:22 -04:00
|
|
|
func (donut API) listDonutBuckets() error {
|
|
|
|
for _, node := range donut.nodes {
|
2015-06-25 13:43:36 -04:00
|
|
|
disks, err := node.ListDisks()
|
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
|
|
|
for _, disk := range disks {
|
2015-07-02 23:31:22 -04:00
|
|
|
dirs, err := disk.ListDir(donut.config.DonutName)
|
2015-06-25 13:43:36 -04: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 15:55:13 -04:00
|
|
|
// we dont need this once we cache from makeDonutBucket()
|
2015-07-02 23:31:22 -04:00
|
|
|
bucket, _, err := newBucket(bucketName, "private", donut.config.DonutName, donut.nodes)
|
2015-06-25 13:43:36 -04:00
|
|
|
if err != nil {
|
|
|
|
return iodine.New(err, nil)
|
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
donut.buckets[bucketName] = bucket
|
2015-06-25 13:43:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|