mirror of
https://github.com/minio/minio.git
synced 2025-11-20 01:50:24 -05:00
Allow usage check to be configurable (#6006)
This commit is contained in:
committed by
kannappanr
parent
df1b33013f
commit
6fb0604502
52
cmd/posix.go
52
cmd/posix.go
@@ -44,15 +44,18 @@ const (
|
||||
|
||||
// posix - implements StorageAPI interface.
|
||||
type posix struct {
|
||||
ioErrCount int32 // ref: https://golang.org/pkg/sync/atomic/#pkg-note-BUG
|
||||
diskPath string
|
||||
pool sync.Pool
|
||||
connected bool
|
||||
// Disk usage metrics
|
||||
totalUsed uint64 // ref: https://golang.org/pkg/sync/atomic/#pkg-note-BUG
|
||||
// Disk usage running routine
|
||||
usageRunning int32 // ref: https://golang.org/pkg/sync/atomic/#pkg-note-BUG
|
||||
ioErrCount int32 // ref: https://golang.org/pkg/sync/atomic/#pkg-note-BUG
|
||||
|
||||
diskPath string
|
||||
pool sync.Pool
|
||||
connected bool
|
||||
|
||||
// Disk usage metrics
|
||||
stopUsageCh chan struct{}
|
||||
totalUsage uint64
|
||||
usageCheckInterval time.Duration
|
||||
stopUsageCh chan struct{}
|
||||
}
|
||||
|
||||
// checkPathLength - returns error if given path name length more than 255
|
||||
@@ -164,13 +167,12 @@ func newPosix(path string) (StorageAPI, error) {
|
||||
return &b
|
||||
},
|
||||
},
|
||||
stopUsageCh: make(chan struct{}),
|
||||
usageCheckInterval: usageCheckInterval,
|
||||
stopUsageCh: make(chan struct{}),
|
||||
}
|
||||
|
||||
st.connected = true
|
||||
|
||||
go st.diskUsage()
|
||||
go st.diskUsage(globalServiceDoneCh)
|
||||
|
||||
// Success.
|
||||
return st, nil
|
||||
@@ -281,7 +283,7 @@ func (s *posix) DiskInfo() (info DiskInfo, err error) {
|
||||
return DiskInfo{
|
||||
Total: di.Total,
|
||||
Free: di.Free,
|
||||
Used: atomic.LoadUint64(&s.totalUsage),
|
||||
Used: atomic.LoadUint64(&s.totalUsed),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -315,8 +317,8 @@ func (s *posix) checkDiskFound() (err error) {
|
||||
}
|
||||
|
||||
// diskUsage returns du information for the posix path, in a continuous routine.
|
||||
func (s *posix) diskUsage() {
|
||||
ticker := time.NewTicker(s.usageCheckInterval)
|
||||
func (s *posix) diskUsage(doneCh chan struct{}) {
|
||||
ticker := time.NewTicker(globalUsageCheckInterval)
|
||||
defer ticker.Stop()
|
||||
|
||||
usageFn := func(ctx context.Context, entry string) error {
|
||||
@@ -328,11 +330,18 @@ func (s *posix) diskUsage() {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
atomic.AddUint64(&s.totalUsage, uint64(fi.Size()))
|
||||
atomic.AddUint64(&s.totalUsed, uint64(fi.Size()))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Check if disk usage routine is running, if yes then return.
|
||||
if atomic.LoadInt32(&s.usageRunning) == 1 {
|
||||
return
|
||||
}
|
||||
atomic.StoreInt32(&s.usageRunning, 1)
|
||||
defer atomic.StoreInt32(&s.usageRunning, 0)
|
||||
|
||||
if err := getDiskUsage(context.Background(), s.diskPath, usageFn); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -341,9 +350,16 @@ func (s *posix) diskUsage() {
|
||||
select {
|
||||
case <-s.stopUsageCh:
|
||||
return
|
||||
case <-globalServiceDoneCh:
|
||||
case <-doneCh:
|
||||
return
|
||||
case <-ticker.C:
|
||||
// Check if disk usage routine is running, if yes let it
|
||||
// finish, before starting a new one.
|
||||
if atomic.LoadInt32(&s.usageRunning) == 1 {
|
||||
continue
|
||||
}
|
||||
atomic.StoreInt32(&s.usageRunning, 1)
|
||||
|
||||
var usage uint64
|
||||
usageFn = func(ctx context.Context, entry string) error {
|
||||
select {
|
||||
@@ -358,10 +374,14 @@ func (s *posix) diskUsage() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if err := getDiskUsage(context.Background(), s.diskPath, usageFn); err != nil {
|
||||
atomic.StoreInt32(&s.usageRunning, 0)
|
||||
continue
|
||||
}
|
||||
atomic.StoreUint64(&s.totalUsage, usage)
|
||||
|
||||
atomic.StoreInt32(&s.usageRunning, 0)
|
||||
atomic.StoreUint64(&s.totalUsed, usage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user