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
d231cefe25
commit
1d9a461c23
4 changed files with 19 additions and 26 deletions
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
func (st *streamTracker) adviseDontNeed(n int, fdatasync bool) error {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,8 +58,8 @@ func createFlockFile(flockFile string) (*os.File, error) {
|
|||
}
|
||||
|
||||
var (
|
||||
fileMappingMU sync.Mutex
|
||||
fileMappingByAddr = map[uintptr]windows.Handle{}
|
||||
mmapByAddrLock sync.Mutex
|
||||
mmapByAddr = map[uintptr]windows.Handle{}
|
||||
)
|
||||
|
||||
func mmap(fd int, length int) ([]byte, error) {
|
||||
|
@ -77,15 +77,16 @@ func mmap(fd int, length int) ([]byte, error) {
|
|||
windows.CloseHandle(h)
|
||||
return nil, os.NewSyscallError("MapViewOfFile", errno)
|
||||
}
|
||||
fileMappingMU.Lock()
|
||||
fileMappingByAddr[addr] = h
|
||||
fileMappingMU.Unlock()
|
||||
data := make([]byte, 0)
|
||||
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&data))
|
||||
hdr.Data = addr
|
||||
hdr.Len = length
|
||||
hdr.Cap = hdr.Len
|
||||
|
||||
mmapByAddrLock.Lock()
|
||||
mmapByAddr[addr] = h
|
||||
mmapByAddrLock.Unlock()
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
|
@ -94,20 +95,20 @@ func mUnmap(data []byte) error {
|
|||
// In case of write, additional call FlushViewOfFile must be performed.
|
||||
header := (*reflect.SliceHeader)(unsafe.Pointer(&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 {
|
||||
logger.Fatalf("BUG: unmapping for non exist addr: %d", addr)
|
||||
}
|
||||
delete(fileMappingByAddr, addr)
|
||||
delete(mmapByAddr, addr)
|
||||
mmapByAddrLock.Unlock()
|
||||
|
||||
e := windows.CloseHandle(handle)
|
||||
return os.NewSyscallError("CloseHandle", e)
|
||||
if err := windows.UnmapViewOfFile(addr); err != nil {
|
||||
return fmt.Errorf("cannot unmap memory mapped file: %w", err)
|
||||
}
|
||||
errno := windows.CloseHandle(h)
|
||||
return os.NewSyscallError("CloseHandle", errno)
|
||||
}
|
||||
|
||||
func mustGetFreeSpace(path string) uint64 {
|
||||
|
@ -115,8 +116,7 @@ func mustGetFreeSpace(path string) uint64 {
|
|||
r, _, err := procDisk.Call(uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(path))),
|
||||
uintptr(unsafe.Pointer(&freeBytes)))
|
||||
if r == 0 {
|
||||
logger.Errorf("cannot get free space for path: %q : %s", path, err)
|
||||
return 0
|
||||
logger.Panicf("FATAL: cannot get free space for %q : %s", path, err)
|
||||
}
|
||||
return uint64(freeBytes)
|
||||
}
|
||||
|
|
|
@ -83,10 +83,7 @@ func (ph *partHeader) ParseFromPath(path string) error {
|
|||
path = filepath.Clean(path)
|
||||
|
||||
// Extract encoded part name.
|
||||
dir, partName := filepath.Split(path)
|
||||
if len(dir) == 0 {
|
||||
return fmt.Errorf("cannot find encoded part name in the path %q", path)
|
||||
}
|
||||
partName := filepath.Base(path)
|
||||
|
||||
// PartName must have the following form:
|
||||
// RowsCount_BlocksCount_MinTimestamp_MaxTimestamp_Garbage
|
||||
|
|
|
@ -259,11 +259,7 @@ func openPartition(smallPartsPath, bigPartsPath string, s *Storage) (*partition,
|
|||
smallPartsPath = filepath.Clean(smallPartsPath)
|
||||
bigPartsPath = filepath.Clean(bigPartsPath)
|
||||
|
||||
dir, name := filepath.Split(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)
|
||||
}
|
||||
|
||||
name := filepath.Base(smallPartsPath)
|
||||
if !strings.HasSuffix(bigPartsPath, 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