Move PutObject body read outside lock

This commit is contained in:
shabbyrobe
2019-03-11 22:30:25 +11:00
parent 5f66bb9c23
commit ead3e06c9d

View File

@@ -216,6 +216,14 @@ func (db *Backend) GetObject(bucketName, objectName string, rangeRequest *gofake
}
func (db *Backend) PutObject(bucketName, objectName string, meta map[string]string, input io.Reader, size int64) (result gofakes3.PutObjectResult, err error) {
// No need to lock the backend while we read the data into memory; it holds
// the write lock open unnecessarily, and could be blocked for an unreasonably
// long time by a connection timing out:
bts, err := gofakes3.ReadAll(input, size)
if err != nil {
return result, err
}
db.lock.Lock()
defer db.lock.Unlock()
@@ -224,11 +232,6 @@ func (db *Backend) PutObject(bucketName, objectName string, meta map[string]stri
return result, gofakes3.BucketNotFound(bucketName)
}
bts, err := gofakes3.ReadAll(input, size)
if err != nil {
return result, err
}
hash := md5.Sum(bts)
item := &bucketData{