diff --git a/lib/storage/storage.go b/lib/storage/storage.go index 68f64558c..0f92eefe2 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -581,10 +581,15 @@ func (s *Storage) startFreeDiskSpaceWatcher() { freeSpaceBytes := fs.MustGetFreeSpace(s.path) if freeSpaceBytes < freeDiskSpaceLimitBytes { // Switch the storage to readonly mode if there is no enough free space left at s.path + 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) atomic.StoreUint32(&s.isReadOnly, 1) return } - atomic.StoreUint32(&s.isReadOnly, 0) + if atomic.CompareAndSwapUint32(&s.isReadOnly, 1, 0) { + logger.Warnf("enabling writing to the storage at %s, since it has more than -storage.minFreeDiskSpaceBytes=%d of free space: %d bytes left", + s.path, freeDiskSpaceLimitBytes, freeSpaceBytes) + } } f() s.freeDiskSpaceWatcherWG.Add(1)