mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00: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
8c3bac8f40
commit
c22b63af04
1 changed files with 2 additions and 3 deletions
|
@ -663,13 +663,12 @@ func (s *Storage) startFreeDiskSpaceWatcher() {
|
|||
f := func() {
|
||||
freeSpaceBytes := fs.MustGetFreeSpace(s.path)
|
||||
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
|
||||
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)
|
||||
}
|
||||
// Switch the storage to readonly mode if there is no enough free space left at s.path
|
||||
atomic.StoreUint32(&s.isReadOnly, 1)
|
||||
return
|
||||
}
|
||||
if atomic.CompareAndSwapUint32(&s.isReadOnly, 1, 0) {
|
||||
|
|
Loading…
Reference in a new issue