fix(wal): Move WAL disk check to platform-specific code (#19619)

This commit is contained in:
Paul Rogers
2025-10-28 10:02:53 -04:00
committed by GitHub
parent 91e11fce62
commit 2b604f1f29
3 changed files with 41 additions and 17 deletions

View File

@@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"sync"
"syscall"
"time"
"go.uber.org/atomic"
@@ -170,22 +169,6 @@ func (w *walWrapper) checkpointWriter() *WALCheckpointWriter {
}
}
// checkDiskUsage returns the disk usage percentage (0.0 to 1.0) for the WAL directory.
func (w *walWrapper) checkDiskUsage() (float64, error) {
var stat syscall.Statfs_t
if err := syscall.Statfs(w.cfg.Dir, &stat); err != nil {
return 0, err
}
// Calculate usage percentage
total := stat.Blocks * uint64(stat.Bsize)
free := stat.Bfree * uint64(stat.Bsize)
used := total - free
usagePercent := float64(used) / float64(total)
return usagePercent, nil
}
func (w *walWrapper) run() {
level.Info(util_log.Logger).Log("msg", "started", "component", "wal")
defer w.wait.Done()

23
pkg/ingester/wal_unix.go Normal file
View File

@@ -0,0 +1,23 @@
//go:build !windows
package ingester
import (
"syscall"
)
// checkDiskUsage returns the disk usage percentage (0.0 to 1.0) for the WAL directory.
func (w *walWrapper) checkDiskUsage() (float64, error) {
var stat syscall.Statfs_t
if err := syscall.Statfs(w.cfg.Dir, &stat); err != nil {
return 0, err
}
// Calculate usage percentage
total := stat.Blocks * uint64(stat.Bsize)
free := stat.Bfree * uint64(stat.Bsize)
used := total - free
usagePercent := float64(used) / float64(total)
return usagePercent, nil
}

View File

@@ -0,0 +1,18 @@
//go:build windows
package ingester
import (
"syscall"
)
var (
kernel32 = syscall.NewLazyDLL("kernel32.dll")
procGetDiskFreeSpaceEx = kernel32.NewProc("GetDiskFreeSpaceExW")
)
// checkDiskUsage returns the disk usage percentage (0.0 to 1.0) for the WAL directory.
func (w *walWrapper) checkDiskUsage() (float64, error) {
// Disable this for Windows for now
return 0.0, nil
}