fsutil

package
v0.0.0-...-be15534 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DropPageCache

func DropPageCache(name string) error

DropPageCache us fadvise to tell OS the reclaim memory associated with the file as soon as possible, which can avoid the unexpected I/O latency spike risk.

func IsDirAndWritable

func IsDirAndWritable(path string) error

IsDirAndWritable checks a given path is directory and writable

func IsDirReadWritable

func IsDirReadWritable(dir string) error

IsDirReadWritable check if the dir is writable and readable by cdc server

func IsDirWritable

func IsDirWritable(dir string) error

IsDirWritable checks if a dir is writable, return error nil means it is writable

func PreAllocate

func PreAllocate(f *os.File, size int64) error

PreAllocate can allocate disk space beforehand in case of ENOSPC error occurs when writing a file, which is not uncommon for a rigorous redolog/WAL design. Besides, pre-allocating disk space can reduce the overhead of file metadata updating.

Types

type DiskInfo

type DiskInfo struct {
	All             uint64
	Used            uint64
	Free            uint64
	Avail           uint64
	AvailPercentage float32
}

DiskInfo present the disk amount information, in gb

func GetDiskInfo

func GetDiskInfo(dir string) (*DiskInfo, error)

GetDiskInfo return the disk space information of the given directory the caller should guarantee that dir exist

func (*DiskInfo) String

func (d *DiskInfo) String() string

type FileAllocator

type FileAllocator struct {
	// contains filtered or unexported fields
}

FileAllocator has two functionalities:

  1. create new file or reuse the existing file (the existing tmp file will be cleared) beforehand for file write.
  2. pre-allocate disk space to mitigate the overhead of file metadata updating.

ref: https://github.com/etcd-io/etcd/pull/4785

func NewFileAllocator

func NewFileAllocator(dir string, prefix string, size int64) *FileAllocator

NewFileAllocator creates a file allocator and starts a background file allocation goroutine.

func (*FileAllocator) Close

func (fl *FileAllocator) Close() error

Close closes the doneCh to notify the background goroutine to exit.

func (*FileAllocator) Open

func (fl *FileAllocator) Open() (f *os.File, err error)

Open returns a file for writing, this tmp file needs to be renamed after calling Open().

type FileLock

type FileLock struct {
	// contains filtered or unexported fields
}

FileLock represents a file lock created by `flock`. For more on the system call `flock`, read: https://linux.die.net/man/2/flock

func NewFileLock

func NewFileLock(filePath string) (*FileLock, error)

NewFileLock creates a new file lock on the file described in filePath.

func (*FileLock) Close

func (fl *FileLock) Close() error

Close closes the underlying file. NOTE: this function will unlock the lock as well.

func (*FileLock) IsLocked

func (fl *FileLock) IsLocked() (bool, error)

IsLocked checks whether the file is currently locked

func (*FileLock) Lock

func (fl *FileLock) Lock() error

Lock places a lock on the file

func (*FileLock) Unlock

func (fl *FileLock) Unlock() error

Unlock unlocks the file lock

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL