|
|
@ -54,7 +54,7 @@ type Config struct { |
|
|
|
// API - local variables
|
|
|
|
// API - local variables
|
|
|
|
type API struct { |
|
|
|
type API struct { |
|
|
|
config *Config |
|
|
|
config *Config |
|
|
|
lock *sync.RWMutex |
|
|
|
lock *sync.Mutex |
|
|
|
objects *trove.Cache |
|
|
|
objects *trove.Cache |
|
|
|
multiPartObjects *trove.Cache |
|
|
|
multiPartObjects *trove.Cache |
|
|
|
storedBuckets map[string]storedBucket |
|
|
|
storedBuckets map[string]storedBucket |
|
|
@ -90,7 +90,7 @@ func New(c *Config) (Interface, error) { |
|
|
|
a.multiPartObjects = trove.NewCache(0, time.Duration(0)) |
|
|
|
a.multiPartObjects = trove.NewCache(0, time.Duration(0)) |
|
|
|
a.objects.OnExpired = a.expiredObject |
|
|
|
a.objects.OnExpired = a.expiredObject |
|
|
|
a.multiPartObjects.OnExpired = a.expiredPart |
|
|
|
a.multiPartObjects.OnExpired = a.expiredPart |
|
|
|
a.lock = new(sync.RWMutex) |
|
|
|
a.lock = new(sync.Mutex) |
|
|
|
|
|
|
|
|
|
|
|
// set up cache expiration
|
|
|
|
// set up cache expiration
|
|
|
|
a.objects.ExpireObjects(time.Second * 5) |
|
|
|
a.objects.ExpireObjects(time.Second * 5) |
|
|
@ -121,17 +121,15 @@ func New(c *Config) (Interface, error) { |
|
|
|
|
|
|
|
|
|
|
|
// GetObject - GET object from cache buffer
|
|
|
|
// GetObject - GET object from cache buffer
|
|
|
|
func (donut API) GetObject(w io.Writer, bucket string, object string) (int64, error) { |
|
|
|
func (donut API) GetObject(w io.Writer, bucket string, object string) (int64, error) { |
|
|
|
donut.lock.RLock() |
|
|
|
donut.lock.Lock() |
|
|
|
|
|
|
|
defer donut.lock.Unlock() |
|
|
|
if !IsValidBucket(bucket) { |
|
|
|
if !IsValidBucket(bucket) { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return 0, iodine.New(BucketNameInvalid{Bucket: bucket}, nil) |
|
|
|
return 0, iodine.New(BucketNameInvalid{Bucket: bucket}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
if !IsValidObjectName(object) { |
|
|
|
if !IsValidObjectName(object) { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return 0, iodine.New(ObjectNameInvalid{Object: object}, nil) |
|
|
|
return 0, iodine.New(ObjectNameInvalid{Object: object}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
if _, ok := donut.storedBuckets[bucket]; ok == false { |
|
|
|
if _, ok := donut.storedBuckets[bucket]; ok == false { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return 0, iodine.New(BucketNotFound{Bucket: bucket}, nil) |
|
|
|
return 0, iodine.New(BucketNotFound{Bucket: bucket}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
objectKey := bucket + "/" + object |
|
|
|
objectKey := bucket + "/" + object |
|
|
@ -140,60 +138,49 @@ func (donut API) GetObject(w io.Writer, bucket string, object string) (int64, er |
|
|
|
if len(donut.config.NodeDiskMap) > 0 { |
|
|
|
if len(donut.config.NodeDiskMap) > 0 { |
|
|
|
reader, size, err := donut.getObject(bucket, object) |
|
|
|
reader, size, err := donut.getObject(bucket, object) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return 0, iodine.New(err, nil) |
|
|
|
return 0, iodine.New(err, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
// new proxy writer to capture data read from disk
|
|
|
|
// new proxy writer to capture data read from disk
|
|
|
|
pw := NewProxyWriter(w) |
|
|
|
pw := NewProxyWriter(w) |
|
|
|
written, err := io.CopyN(pw, reader, size) |
|
|
|
written, err := io.CopyN(pw, reader, size) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return 0, iodine.New(err, nil) |
|
|
|
return 0, iodine.New(err, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
/// cache object read from disk
|
|
|
|
/// cache object read from disk
|
|
|
|
{ |
|
|
|
ok := donut.objects.Set(objectKey, pw.writtenBytes) |
|
|
|
donut.lock.Lock() |
|
|
|
pw.writtenBytes = nil |
|
|
|
ok := donut.objects.Set(objectKey, pw.writtenBytes) |
|
|
|
go debug.FreeOSMemory() |
|
|
|
donut.lock.Unlock() |
|
|
|
if !ok { |
|
|
|
pw.writtenBytes = nil |
|
|
|
return 0, iodine.New(InternalError{}, nil) |
|
|
|
go debug.FreeOSMemory() |
|
|
|
|
|
|
|
if !ok { |
|
|
|
|
|
|
|
return 0, iodine.New(InternalError{}, nil) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return written, nil |
|
|
|
return written, nil |
|
|
|
} |
|
|
|
} |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return 0, iodine.New(ObjectNotFound{Object: object}, nil) |
|
|
|
return 0, iodine.New(ObjectNotFound{Object: object}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
written, err := io.CopyN(w, bytes.NewBuffer(data), int64(donut.objects.Len(objectKey))) |
|
|
|
written, err := io.CopyN(w, bytes.NewBuffer(data), int64(donut.objects.Len(objectKey))) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return 0, iodine.New(err, nil) |
|
|
|
return 0, iodine.New(err, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return written, nil |
|
|
|
return written, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetPartialObject - GET object from cache buffer range
|
|
|
|
// GetPartialObject - GET object from cache buffer range
|
|
|
|
func (donut API) GetPartialObject(w io.Writer, bucket, object string, start, length int64) (int64, error) { |
|
|
|
func (donut API) GetPartialObject(w io.Writer, bucket, object string, start, length int64) (int64, error) { |
|
|
|
|
|
|
|
donut.lock.Lock() |
|
|
|
|
|
|
|
defer donut.lock.Unlock() |
|
|
|
errParams := map[string]string{ |
|
|
|
errParams := map[string]string{ |
|
|
|
"bucket": bucket, |
|
|
|
"bucket": bucket, |
|
|
|
"object": object, |
|
|
|
"object": object, |
|
|
|
"start": strconv.FormatInt(start, 10), |
|
|
|
"start": strconv.FormatInt(start, 10), |
|
|
|
"length": strconv.FormatInt(length, 10), |
|
|
|
"length": strconv.FormatInt(length, 10), |
|
|
|
} |
|
|
|
} |
|
|
|
donut.lock.RLock() |
|
|
|
|
|
|
|
if !IsValidBucket(bucket) { |
|
|
|
if !IsValidBucket(bucket) { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return 0, iodine.New(BucketNameInvalid{Bucket: bucket}, errParams) |
|
|
|
return 0, iodine.New(BucketNameInvalid{Bucket: bucket}, errParams) |
|
|
|
} |
|
|
|
} |
|
|
|
if !IsValidObjectName(object) { |
|
|
|
if !IsValidObjectName(object) { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return 0, iodine.New(ObjectNameInvalid{Object: object}, errParams) |
|
|
|
return 0, iodine.New(ObjectNameInvalid{Object: object}, errParams) |
|
|
|
} |
|
|
|
} |
|
|
|
if start < 0 { |
|
|
|
if start < 0 { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return 0, iodine.New(InvalidRange{ |
|
|
|
return 0, iodine.New(InvalidRange{ |
|
|
|
Start: start, |
|
|
|
Start: start, |
|
|
|
Length: length, |
|
|
|
Length: length, |
|
|
@ -205,96 +192,73 @@ func (donut API) GetPartialObject(w io.Writer, bucket, object string, start, len |
|
|
|
if len(donut.config.NodeDiskMap) > 0 { |
|
|
|
if len(donut.config.NodeDiskMap) > 0 { |
|
|
|
reader, _, err := donut.getObject(bucket, object) |
|
|
|
reader, _, err := donut.getObject(bucket, object) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return 0, iodine.New(err, nil) |
|
|
|
return 0, iodine.New(err, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
if _, err := io.CopyN(ioutil.Discard, reader, start); err != nil { |
|
|
|
if _, err := io.CopyN(ioutil.Discard, reader, start); err != nil { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return 0, iodine.New(err, nil) |
|
|
|
return 0, iodine.New(err, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
pw := NewProxyWriter(w) |
|
|
|
pw := NewProxyWriter(w) |
|
|
|
written, err := io.CopyN(w, reader, length) |
|
|
|
written, err := io.CopyN(w, reader, length) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return 0, iodine.New(err, nil) |
|
|
|
return 0, iodine.New(err, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
donut.lock.RUnlock() |
|
|
|
ok := donut.objects.Set(objectKey, pw.writtenBytes) |
|
|
|
{ |
|
|
|
pw.writtenBytes = nil |
|
|
|
donut.lock.Lock() |
|
|
|
go debug.FreeOSMemory() |
|
|
|
ok := donut.objects.Set(objectKey, pw.writtenBytes) |
|
|
|
if !ok { |
|
|
|
donut.lock.Unlock() |
|
|
|
return 0, iodine.New(InternalError{}, nil) |
|
|
|
pw.writtenBytes = nil |
|
|
|
|
|
|
|
go debug.FreeOSMemory() |
|
|
|
|
|
|
|
if !ok { |
|
|
|
|
|
|
|
return 0, iodine.New(InternalError{}, nil) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return written, nil |
|
|
|
return written, nil |
|
|
|
} |
|
|
|
} |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return 0, iodine.New(ObjectNotFound{Object: object}, nil) |
|
|
|
return 0, iodine.New(ObjectNotFound{Object: object}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
written, err := io.CopyN(w, bytes.NewBuffer(data[start:]), length) |
|
|
|
written, err := io.CopyN(w, bytes.NewBuffer(data[start:]), length) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return 0, iodine.New(err, nil) |
|
|
|
return 0, iodine.New(err, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return written, nil |
|
|
|
return written, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetBucketMetadata -
|
|
|
|
// GetBucketMetadata -
|
|
|
|
func (donut API) GetBucketMetadata(bucket string) (BucketMetadata, error) { |
|
|
|
func (donut API) GetBucketMetadata(bucket string) (BucketMetadata, error) { |
|
|
|
donut.lock.RLock() |
|
|
|
donut.lock.Lock() |
|
|
|
|
|
|
|
defer donut.lock.Unlock() |
|
|
|
if !IsValidBucket(bucket) { |
|
|
|
if !IsValidBucket(bucket) { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return BucketMetadata{}, iodine.New(BucketNameInvalid{Bucket: bucket}, nil) |
|
|
|
return BucketMetadata{}, iodine.New(BucketNameInvalid{Bucket: bucket}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
if _, ok := donut.storedBuckets[bucket]; ok == false { |
|
|
|
if _, ok := donut.storedBuckets[bucket]; ok == false { |
|
|
|
if len(donut.config.NodeDiskMap) > 0 { |
|
|
|
if len(donut.config.NodeDiskMap) > 0 { |
|
|
|
bucketMetadata, err := donut.getBucketMetadata(bucket) |
|
|
|
bucketMetadata, err := donut.getBucketMetadata(bucket) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return BucketMetadata{}, iodine.New(err, nil) |
|
|
|
return BucketMetadata{}, iodine.New(err, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
storedBucket := donut.storedBuckets[bucket] |
|
|
|
storedBucket := donut.storedBuckets[bucket] |
|
|
|
donut.lock.RUnlock() |
|
|
|
storedBucket.bucketMetadata = bucketMetadata |
|
|
|
{ |
|
|
|
donut.storedBuckets[bucket] = storedBucket |
|
|
|
donut.lock.Lock() |
|
|
|
|
|
|
|
storedBucket.bucketMetadata = bucketMetadata |
|
|
|
|
|
|
|
donut.storedBuckets[bucket] = storedBucket |
|
|
|
|
|
|
|
donut.lock.Unlock() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return BucketMetadata{}, iodine.New(BucketNotFound{Bucket: bucket}, nil) |
|
|
|
return BucketMetadata{}, iodine.New(BucketNotFound{Bucket: bucket}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return donut.storedBuckets[bucket].bucketMetadata, nil |
|
|
|
return donut.storedBuckets[bucket].bucketMetadata, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// SetBucketMetadata -
|
|
|
|
// SetBucketMetadata -
|
|
|
|
func (donut API) SetBucketMetadata(bucket string, metadata map[string]string) error { |
|
|
|
func (donut API) SetBucketMetadata(bucket string, metadata map[string]string) error { |
|
|
|
donut.lock.RLock() |
|
|
|
donut.lock.Lock() |
|
|
|
|
|
|
|
defer donut.lock.Unlock() |
|
|
|
if !IsValidBucket(bucket) { |
|
|
|
if !IsValidBucket(bucket) { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return iodine.New(BucketNameInvalid{Bucket: bucket}, nil) |
|
|
|
return iodine.New(BucketNameInvalid{Bucket: bucket}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
if _, ok := donut.storedBuckets[bucket]; ok == false { |
|
|
|
if _, ok := donut.storedBuckets[bucket]; ok == false { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return iodine.New(BucketNotFound{Bucket: bucket}, nil) |
|
|
|
return iodine.New(BucketNotFound{Bucket: bucket}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
donut.lock.RUnlock() |
|
|
|
if len(donut.config.NodeDiskMap) > 0 { |
|
|
|
donut.lock.Lock() |
|
|
|
if err := donut.setBucketMetadata(bucket, metadata); err != nil { |
|
|
|
{ |
|
|
|
return iodine.New(err, nil) |
|
|
|
if len(donut.config.NodeDiskMap) > 0 { |
|
|
|
|
|
|
|
if err := donut.setBucketMetadata(bucket, metadata); err != nil { |
|
|
|
|
|
|
|
return iodine.New(err, nil) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
storedBucket := donut.storedBuckets[bucket] |
|
|
|
|
|
|
|
storedBucket.bucketMetadata.ACL = BucketACL(metadata["acl"]) |
|
|
|
|
|
|
|
donut.storedBuckets[bucket] = storedBucket |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
donut.lock.Unlock() |
|
|
|
storedBucket := donut.storedBuckets[bucket] |
|
|
|
|
|
|
|
storedBucket.bucketMetadata.ACL = BucketACL(metadata["acl"]) |
|
|
|
|
|
|
|
donut.storedBuckets[bucket] = storedBucket |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -328,7 +292,9 @@ func (donut API) CreateObject(bucket, key, expectedMD5Sum string, size int64, da |
|
|
|
}, nil) |
|
|
|
}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
contentType := metadata["contentType"] |
|
|
|
contentType := metadata["contentType"] |
|
|
|
|
|
|
|
donut.lock.Lock() |
|
|
|
objectMetadata, err := donut.createObject(bucket, key, contentType, expectedMD5Sum, size, data) |
|
|
|
objectMetadata, err := donut.createObject(bucket, key, contentType, expectedMD5Sum, size, data) |
|
|
|
|
|
|
|
donut.lock.Unlock() |
|
|
|
// free
|
|
|
|
// free
|
|
|
|
debug.FreeOSMemory() |
|
|
|
debug.FreeOSMemory() |
|
|
|
return objectMetadata, iodine.New(err, nil) |
|
|
|
return objectMetadata, iodine.New(err, nil) |
|
|
@ -336,27 +302,21 @@ func (donut API) CreateObject(bucket, key, expectedMD5Sum string, size int64, da |
|
|
|
|
|
|
|
|
|
|
|
// createObject - PUT object to cache buffer
|
|
|
|
// createObject - PUT object to cache buffer
|
|
|
|
func (donut API) createObject(bucket, key, contentType, expectedMD5Sum string, size int64, data io.Reader) (ObjectMetadata, error) { |
|
|
|
func (donut API) createObject(bucket, key, contentType, expectedMD5Sum string, size int64, data io.Reader) (ObjectMetadata, error) { |
|
|
|
donut.lock.RLock() |
|
|
|
|
|
|
|
if !IsValidBucket(bucket) { |
|
|
|
if !IsValidBucket(bucket) { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return ObjectMetadata{}, iodine.New(BucketNameInvalid{Bucket: bucket}, nil) |
|
|
|
return ObjectMetadata{}, iodine.New(BucketNameInvalid{Bucket: bucket}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
if !IsValidObjectName(key) { |
|
|
|
if !IsValidObjectName(key) { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return ObjectMetadata{}, iodine.New(ObjectNameInvalid{Object: key}, nil) |
|
|
|
return ObjectMetadata{}, iodine.New(ObjectNameInvalid{Object: key}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
if _, ok := donut.storedBuckets[bucket]; ok == false { |
|
|
|
if _, ok := donut.storedBuckets[bucket]; ok == false { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return ObjectMetadata{}, iodine.New(BucketNotFound{Bucket: bucket}, nil) |
|
|
|
return ObjectMetadata{}, iodine.New(BucketNotFound{Bucket: bucket}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
storedBucket := donut.storedBuckets[bucket] |
|
|
|
storedBucket := donut.storedBuckets[bucket] |
|
|
|
// get object key
|
|
|
|
// get object key
|
|
|
|
objectKey := bucket + "/" + key |
|
|
|
objectKey := bucket + "/" + key |
|
|
|
if _, ok := storedBucket.objectMetadata[objectKey]; ok == true { |
|
|
|
if _, ok := storedBucket.objectMetadata[objectKey]; ok == true { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return ObjectMetadata{}, iodine.New(ObjectExists{Object: key}, nil) |
|
|
|
return ObjectMetadata{}, iodine.New(ObjectExists{Object: key}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if contentType == "" { |
|
|
|
if contentType == "" { |
|
|
|
contentType = "application/octet-stream" |
|
|
|
contentType = "application/octet-stream" |
|
|
@ -376,10 +336,8 @@ func (donut API) createObject(bucket, key, contentType, expectedMD5Sum string, s |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return ObjectMetadata{}, iodine.New(err, nil) |
|
|
|
return ObjectMetadata{}, iodine.New(err, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
donut.lock.Lock() |
|
|
|
|
|
|
|
storedBucket.objectMetadata[objectKey] = objMetadata |
|
|
|
storedBucket.objectMetadata[objectKey] = objMetadata |
|
|
|
donut.storedBuckets[bucket] = storedBucket |
|
|
|
donut.storedBuckets[bucket] = storedBucket |
|
|
|
donut.lock.Unlock() |
|
|
|
|
|
|
|
return objMetadata, nil |
|
|
|
return objMetadata, nil |
|
|
|
} |
|
|
|
} |
|
|
|
// calculate md5
|
|
|
|
// calculate md5
|
|
|
@ -397,9 +355,7 @@ func (donut API) createObject(bucket, key, contentType, expectedMD5Sum string, s |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
hash.Write(byteBuffer[0:length]) |
|
|
|
hash.Write(byteBuffer[0:length]) |
|
|
|
//donut.lock.Lock()
|
|
|
|
|
|
|
|
ok := donut.objects.Append(objectKey, byteBuffer[0:length]) |
|
|
|
ok := donut.objects.Append(objectKey, byteBuffer[0:length]) |
|
|
|
//donut.lock.Unlock()
|
|
|
|
|
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
return ObjectMetadata{}, iodine.New(InternalError{}, nil) |
|
|
|
return ObjectMetadata{}, iodine.New(InternalError{}, nil) |
|
|
|
} |
|
|
|
} |
|
|
@ -431,33 +387,27 @@ func (donut API) createObject(bucket, key, contentType, expectedMD5Sum string, s |
|
|
|
Size: int64(totalLength), |
|
|
|
Size: int64(totalLength), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//donut.lock.Lock()
|
|
|
|
|
|
|
|
storedBucket.objectMetadata[objectKey] = newObject |
|
|
|
storedBucket.objectMetadata[objectKey] = newObject |
|
|
|
donut.storedBuckets[bucket] = storedBucket |
|
|
|
donut.storedBuckets[bucket] = storedBucket |
|
|
|
//donut.lock.Unlock()
|
|
|
|
|
|
|
|
return newObject, nil |
|
|
|
return newObject, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// MakeBucket - create bucket in cache
|
|
|
|
// MakeBucket - create bucket in cache
|
|
|
|
func (donut API) MakeBucket(bucketName, acl string) error { |
|
|
|
func (donut API) MakeBucket(bucketName, acl string) error { |
|
|
|
donut.lock.RLock() |
|
|
|
donut.lock.Lock() |
|
|
|
|
|
|
|
defer donut.lock.Unlock() |
|
|
|
if len(donut.storedBuckets) == totalBuckets { |
|
|
|
if len(donut.storedBuckets) == totalBuckets { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return iodine.New(TooManyBuckets{Bucket: bucketName}, nil) |
|
|
|
return iodine.New(TooManyBuckets{Bucket: bucketName}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
if !IsValidBucket(bucketName) { |
|
|
|
if !IsValidBucket(bucketName) { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return iodine.New(BucketNameInvalid{Bucket: bucketName}, nil) |
|
|
|
return iodine.New(BucketNameInvalid{Bucket: bucketName}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
if !IsValidBucketACL(acl) { |
|
|
|
if !IsValidBucketACL(acl) { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return iodine.New(InvalidACL{ACL: acl}, nil) |
|
|
|
return iodine.New(InvalidACL{ACL: acl}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
if _, ok := donut.storedBuckets[bucketName]; ok == true { |
|
|
|
if _, ok := donut.storedBuckets[bucketName]; ok == true { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return iodine.New(BucketExists{Bucket: bucketName}, nil) |
|
|
|
return iodine.New(BucketExists{Bucket: bucketName}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if strings.TrimSpace(acl) == "" { |
|
|
|
if strings.TrimSpace(acl) == "" { |
|
|
|
// default is private
|
|
|
|
// default is private
|
|
|
@ -476,16 +426,14 @@ func (donut API) MakeBucket(bucketName, acl string) error { |
|
|
|
newBucket.bucketMetadata.Name = bucketName |
|
|
|
newBucket.bucketMetadata.Name = bucketName |
|
|
|
newBucket.bucketMetadata.Created = time.Now().UTC() |
|
|
|
newBucket.bucketMetadata.Created = time.Now().UTC() |
|
|
|
newBucket.bucketMetadata.ACL = BucketACL(acl) |
|
|
|
newBucket.bucketMetadata.ACL = BucketACL(acl) |
|
|
|
//donut.lock.Lock()
|
|
|
|
|
|
|
|
donut.storedBuckets[bucketName] = newBucket |
|
|
|
donut.storedBuckets[bucketName] = newBucket |
|
|
|
//donut.lock.Unlock()
|
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ListObjects - list objects from cache
|
|
|
|
// ListObjects - list objects from cache
|
|
|
|
func (donut API) ListObjects(bucket string, resources BucketResourcesMetadata) ([]ObjectMetadata, BucketResourcesMetadata, error) { |
|
|
|
func (donut API) ListObjects(bucket string, resources BucketResourcesMetadata) ([]ObjectMetadata, BucketResourcesMetadata, error) { |
|
|
|
donut.lock.RLock() |
|
|
|
donut.lock.Lock() |
|
|
|
defer donut.lock.RUnlock() |
|
|
|
defer donut.lock.Unlock() |
|
|
|
if !IsValidBucket(bucket) { |
|
|
|
if !IsValidBucket(bucket) { |
|
|
|
return nil, BucketResourcesMetadata{IsTruncated: false}, iodine.New(BucketNameInvalid{Bucket: bucket}, nil) |
|
|
|
return nil, BucketResourcesMetadata{IsTruncated: false}, iodine.New(BucketNameInvalid{Bucket: bucket}, nil) |
|
|
|
} |
|
|
|
} |
|
|
@ -577,8 +525,8 @@ func (b byBucketName) Less(i, j int) bool { return b[i].Name < b[j].Name } |
|
|
|
|
|
|
|
|
|
|
|
// ListBuckets - List buckets from cache
|
|
|
|
// ListBuckets - List buckets from cache
|
|
|
|
func (donut API) ListBuckets() ([]BucketMetadata, error) { |
|
|
|
func (donut API) ListBuckets() ([]BucketMetadata, error) { |
|
|
|
donut.lock.RLock() |
|
|
|
donut.lock.Lock() |
|
|
|
defer donut.lock.RUnlock() |
|
|
|
defer donut.lock.Unlock() |
|
|
|
var results []BucketMetadata |
|
|
|
var results []BucketMetadata |
|
|
|
for _, bucket := range donut.storedBuckets { |
|
|
|
for _, bucket := range donut.storedBuckets { |
|
|
|
results = append(results, bucket.bucketMetadata) |
|
|
|
results = append(results, bucket.bucketMetadata) |
|
|
@ -589,39 +537,32 @@ func (donut API) ListBuckets() ([]BucketMetadata, error) { |
|
|
|
|
|
|
|
|
|
|
|
// GetObjectMetadata - get object metadata from cache
|
|
|
|
// GetObjectMetadata - get object metadata from cache
|
|
|
|
func (donut API) GetObjectMetadata(bucket, key string) (ObjectMetadata, error) { |
|
|
|
func (donut API) GetObjectMetadata(bucket, key string) (ObjectMetadata, error) { |
|
|
|
donut.lock.RLock() |
|
|
|
donut.lock.Lock() |
|
|
|
|
|
|
|
defer donut.lock.Unlock() |
|
|
|
// check if bucket exists
|
|
|
|
// check if bucket exists
|
|
|
|
if !IsValidBucket(bucket) { |
|
|
|
if !IsValidBucket(bucket) { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return ObjectMetadata{}, iodine.New(BucketNameInvalid{Bucket: bucket}, nil) |
|
|
|
return ObjectMetadata{}, iodine.New(BucketNameInvalid{Bucket: bucket}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
if !IsValidObjectName(key) { |
|
|
|
if !IsValidObjectName(key) { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return ObjectMetadata{}, iodine.New(ObjectNameInvalid{Object: key}, nil) |
|
|
|
return ObjectMetadata{}, iodine.New(ObjectNameInvalid{Object: key}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
if _, ok := donut.storedBuckets[bucket]; ok == false { |
|
|
|
if _, ok := donut.storedBuckets[bucket]; ok == false { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return ObjectMetadata{}, iodine.New(BucketNotFound{Bucket: bucket}, nil) |
|
|
|
return ObjectMetadata{}, iodine.New(BucketNotFound{Bucket: bucket}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
storedBucket := donut.storedBuckets[bucket] |
|
|
|
storedBucket := donut.storedBuckets[bucket] |
|
|
|
objectKey := bucket + "/" + key |
|
|
|
objectKey := bucket + "/" + key |
|
|
|
if objMetadata, ok := storedBucket.objectMetadata[objectKey]; ok == true { |
|
|
|
if objMetadata, ok := storedBucket.objectMetadata[objectKey]; ok == true { |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return objMetadata, nil |
|
|
|
return objMetadata, nil |
|
|
|
} |
|
|
|
} |
|
|
|
if len(donut.config.NodeDiskMap) > 0 { |
|
|
|
if len(donut.config.NodeDiskMap) > 0 { |
|
|
|
objMetadata, err := donut.getObjectMetadata(bucket, key) |
|
|
|
objMetadata, err := donut.getObjectMetadata(bucket, key) |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return ObjectMetadata{}, iodine.New(err, nil) |
|
|
|
return ObjectMetadata{}, iodine.New(err, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
// update
|
|
|
|
// update
|
|
|
|
donut.lock.Lock() |
|
|
|
|
|
|
|
storedBucket.objectMetadata[objectKey] = objMetadata |
|
|
|
storedBucket.objectMetadata[objectKey] = objMetadata |
|
|
|
donut.lock.Unlock() |
|
|
|
|
|
|
|
return objMetadata, nil |
|
|
|
return objMetadata, nil |
|
|
|
} |
|
|
|
} |
|
|
|
donut.lock.RUnlock() |
|
|
|
|
|
|
|
return ObjectMetadata{}, iodine.New(ObjectNotFound{Object: key}, nil) |
|
|
|
return ObjectMetadata{}, iodine.New(ObjectNotFound{Object: key}, nil) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|