binlogfile

package
v0.0.0-...-6fba4f8 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFileContentCorruption represents file or directory's content is curruption for some season
	ErrFileContentCorruption = errors.New("binlogger: content is corruption")

	// ErrCRCMismatch is the error represents crc don't match
	ErrCRCMismatch = errors.New("binlogger: crc mismatch")

	// ErrMagicMismatch is the error represents magic don't match
	ErrMagicMismatch = errors.New("binlogger: magic mismatch")

	// SegmentSizeBytes is the max file size of file
	SegmentSizeBytes int64 = 512 * 1024 * 1024
)
View Source
var (
	// ErrBadBinlogName is an error represents invalid file name.
	ErrBadBinlogName = errors.New("bad file name")

	// ErrFileNotFound is an error represents binlog file not found
	ErrFileNotFound = errors.New("binlogger: file not found")
)

Functions

func BinlogName

func BinlogName(index uint64) string

BinlogName creates a binlog file name. The file name format is like binlog-0000000000000001-20181010101010

func CheckMagic

func CheckMagic(mgicNum uint32) error

CheckMagic check weather the magicNum is right

func CloseBinlogger

func CloseBinlogger(binlogger Binlogger) error

CloseBinlogger closes the binlogger

func CreateDirAll

func CreateDirAll(dir string) error

CreateDirAll guarantees to create a new and empty dir

func Decode

func Decode(r io.Reader) (payload []byte, length int64, err error)

Decode return payload and bytes read from io.Reader

func Encode

func Encode(payload []byte) []byte

Encode encodes the payload

func Exist

func Exist(name string) bool

Exist detects the file/dir whether exist

func FilterBinlogNames

func FilterBinlogNames(names []string) []string

FilterBinlogNames filter binlog names from names.

func InitMetircs

func InitMetircs(registry *prometheus.Registry)

InitMetircs register the metrics to registry

func IsValidBinlog

func IsValidBinlog(names []string) bool

IsValidBinlog detects the binlog names is valid

func ParseBinlogName

func ParseBinlogName(str string) (index uint64, ts int64, err error)

ParseBinlogName parse binlog file name and return binlog index.

func ReadBinlogNames

func ReadBinlogNames(dirpath string) ([]string, error)

ReadBinlogNames returns sorted filenames in the dirpath

func ReadDir

func ReadDir(dirpath string) ([]string, error)

ReadDir reads and returns all file and dir names from directory f

func SearchIndex

func SearchIndex(names []string, index uint64) (int, bool)

SearchIndex returns the last array index of file equal to or smaller than the given index.

Types

type Binlogger

type Binlogger interface {
	// read nums binlog events from the "from" position
	ReadFrom(from binlog.Pos, nums int32) ([]binlog.Entity, error)

	// ReadAll reads all binlog in the directory.
	ReadAll(ctx context.Context) (<-chan *binlog.Entity, <-chan error)

	// batch write binlog event, and returns current offset(if have).
	WriteTail(entity *binlog.Entity) (binlog.Pos, error)

	// Walk reads binlog from the "from" position and sends binlogs in the streaming way
	Walk(ctx context.Context, from binlog.Pos, sendBinlog func(entity *binlog.Entity) error) error

	// close the binlogger
	Close() error

	// GGCByTime delete all files that's older than the specified duration, the latest file is always kept
	GCByTime(retentionTime time.Duration)

	// GCByPos delete all files that's before the specified position, the latest file is always kept
	GCByPos(pos binlog.Pos)
}

Binlogger is the interface that for append and read binlog

func OpenBinlogger

func OpenBinlogger(dirpath string, maxFileSize int64) (Binlogger, error)

OpenBinlogger returns a binlogger for write, then it can be appended

type Decoder

type Decoder interface {
	Decode() (payload []byte, offset int64, err error)
}

Decoder is an interface wraps basic Decode method which decode binlog.Entity into binlogBuffer.

func NewDecoder

func NewDecoder(r io.Reader, initOffset int64) Decoder

NewDecoder creates a new Decoder.

type Encoder

type Encoder interface {
	Encode(payload []byte) (int64, error)
}

Encoder is an interface wraps basic Encode method which encodes payload and write it, and returns offset.

func NewEncoder

func NewEncoder(w io.Writer, initOffset int64) Encoder

NewEncoder creates a Encoder instance

Jump to

Keyboard shortcuts

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