mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 12:31:07 +01:00
lib/storage: follow-up for 29cebd82fb
Use atomic.CompareAndSwapUint32() instead of atomic.LoadUint32() followed by atomic.StoreUint32(). This makes the code more clear. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5159
This commit is contained in:
parent
f6208965ce
commit
7ac49162c6
@ -648,13 +648,12 @@ func (s *Storage) startFreeDiskSpaceWatcher() {
|
|||||||
f := func() {
|
f := func() {
|
||||||
freeSpaceBytes := fs.MustGetFreeSpace(s.path)
|
freeSpaceBytes := fs.MustGetFreeSpace(s.path)
|
||||||
if freeSpaceBytes < freeDiskSpaceLimitBytes {
|
if freeSpaceBytes < freeDiskSpaceLimitBytes {
|
||||||
if atomic.LoadUint32(&s.isReadOnly) == 0 {
|
// Switch the storage to readonly mode if there is no enough free space left at s.path
|
||||||
|
if atomic.CompareAndSwapUint32(&s.isReadOnly, 0, 1) {
|
||||||
// log notification only on state change
|
// log notification only on state change
|
||||||
logger.Warnf("switching the storage at %s to read-only mode, since it has less than -storage.minFreeDiskSpaceBytes=%d of free space: %d bytes left",
|
logger.Warnf("switching the storage at %s to read-only mode, since it has less than -storage.minFreeDiskSpaceBytes=%d of free space: %d bytes left",
|
||||||
s.path, freeDiskSpaceLimitBytes, freeSpaceBytes)
|
s.path, freeDiskSpaceLimitBytes, freeSpaceBytes)
|
||||||
}
|
}
|
||||||
// Switch the storage to readonly mode if there is no enough free space left at s.path
|
|
||||||
atomic.StoreUint32(&s.isReadOnly, 1)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if atomic.CompareAndSwapUint32(&s.isReadOnly, 1, 0) {
|
if atomic.CompareAndSwapUint32(&s.isReadOnly, 1, 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user