mirror of
https://github.com/minio/minio.git
synced 2025-11-22 18:47:43 -05:00
pkg/fs: for locks, prefer defer and read-only ops
This commit prefers the use of 'defer' for fs.Unlock (and fs.RUnlock) because it is more idiomatic Go and reduces repetition in the code, lending to a cleaner code base. It also switches a few uses of the lock to read-only locks, which should improve performance of those functions dramatically in certain contexts.
This commit is contained in:
@@ -276,6 +276,7 @@ func (fs Filesystem) NewMultipartUpload(bucket, object string) (string, *probe.E
|
||||
|
||||
// Critical region requiring write lock.
|
||||
fs.rwLock.Lock()
|
||||
defer fs.rwLock.Unlock()
|
||||
// Initialize multipart session.
|
||||
mpartSession := &MultipartSession{}
|
||||
mpartSession.TotalParts = 0
|
||||
@@ -288,10 +289,8 @@ func (fs Filesystem) NewMultipartUpload(bucket, object string) (string, *probe.E
|
||||
|
||||
fs.multiparts.ActiveSession[uploadID] = mpartSession
|
||||
if err := saveMultipartsSession(*fs.multiparts); err != nil {
|
||||
fs.rwLock.Unlock()
|
||||
return "", err.Trace(objectPath)
|
||||
}
|
||||
fs.rwLock.Unlock()
|
||||
return uploadID, nil
|
||||
}
|
||||
|
||||
@@ -445,12 +444,12 @@ func (fs Filesystem) CreateObjectPart(bucket, object, uploadID, expectedMD5Sum s
|
||||
|
||||
// Critical region requiring write lock.
|
||||
fs.rwLock.Lock()
|
||||
defer fs.rwLock.Unlock()
|
||||
|
||||
fs.multiparts.ActiveSession[uploadID] = deserializedMultipartSession
|
||||
if err := saveMultipartsSession(*fs.multiparts); err != nil {
|
||||
fs.rwLock.Unlock()
|
||||
return "", err.Trace(partPathPrefix)
|
||||
}
|
||||
fs.rwLock.Unlock()
|
||||
|
||||
// Return etag.
|
||||
return partMetadata.ETag, nil
|
||||
@@ -693,11 +692,11 @@ func (fs Filesystem) AbortMultipartUpload(bucket, object, uploadID string) *prob
|
||||
|
||||
// Critical region requiring write lock.
|
||||
fs.rwLock.Lock()
|
||||
defer fs.rwLock.Unlock()
|
||||
|
||||
delete(fs.multiparts.ActiveSession, uploadID)
|
||||
if err := saveMultipartsSession(*fs.multiparts); err != nil {
|
||||
fs.rwLock.Unlock()
|
||||
return err.Trace(partPathPrefix)
|
||||
}
|
||||
fs.rwLock.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user