|
@ -35,6 +35,7 @@ type DiskLocation struct { |
|
|
ecVolumesLock sync.RWMutex |
|
|
ecVolumesLock sync.RWMutex |
|
|
|
|
|
|
|
|
isDiskSpaceLow bool |
|
|
isDiskSpaceLow bool |
|
|
|
|
|
closeCh chan struct{} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func GenerateDirUuid(dir string) (dirUuidString string, err error) { |
|
|
func GenerateDirUuid(dir string) (dirUuidString string, err error) { |
|
@ -80,7 +81,17 @@ func NewDiskLocation(dir string, maxVolumeCount int32, minFreeSpace util.MinFree |
|
|
} |
|
|
} |
|
|
location.volumes = make(map[needle.VolumeId]*Volume) |
|
|
location.volumes = make(map[needle.VolumeId]*Volume) |
|
|
location.ecVolumes = make(map[needle.VolumeId]*erasure_coding.EcVolume) |
|
|
location.ecVolumes = make(map[needle.VolumeId]*erasure_coding.EcVolume) |
|
|
go location.CheckDiskSpace() |
|
|
|
|
|
|
|
|
location.closeCh = make(chan struct{}) |
|
|
|
|
|
go func() { |
|
|
|
|
|
for { |
|
|
|
|
|
select { |
|
|
|
|
|
case <-location.closeCh: |
|
|
|
|
|
return |
|
|
|
|
|
case <-time.After(time.Minute): |
|
|
|
|
|
location.CheckDiskSpace() |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}() |
|
|
return location |
|
|
return location |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -384,6 +395,7 @@ func (l *DiskLocation) Close() { |
|
|
} |
|
|
} |
|
|
l.ecVolumesLock.Unlock() |
|
|
l.ecVolumesLock.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
close(l.closeCh) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -420,26 +432,22 @@ func (l *DiskLocation) UnUsedSpace(volumeSizeLimit uint64) (unUsedSpace uint64) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (l *DiskLocation) CheckDiskSpace() { |
|
|
func (l *DiskLocation) CheckDiskSpace() { |
|
|
for { |
|
|
|
|
|
if dir, e := filepath.Abs(l.Directory); e == nil { |
|
|
|
|
|
s := stats.NewDiskStatus(dir) |
|
|
|
|
|
stats.VolumeServerResourceGauge.WithLabelValues(l.Directory, "all").Set(float64(s.All)) |
|
|
|
|
|
stats.VolumeServerResourceGauge.WithLabelValues(l.Directory, "used").Set(float64(s.Used)) |
|
|
|
|
|
stats.VolumeServerResourceGauge.WithLabelValues(l.Directory, "free").Set(float64(s.Free)) |
|
|
|
|
|
|
|
|
|
|
|
isLow, desc := l.MinFreeSpace.IsLow(s.Free, s.PercentFree) |
|
|
|
|
|
if isLow != l.isDiskSpaceLow { |
|
|
|
|
|
l.isDiskSpaceLow = !l.isDiskSpaceLow |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
logLevel := glog.Level(4) |
|
|
|
|
|
if l.isDiskSpaceLow { |
|
|
|
|
|
logLevel = glog.Level(0) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if dir, e := filepath.Abs(l.Directory); e == nil { |
|
|
|
|
|
s := stats.NewDiskStatus(dir) |
|
|
|
|
|
stats.VolumeServerResourceGauge.WithLabelValues(l.Directory, "all").Set(float64(s.All)) |
|
|
|
|
|
stats.VolumeServerResourceGauge.WithLabelValues(l.Directory, "used").Set(float64(s.Used)) |
|
|
|
|
|
stats.VolumeServerResourceGauge.WithLabelValues(l.Directory, "free").Set(float64(s.Free)) |
|
|
|
|
|
|
|
|
|
|
|
isLow, desc := l.MinFreeSpace.IsLow(s.Free, s.PercentFree) |
|
|
|
|
|
if isLow != l.isDiskSpaceLow { |
|
|
|
|
|
l.isDiskSpaceLow = !l.isDiskSpaceLow |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
glog.V(logLevel).Infof("dir %s %s", dir, desc) |
|
|
|
|
|
|
|
|
logLevel := glog.Level(4) |
|
|
|
|
|
if l.isDiskSpaceLow { |
|
|
|
|
|
logLevel = glog.Level(0) |
|
|
} |
|
|
} |
|
|
time.Sleep(time.Minute) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glog.V(logLevel).Infof("dir %s %s", dir, desc) |
|
|
|
|
|
} |
|
|
} |
|
|
} |