Merge pull request #561 from fkautz/pr_out_attempt_to_fix_memory_lock_on_get_preventing_write

This commit is contained in:
Frederick F. Kautz IV 2015-05-01 17:52:24 -07:00
commit b624072dbb

View File

@ -100,14 +100,16 @@ func start(ctrlChannel <-chan string, errorChannel chan<- error) {
// GetObject - GET object from memory buffer
func (memory *memoryDriver) GetObject(w io.Writer, bucket string, object string) (int64, error) {
memory.lock.RLock()
defer memory.lock.RUnlock()
if !drivers.IsValidBucket(bucket) {
memory.lock.RUnlock()
return 0, iodine.New(drivers.BucketNameInvalid{Bucket: bucket}, nil)
}
if !drivers.IsValidObject(object) {
memory.lock.RUnlock()
return 0, iodine.New(drivers.ObjectNameInvalid{Object: object}, nil)
}
if _, ok := memory.storedBuckets[bucket]; ok == false {
memory.lock.RUnlock()
return 0, iodine.New(drivers.BucketNotFound{Bucket: bucket}, nil)
}
storedBucket := memory.storedBuckets[bucket]
@ -117,11 +119,13 @@ func (memory *memoryDriver) GetObject(w io.Writer, bucket string, object string)
if data, ok := memory.objects.Get(objectKey); ok {
dataSlice := data.([]byte)
objectBuffer := bytes.NewBuffer(dataSlice)
written, err := io.Copy(w, objectBuffer)
memory.lock.RUnlock()
go memory.updateAccessTime(objectKey)
written, err := io.Copy(w, objectBuffer)
return written, iodine.New(err, nil)
}
}
memory.lock.RUnlock()
return 0, iodine.New(drivers.ObjectNotFound{Bucket: bucket, Object: object}, nil)
}