mirror of
https://github.com/minio/minio.git
synced 2025-11-23 19:17: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:
@@ -58,12 +58,12 @@ func (fs Filesystem) DeleteBucket(bucket string) *probe.Error {
|
||||
|
||||
// Critical region hold write lock.
|
||||
fs.rwLock.Lock()
|
||||
defer fs.rwLock.Unlock()
|
||||
|
||||
delete(fs.buckets.Metadata, bucket)
|
||||
if err := saveBucketsMetadata(*fs.buckets); err != nil {
|
||||
fs.rwLock.Unlock()
|
||||
return err.Trace(bucket)
|
||||
}
|
||||
fs.rwLock.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -171,12 +171,12 @@ func (fs Filesystem) MakeBucket(bucket, acl string) *probe.Error {
|
||||
|
||||
// Critical region hold a write lock.
|
||||
fs.rwLock.Lock()
|
||||
defer fs.rwLock.Unlock()
|
||||
|
||||
fs.buckets.Metadata[bucket] = bucketMetadata
|
||||
if err := saveBucketsMetadata(*fs.buckets); err != nil {
|
||||
fs.rwLock.Unlock()
|
||||
return err.Trace(bucket)
|
||||
}
|
||||
fs.rwLock.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -266,11 +266,11 @@ func (fs Filesystem) SetBucketMetadata(bucket string, metadata map[string]string
|
||||
|
||||
// Critical region handle write lock.
|
||||
fs.rwLock.Lock()
|
||||
defer fs.rwLock.Unlock()
|
||||
|
||||
fs.buckets.Metadata[bucket] = bucketMetadata
|
||||
if err := saveBucketsMetadata(*fs.buckets); err != nil {
|
||||
fs.rwLock.Unlock()
|
||||
return err.Trace(bucket)
|
||||
}
|
||||
fs.rwLock.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user