mirror of
https://github.com/minio/minio.git
synced 2025-11-23 02:57:42 -05:00
fs: Add granular locking.
This commit is contained in:
36
pkg/fs/fs.go
36
pkg/fs/fs.go
@@ -31,7 +31,7 @@ type Filesystem struct {
|
||||
path string
|
||||
minFreeDisk int64
|
||||
maxBuckets int
|
||||
lock *sync.Mutex
|
||||
rwLock *sync.RWMutex
|
||||
multiparts *Multiparts
|
||||
buckets *Buckets
|
||||
listServiceReqCh chan<- listServiceReq
|
||||
@@ -59,7 +59,7 @@ type Multiparts struct {
|
||||
}
|
||||
|
||||
// New instantiate a new donut
|
||||
func New(rootPath string) (Filesystem, *probe.Error) {
|
||||
func New(rootPath string, minFreeDisk int64, maxBuckets int) (Filesystem, *probe.Error) {
|
||||
setFSBucketsConfigPath(filepath.Join(rootPath, "$buckets.json"))
|
||||
setFSMultipartsConfigPath(filepath.Join(rootPath, "$multiparts-session.json"))
|
||||
|
||||
@@ -80,8 +80,11 @@ func New(rootPath string) (Filesystem, *probe.Error) {
|
||||
return Filesystem{}, err.Trace()
|
||||
}
|
||||
}
|
||||
// Initialize content db.
|
||||
contentdb.Init()
|
||||
|
||||
// Initialize contentdb.
|
||||
if e := contentdb.Init(); e != nil {
|
||||
return Filesystem{}, probe.NewError(e)
|
||||
}
|
||||
|
||||
var buckets *Buckets
|
||||
buckets, err = loadBucketsMetadata()
|
||||
@@ -98,16 +101,18 @@ func New(rootPath string) (Filesystem, *probe.Error) {
|
||||
return Filesystem{}, err.Trace()
|
||||
}
|
||||
}
|
||||
fs := Filesystem{lock: new(sync.Mutex)}
|
||||
fs := Filesystem{
|
||||
rwLock: &sync.RWMutex{},
|
||||
}
|
||||
fs.path = rootPath
|
||||
fs.multiparts = multiparts
|
||||
fs.buckets = buckets
|
||||
/// Defaults
|
||||
|
||||
// maximum buckets to be listed from list buckets.
|
||||
fs.maxBuckets = 1000
|
||||
fs.maxBuckets = maxBuckets
|
||||
// minium free disk required for i/o operations to succeed.
|
||||
fs.minFreeDisk = 10
|
||||
fs.minFreeDisk = minFreeDisk
|
||||
|
||||
// Start list goroutine.
|
||||
if err = fs.listObjectsService(); err != nil {
|
||||
@@ -116,20 +121,3 @@ func New(rootPath string) (Filesystem, *probe.Error) {
|
||||
// Return here.
|
||||
return fs, nil
|
||||
}
|
||||
|
||||
// SetMinFreeDisk - set min free disk
|
||||
func (fs *Filesystem) SetMinFreeDisk(minFreeDisk int64) {
|
||||
fs.lock.Lock()
|
||||
defer fs.lock.Unlock()
|
||||
fs.minFreeDisk = minFreeDisk
|
||||
}
|
||||
|
||||
// SetMaxBuckets - set total number of buckets supported, default is 100.
|
||||
func (fs *Filesystem) SetMaxBuckets(maxBuckets int) {
|
||||
fs.lock.Lock()
|
||||
defer fs.lock.Unlock()
|
||||
if maxBuckets == 0 {
|
||||
maxBuckets = 100
|
||||
}
|
||||
fs.maxBuckets = maxBuckets
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user