utility

package
v0.0.0-...-e89a0ad Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VersionStr       = "005"
	BaseBackupPath   = "basebackups_" + VersionStr + "/"
	CatchupPath      = "catchup_" + VersionStr + "/"
	WalPath          = "wal_" + VersionStr + "/"
	BackupNamePrefix = "base_"
	BackupTimeFormat = "20060102T150405Z" // timestamps in that format should be lexicographically sorted

	// utility.SentinelSuffix is a suffix of backup finish sentinel file
	SentinelSuffix         = "_backup_stop_sentinel.json"
	CompressedBlockMaxSize = 20 << 20
	CopiedBlockMaxSize     = CompressedBlockMaxSize
	MetadataFileName       = "metadata.json"
	StreamMetadataFileName = "stream_metadata.json"
	PathSeparator          = string(os.PathSeparator)
	Mebibyte               = 1024 * 1024
)
View Source
const CopyBytesPoolSize = 2

Variables

View Source
var MaxTime time.Time

MaxTime not really the maximal value, but high enough.

View Source
var MinTime = time.Unix(0, 0)
View Source
var RegexpLSN = regexp.MustCompile(patternLSN)

Functions

func AbsResolveSymlink(path string) string

AbsResolveSymlink first tries to turn 'path' to an absolute path, then calls ResolveSymlink. If 'path' can't be turned to an absolute path, keep the relative path.

func AllZero

func AllZero(s []byte) bool

func CeilTimeUpToMicroseconds

func CeilTimeUpToMicroseconds(timeToCeil time.Time) time.Time

This function is needed for being cross-platform

func ConcatByteSlices

func ConcatByteSlices(a []byte, b []byte) []byte

func CreateLocalFile

func CreateLocalFile(targetPath, name string) (*os.File, error)

create new local file on disk

func CreateParentDirs

func CreateParentDirs(fileName string, targetPath string) error

creates parent dirs of the file

func FastCopy

func FastCopy(dst io.Writer, src io.Reader) (int64, error)

FastCopy copies data from src to dst in blocks of CopiedBlockMaxSize bytes

func GetFileExtension

func GetFileExtension(filePath string) string

func GetLocalFile

func GetLocalFile(targetPath string, header *tar.Header) (localFile *os.File, isNewFile bool, err error)

func GetLocalFileInfo

func GetLocalFileInfo(targetPath string) (fileInfo os.FileInfo, err error)

get file info by file path

func GetSubdirectoryRelativePath

func GetSubdirectoryRelativePath(subdirectoryPath string, directoryPath string) string

func IsDirectoryEmpty

func IsDirectoryEmpty(directoryPath string) (bool, error)

func IsInDirectory

func IsInDirectory(path, directoryPath string) bool

func LoggedClose

func LoggedClose(c io.Closer, errmsg string)

func LoggedSync

func LoggedSync(file *os.File, errmsg string, fsync bool)

func MarshalEnumToString

func MarshalEnumToString(enum fmt.Stringer) ([]byte, error)

MarshalEnumToString is used to write the string enum representation instead of int enum value to JSON

func Max

func Max(a, b int) int

func Min

func Min(a, b int) int

func NormalizePath

func NormalizePath(path string) string

func ParseUntilTS

func ParseUntilTS(untilTS string) (time.Time, error)

func PathsEqual

func PathsEqual(path1, path2 string) bool

func ResetTimer

func ResetTimer(t *time.Timer, d time.Duration)

ResetTimer safety resets timer (drains channel if required)

func ResolveSymlink(path string) string

utility.ResolveSymlink converts path to physical if it is symlink

func SanitizePath

func SanitizePath(path string) string

func ScanToMap

func ScanToMap(rows *sql.Rows, dst map[string]interface{}) error

func SelectMatchingFiles

func SelectMatchingFiles(fileMask string, filePathsToFilter map[string]bool) (map[string]bool, error)

func StartCommandWithStdoutPipe

func StartCommandWithStdoutPipe(cmd *exec.Cmd) (io.ReadCloser, error)

func StartCommandWithStdoutStderr

func StartCommandWithStdoutStderr(cmd *exec.Cmd) (io.ReadCloser, *bytes.Buffer, error)

func StripLeftmostBackupName

func StripLeftmostBackupName(path string) string

func StripPrefixName

func StripPrefixName(path string) string

func StripRightmostBackupName

func StripRightmostBackupName(path string) string

func StripWalFileName

func StripWalFileName(path string) string

Strips the backup WAL file name.

func TimeNowCrossPlatformLocal

func TimeNowCrossPlatformLocal() time.Time

func TimeNowCrossPlatformUTC

func TimeNowCrossPlatformUTC() time.Time

func ToBytes

func ToBytes(x interface{}) []byte

func TrimFileExtension

func TrimFileExtension(filePath string) string

func TryFetchTimeRFC3999

func TryFetchTimeRFC3999(name string) (string, bool)

func WriteLocalFile

func WriteLocalFile(fileReader io.Reader, header *tar.Header, localFile *os.File, fsync bool) error

Types

type BytesPool

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

BytesPool holds []byte.

func NewBytesPool

func NewBytesPool(max int) *BytesPool

NewBytesPool creates new BytesPool.

func (*BytesPool) Get

func (p *BytesPool) Get() []byte

Get borrows []byte from the pool.

func (*BytesPool) Put

func (p *BytesPool) Put(b []byte)

Put returns []byte to the pool.

type CascadeReadCloser

type CascadeReadCloser struct {
	io.ReadCloser
	Underlying io.Closer
}

CascadeReadCloser bundles multiple closures into one function. Calling Close() will close the main and underlying writers.

func (*CascadeReadCloser) Close

func (cc *CascadeReadCloser) Close() error

Close returns the first encountered error from closing main or underlying writer.

type CascadeWriteCloser

type CascadeWriteCloser struct {
	io.WriteCloser
	Underlying io.Closer
}

CascadeWriteCloser bundles multiple closures into one function. Calling Close() will close the main and underlying writers.

func (*CascadeWriteCloser) Close

func (cc *CascadeWriteCloser) Close() error

Close returns the first encountered error from closing main or underlying writer.

type CloseOnce

type CloseOnce struct {
	io.WriteCloser
	// contains filtered or unexported fields
}

CloseOnce is a wrapper that prevents users from closing io.WriteCloser multiple times Note: The behavior of Close after the first call is undefined. (proof: io.Closer comments)

func (*CloseOnce) Close

func (c *CloseOnce) Close() error

type Empty

type Empty struct{}

Empty is used for channel signaling.

type EmptyWriteCloserIgnorer

type EmptyWriteCloserIgnorer struct {
	io.WriteCloser
}

func (EmptyWriteCloserIgnorer) Close

func (e EmptyWriteCloserIgnorer) Close() error

func (EmptyWriteCloserIgnorer) Write

func (e EmptyWriteCloserIgnorer) Write(p []byte) (int, error)

type EmptyWriteIgnorer

type EmptyWriteIgnorer struct {
	io.Writer
}

EmptyWriteIgnorer handles 0 byte write in LZ4 package to stop pipe reader/writer from blocking.

func (EmptyWriteIgnorer) Write

func (e EmptyWriteIgnorer) Write(p []byte) (int, error)

type ForbiddenActionError

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

func NewForbiddenActionError

func NewForbiddenActionError(message string) ForbiddenActionError

func (ForbiddenActionError) Error

func (err ForbiddenActionError) Error() string

type SignalHandler

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

SignalHandler defines signal handler setup & shutdown representation

func NewSignalHandler

func NewSignalHandler(ctx context.Context, cancel func(), signals []os.Signal) *SignalHandler

NewSignalHandler constructs SignalHandler and sets up signal mask

func (*SignalHandler) Close

func (sh *SignalHandler) Close() error

Close removes signal mask and call cancel func

type WithSizeReadCloser

type WithSizeReadCloser struct {
	WithSizeReader
	// contains filtered or unexported fields
}

func NewWithSizeReadCloser

func NewWithSizeReadCloser(underlying io.ReadCloser, readSize *int64) *WithSizeReadCloser

func (*WithSizeReadCloser) Close

func (w *WithSizeReadCloser) Close() error

type WithSizeReader

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

func NewWithSizeReader

func NewWithSizeReader(underlying io.Reader, readSize *int64) *WithSizeReader

func (*WithSizeReader) Read

func (reader *WithSizeReader) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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