From 53bb58ed2aee9b0562cb3d16729190e2c95b351f Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 19 Oct 2021 23:58:05 +0300 Subject: [PATCH] lib/storage: log a warning when the -storageDataPath has less than -storage.minFreeDiskSpaceBytes This should improve the debuggability of the readonly feature. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1727 --- lib/storage/storage.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/storage/storage.go b/lib/storage/storage.go index 68f64558cb..0f92eefe27 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)