Merge pull request #684 from harshavardhana/pr_out_make_sure_to_populate_on_disk_data_into_memory_upon_first_api_requests

This commit is contained in:
Harshavardhana 2015-06-28 01:28:29 +00:00
commit 762aae7c32
2 changed files with 56 additions and 22 deletions

View File

@ -188,7 +188,7 @@ func (d donutDriver) ListBuckets() (results []drivers.BucketMetadata, err error)
} }
buckets, err := d.donut.ListBuckets() buckets, err := d.donut.ListBuckets()
if err != nil { if err != nil {
return nil, err return nil, iodine.New(err, nil)
} }
for bucketName, metadata := range buckets { for bucketName, metadata := range buckets {
result := drivers.BucketMetadata{ result := drivers.BucketMetadata{
@ -198,6 +198,15 @@ func (d donutDriver) ListBuckets() (results []drivers.BucketMetadata, err error)
} }
d.lock.Lock() d.lock.Lock()
storedBucket := d.storedBuckets[bucketName] storedBucket := d.storedBuckets[bucketName]
if len(storedBucket.multiPartSession) == 0 {
storedBucket.multiPartSession = make(map[string]multiPartSession)
}
if len(storedBucket.objectMetadata) == 0 {
storedBucket.objectMetadata = make(map[string]drivers.ObjectMetadata)
}
if len(storedBucket.partMetadata) == 0 {
storedBucket.partMetadata = make(map[string]drivers.PartMetadata)
}
storedBucket.bucketMetadata = result storedBucket.bucketMetadata = result
d.storedBuckets[bucketName] = storedBucket d.storedBuckets[bucketName] = storedBucket
d.lock.Unlock() d.lock.Unlock()
@ -407,14 +416,13 @@ func (d donutDriver) GetObjectMetadata(bucketName, objectName string) (drivers.O
if !drivers.IsValidObjectName(objectName) { if !drivers.IsValidObjectName(objectName) {
return drivers.ObjectMetadata{}, iodine.New(drivers.ObjectNameInvalid{Object: objectName}, errParams) return drivers.ObjectMetadata{}, iodine.New(drivers.ObjectNameInvalid{Object: objectName}, errParams)
} }
if _, ok := d.storedBuckets[bucketName]; !ok { if _, ok := d.storedBuckets[bucketName]; ok {
return drivers.ObjectMetadata{}, iodine.New(drivers.BucketNotFound{Bucket: bucketName}, nil)
}
storedBucket := d.storedBuckets[bucketName] storedBucket := d.storedBuckets[bucketName]
objectKey := bucketName + "/" + objectName objectKey := bucketName + "/" + objectName
if object, ok := storedBucket.objectMetadata[objectKey]; ok { if object, ok := storedBucket.objectMetadata[objectKey]; ok {
return object, nil return object, nil
} }
}
metadata, err := d.donut.GetObjectMetadata(bucketName, objectName) metadata, err := d.donut.GetObjectMetadata(bucketName, objectName)
if err != nil { if err != nil {
return drivers.ObjectMetadata{}, iodine.New(drivers.ObjectNotFound{ return drivers.ObjectMetadata{}, iodine.New(drivers.ObjectNotFound{

View File

@ -54,40 +54,66 @@ func isMD5SumEqual(expectedMD5Sum, actualMD5Sum string) error {
return iodine.New(errors.New("invalid argument"), nil) return iodine.New(errors.New("invalid argument"), nil)
} }
func (d donutDriver) NewMultipartUpload(bucket, key, contentType string) (string, error) { func (d donutDriver) NewMultipartUpload(bucketName, objectName, contentType string) (string, error) {
d.lock.RLock() d.lock.RLock()
if !drivers.IsValidBucket(bucket) { if !drivers.IsValidBucket(bucketName) {
d.lock.RUnlock() d.lock.RUnlock()
return "", iodine.New(drivers.BucketNameInvalid{Bucket: bucket}, nil) return "", iodine.New(drivers.BucketNameInvalid{Bucket: bucketName}, nil)
} }
if !drivers.IsValidObjectName(key) { if !drivers.IsValidObjectName(objectName) {
d.lock.RUnlock() d.lock.RUnlock()
return "", iodine.New(drivers.ObjectNameInvalid{Object: key}, nil) return "", iodine.New(drivers.ObjectNameInvalid{Object: objectName}, nil)
} }
if _, ok := d.storedBuckets[bucket]; ok == false {
d.lock.RUnlock() d.lock.RUnlock()
return "", iodine.New(drivers.BucketNotFound{Bucket: bucket}, nil) buckets, err := d.donut.ListBuckets()
if err != nil {
return "", iodine.New(err, nil)
} }
storedBucket := d.storedBuckets[bucket] for bucketName, metadata := range buckets {
objectKey := bucket + "/" + key result := drivers.BucketMetadata{
Name: metadata.Name,
Created: metadata.Created,
ACL: drivers.BucketACL(metadata.ACL),
}
d.lock.Lock()
storedBucket := d.storedBuckets[bucketName]
storedBucket.bucketMetadata = result
if len(storedBucket.multiPartSession) == 0 {
storedBucket.multiPartSession = make(map[string]multiPartSession)
}
if len(storedBucket.objectMetadata) == 0 {
storedBucket.objectMetadata = make(map[string]drivers.ObjectMetadata)
}
if len(storedBucket.partMetadata) == 0 {
storedBucket.partMetadata = make(map[string]drivers.PartMetadata)
}
d.storedBuckets[bucketName] = storedBucket
d.lock.Unlock()
}
d.lock.RLock()
if _, ok := d.storedBuckets[bucketName]; ok == false {
d.lock.RUnlock()
return "", iodine.New(drivers.BucketNotFound{Bucket: bucketName}, nil)
}
storedBucket := d.storedBuckets[bucketName]
objectKey := bucketName + "/" + objectName
if _, ok := storedBucket.objectMetadata[objectKey]; ok == true { if _, ok := storedBucket.objectMetadata[objectKey]; ok == true {
d.lock.RUnlock() d.lock.RUnlock()
return "", iodine.New(drivers.ObjectExists{Bucket: bucket, Object: key}, nil) return "", iodine.New(drivers.ObjectExists{Bucket: bucketName, Object: objectName}, nil)
} }
d.lock.RUnlock() d.lock.RUnlock()
d.lock.Lock() d.lock.Lock()
id := []byte(strconv.FormatInt(rand.Int63(), 10) + bucket + key + time.Now().String()) id := []byte(strconv.FormatInt(rand.Int63(), 10) + bucketName + objectName + time.Now().String())
uploadIDSum := sha512.Sum512(id) uploadIDSum := sha512.Sum512(id)
uploadID := base64.URLEncoding.EncodeToString(uploadIDSum[:])[:47] uploadID := base64.URLEncoding.EncodeToString(uploadIDSum[:])[:47]
d.storedBuckets[bucket].multiPartSession[key] = multiPartSession{ d.storedBuckets[bucketName].multiPartSession[objectName] = multiPartSession{
uploadID: uploadID, uploadID: uploadID,
initiated: time.Now(), initiated: time.Now().UTC(),
totalParts: 0, totalParts: 0,
} }
d.lock.Unlock() d.lock.Unlock()
return uploadID, nil return uploadID, nil
} }