mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
all: follow-up after 34634ec357
- Use windows.FlushFileBuffers() instead of windows.Fsync() at streamTracker.adviseDontNeed() for consistency with implementations for other architectures. - Use filepath.Base() instead of filepath.Split(), since the dir part isn't used. This simplifies the code a bit. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/70
This commit is contained in:
parent
34634ec357
commit
b14d96618c
4 changed files with 19 additions and 26 deletions
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
func (st *streamTracker) adviseDontNeed(n int, fdatasync bool) error {
|
func (st *streamTracker) adviseDontNeed(n int, fdatasync bool) error {
|
||||||
if fdatasync && st.fd > 0 {
|
if fdatasync && st.fd > 0 {
|
||||||
if err := windows.Fsync(windows.Handle(st.fd)); err != nil {
|
if err := windows.FlushFileBuffers(windows.Handle(st.fd)); err != nil {
|
||||||
return fmt.Errorf("windows.Fsync error: %w", err)
|
return fmt.Errorf("windows.Fsync error: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,8 +58,8 @@ func createFlockFile(flockFile string) (*os.File, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
fileMappingMU sync.Mutex
|
mmapByAddrLock sync.Mutex
|
||||||
fileMappingByAddr = map[uintptr]windows.Handle{}
|
mmapByAddr = map[uintptr]windows.Handle{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func mmap(fd int, length int) ([]byte, error) {
|
func mmap(fd int, length int) ([]byte, error) {
|
||||||
|
@ -77,15 +77,16 @@ func mmap(fd int, length int) ([]byte, error) {
|
||||||
windows.CloseHandle(h)
|
windows.CloseHandle(h)
|
||||||
return nil, os.NewSyscallError("MapViewOfFile", errno)
|
return nil, os.NewSyscallError("MapViewOfFile", errno)
|
||||||
}
|
}
|
||||||
fileMappingMU.Lock()
|
|
||||||
fileMappingByAddr[addr] = h
|
|
||||||
fileMappingMU.Unlock()
|
|
||||||
data := make([]byte, 0)
|
data := make([]byte, 0)
|
||||||
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&data))
|
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&data))
|
||||||
hdr.Data = addr
|
hdr.Data = addr
|
||||||
hdr.Len = length
|
hdr.Len = length
|
||||||
hdr.Cap = hdr.Len
|
hdr.Cap = hdr.Len
|
||||||
|
|
||||||
|
mmapByAddrLock.Lock()
|
||||||
|
mmapByAddr[addr] = h
|
||||||
|
mmapByAddrLock.Unlock()
|
||||||
|
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,20 +95,20 @@ func mUnmap(data []byte) error {
|
||||||
// In case of write, additional call FlushViewOfFile must be performed.
|
// In case of write, additional call FlushViewOfFile must be performed.
|
||||||
header := (*reflect.SliceHeader)(unsafe.Pointer(&data))
|
header := (*reflect.SliceHeader)(unsafe.Pointer(&data))
|
||||||
addr := header.Data
|
addr := header.Data
|
||||||
fileMappingMU.Lock()
|
|
||||||
defer fileMappingMU.Unlock()
|
|
||||||
if err := windows.UnmapViewOfFile(addr); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
handle, ok := fileMappingByAddr[addr]
|
mmapByAddrLock.Lock()
|
||||||
|
h, ok := mmapByAddr[addr]
|
||||||
if !ok {
|
if !ok {
|
||||||
logger.Fatalf("BUG: unmapping for non exist addr: %d", addr)
|
logger.Fatalf("BUG: unmapping for non exist addr: %d", addr)
|
||||||
}
|
}
|
||||||
delete(fileMappingByAddr, addr)
|
delete(mmapByAddr, addr)
|
||||||
|
mmapByAddrLock.Unlock()
|
||||||
|
|
||||||
e := windows.CloseHandle(handle)
|
if err := windows.UnmapViewOfFile(addr); err != nil {
|
||||||
return os.NewSyscallError("CloseHandle", e)
|
return fmt.Errorf("cannot unmap memory mapped file: %w", err)
|
||||||
|
}
|
||||||
|
errno := windows.CloseHandle(h)
|
||||||
|
return os.NewSyscallError("CloseHandle", errno)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustGetFreeSpace(path string) uint64 {
|
func mustGetFreeSpace(path string) uint64 {
|
||||||
|
@ -115,8 +116,7 @@ func mustGetFreeSpace(path string) uint64 {
|
||||||
r, _, err := procDisk.Call(uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(path))),
|
r, _, err := procDisk.Call(uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(path))),
|
||||||
uintptr(unsafe.Pointer(&freeBytes)))
|
uintptr(unsafe.Pointer(&freeBytes)))
|
||||||
if r == 0 {
|
if r == 0 {
|
||||||
logger.Errorf("cannot get free space for path: %q : %s", path, err)
|
logger.Panicf("FATAL: cannot get free space for %q : %s", path, err)
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
return uint64(freeBytes)
|
return uint64(freeBytes)
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,10 +83,7 @@ func (ph *partHeader) ParseFromPath(path string) error {
|
||||||
path = filepath.Clean(path)
|
path = filepath.Clean(path)
|
||||||
|
|
||||||
// Extract encoded part name.
|
// Extract encoded part name.
|
||||||
dir, partName := filepath.Split(path)
|
partName := filepath.Base(path)
|
||||||
if len(dir) == 0 {
|
|
||||||
return fmt.Errorf("cannot find encoded part name in the path %q", path)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PartName must have the following form:
|
// PartName must have the following form:
|
||||||
// RowsCount_BlocksCount_MinTimestamp_MaxTimestamp_Garbage
|
// RowsCount_BlocksCount_MinTimestamp_MaxTimestamp_Garbage
|
||||||
|
|
|
@ -259,11 +259,7 @@ func openPartition(smallPartsPath, bigPartsPath string, s *Storage) (*partition,
|
||||||
smallPartsPath = filepath.Clean(smallPartsPath)
|
smallPartsPath = filepath.Clean(smallPartsPath)
|
||||||
bigPartsPath = filepath.Clean(bigPartsPath)
|
bigPartsPath = filepath.Clean(bigPartsPath)
|
||||||
|
|
||||||
dir, name := filepath.Split(smallPartsPath)
|
name := filepath.Base(smallPartsPath)
|
||||||
if len(dir) == 0 {
|
|
||||||
return nil, fmt.Errorf("cannot find partition name from smallPartsPath %q; must be in the form /path/to/smallparts/YYYY_MM", smallPartsPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.HasSuffix(bigPartsPath, name) {
|
if !strings.HasSuffix(bigPartsPath, name) {
|
||||||
return nil, fmt.Errorf("patititon name in bigPartsPath %q doesn't match smallPartsPath %q; want %q", bigPartsPath, smallPartsPath, name)
|
return nil, fmt.Errorf("patititon name in bigPartsPath %q doesn't match smallPartsPath %q; want %q", bigPartsPath, smallPartsPath, name)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue