mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/fs: follow-up after f3a03c4164
This commit is contained in:
parent
f3a03c4164
commit
7cc3d96a41
9 changed files with 24 additions and 50 deletions
1
.github/workflows/main.yml
vendored
1
.github/workflows/main.yml
vendored
|
@ -58,6 +58,7 @@ jobs:
|
|||
GOOS=darwin go build -mod=vendor ./app/vmbackup
|
||||
GOOS=darwin go build -mod=vendor ./app/vmrestore
|
||||
GOOS=darwin go build -mod=vendor ./app/vmctl
|
||||
CGO_ENABLED=0 GOOS=windows go build -mod=vendor ./app/vmagent
|
||||
- name: Publish coverage
|
||||
uses: codecov/codecov-action@v1.0.6
|
||||
with:
|
||||
|
|
|
@ -73,10 +73,6 @@ vmagent-ppc64le:
|
|||
vmagent-386:
|
||||
CGO_ENABLED=0 GOARCH=386 $(MAKE) vmagent-local-with-goarch
|
||||
|
||||
vmagent-windows:
|
||||
GOOS=windows CGO_ENABLED=0 $(MAKE) vmagent-local-with-goarch
|
||||
|
||||
|
||||
vmagent-local-with-goarch:
|
||||
APP_NAME=vmagent $(MAKE) app-local-with-goarch
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* FEATURE: vmagent: optimize [relabeling](https://victoriametrics.github.io/vmagent.html#relabeling) performance for common cases.
|
||||
* FEATURE: add `increase_pure(m[d])` function to MetricsQL. It works the same as `increase(m[d])` except of various edge cases. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/962) for details.
|
||||
* FEATURE: increase accuracy for `buckets_limit(limit, buckets)` results for small `limit` values. See [MetricsQL docs](https://victoriametrics.github.io/MetricsQL.html) for details.
|
||||
* FEATURE: vmagent: initial support for Windows build with `CGO_ENABLED=0 GOOS=windows go build -mod=vendor ./app/vmagent`. See [this](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/70) and [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1036).
|
||||
|
||||
* BUGFIX: vmagent: properly perform graceful shutdown on `SIGINT` and `SIGTERM` signals. The graceful shutdown has been broken in `v1.54.0`. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1065
|
||||
* BUGFIX: reduce the probability of `duplicate time series` errors when querying Kubernetes metrics.
|
||||
|
|
|
@ -321,7 +321,8 @@ func MustWriteData(w io.Writer, data []byte) {
|
|||
// CreateFlockFile creates flock.lock file in the directory dir
|
||||
// and returns the handler to the file.
|
||||
func CreateFlockFile(dir string) (*os.File, error) {
|
||||
return createFlockFile(dir)
|
||||
flockFile := dir + "/flock.lock"
|
||||
return createFlockFile(flockFile)
|
||||
}
|
||||
|
||||
// MustGetFreeSpace returns free space for the given directory path.
|
||||
|
|
|
@ -3,27 +3,9 @@
|
|||
package fs
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func mustGetFreeSpace(path string) uint64 {
|
||||
d, err := os.Open(path)
|
||||
if err != nil {
|
||||
logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err)
|
||||
}
|
||||
defer MustClose(d)
|
||||
|
||||
fd := d.Fd()
|
||||
var stat unix.Statfs_t
|
||||
if err := unix.Fstatfs(int(fd), &stat); err != nil {
|
||||
logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err)
|
||||
}
|
||||
return freeSpace(stat)
|
||||
}
|
||||
|
||||
func freeSpace(stat unix.Statfs_t) uint64 {
|
||||
return uint64(stat.Bavail) * uint64(stat.Bsize)
|
||||
}
|
||||
|
|
|
@ -1,27 +1,9 @@
|
|||
package fs
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func mustGetFreeSpace(path string) uint64 {
|
||||
d, err := os.Open(path)
|
||||
if err != nil {
|
||||
logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err)
|
||||
}
|
||||
defer MustClose(d)
|
||||
|
||||
fd := d.Fd()
|
||||
var stat unix.Statfs_t
|
||||
if err := unix.Fstatfs(int(fd), &stat); err != nil {
|
||||
logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err)
|
||||
}
|
||||
return freeSpace(stat)
|
||||
}
|
||||
|
||||
func freeSpace(stat unix.Statfs_t) uint64 {
|
||||
return uint64(stat.F_bavail) * uint64(stat.F_bsize)
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func mmap(fd int, offset int64, length int) (data []byte, err error) {
|
||||
func mmap(fd int, length int) (data []byte, err error) {
|
||||
return unix.Mmap(fd, 0, length, unix.PROT_READ, unix.MAP_SHARED)
|
||||
|
||||
}
|
||||
|
@ -32,8 +32,7 @@ func mustSyncPath(path string) {
|
|||
}
|
||||
}
|
||||
|
||||
func createFlockFile(dir string) (*os.File, error) {
|
||||
flockFile := dir + "/flock.lock"
|
||||
func createFlockFile(flockFile string) (*os.File, error) {
|
||||
flockF, err := os.Create(flockFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot create lock file %q: %w", flockFile, err)
|
||||
|
@ -43,3 +42,18 @@ func createFlockFile(dir string) (*os.File, error) {
|
|||
}
|
||||
return flockF, nil
|
||||
}
|
||||
|
||||
func mustGetFreeSpace(path string) uint64 {
|
||||
d, err := os.Open(path)
|
||||
if err != nil {
|
||||
logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err)
|
||||
}
|
||||
defer MustClose(d)
|
||||
|
||||
fd := d.Fd()
|
||||
var stat unix.Statfs_t
|
||||
if err := unix.Fstatfs(int(fd), &stat); err != nil {
|
||||
logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err)
|
||||
}
|
||||
return freeSpace(stat)
|
||||
}
|
||||
|
|
|
@ -33,11 +33,8 @@ const (
|
|||
fileDispositionIgnoreReadonlyAttribute = 0x00000010
|
||||
)
|
||||
|
||||
// createFlockFile creates flock.lock file in the directory dir
|
||||
// and returns the handler to the file.
|
||||
// https://github.com/juju/fslock/blob/master/fslock_windows.go
|
||||
func createFlockFile(dir string) (*os.File, error) {
|
||||
flockFile := dir + "/flock.lock"
|
||||
func createFlockFile(flockFile string) (*os.File, error) {
|
||||
name, err := windows.UTF16PtrFromString(flockFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -67,7 +64,7 @@ func createFlockFile(dir string) (*os.File, error) {
|
|||
}
|
||||
|
||||
// stub
|
||||
func mmap(fd int, offset int64, length int) ([]byte, error) {
|
||||
func mmap(fd int, length int) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ func mmapFile(f *os.File, size int64) ([]byte, error) {
|
|||
if size%4096 != 0 {
|
||||
size += 4096 - size%4096
|
||||
}
|
||||
data, err := mmap(int(f.Fd()), 0, int(size))
|
||||
data, err := mmap(int(f.Fd()), int(size))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot mmap file with size %d: %w", size, err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue