binlog

package
v0.0.0-...-690b2a9 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// MinRelaySubDirSuffix is same as relay.MinRelaySubDirSuffix.
	MinRelaySubDirSuffix = 1
	// FileHeaderLen is the length of binlog file header.
	FileHeaderLen = 4
)
View Source
const FakeBinlogName = "start-task with --start-time"

FakeBinlogName is used to bypass the checking of meta in task config when start-task with --start-time.

Variables

View Source
var MinPosition = gmysql.Position{Pos: 4}

MinPosition is the min binlog position.

Functions

func CompareGTID

func CompareGTID(gSet1, gSet2 gmysql.GTIDSet) (int, bool)

CompareGTID returns:

1, true if gSet1 is bigger than gSet2
0, true if gSet1 is equal to gSet2
-1, true if gSet1 is less than gSet2

but if can't compare gSet1 and gSet2, will returns 0, false.

func CompareLocation

func CompareLocation(location1, location2 Location, cmpGTID bool) int

CompareLocation returns:

1 if point1 is bigger than point2
0 if point1 is equal to point2
-1 if point1 is less than point2

func ComparePosition

func ComparePosition(pos1, pos2 gmysql.Position) int

ComparePosition returns:

1 if pos1 is bigger than pos2
0 if pos1 is equal to pos2
-1 if pos1 is less than pos2

func ExtractPos

func ExtractPos(pos gmysql.Position, uuids []string) (uuidWithSuffix string, relaySubDirSuffix string, realPos gmysql.Position, err error)

ExtractPos extracts (uuidWithSuffix, RelaySubDirSuffix, originalPos) from input position (originalPos or convertedPos). nolint:nakedret

func ExtractSuffix

func ExtractSuffix(name string) (int, error)

ExtractSuffix extracts RelaySubDirSuffix from input name.

func IsFreshPosition

func IsFreshPosition(location Location, flavor string, cmpGTID bool) bool

IsFreshPosition returns true when location1 is a fresh location without any info.

func NewLocalBinlogPosFinder

func NewLocalBinlogPosFinder(tctx *tcontext.Context, enableGTID bool, flavor string, relayDir string) *binlogPosFinder

func NewRemoteBinlogPosFinder

func NewRemoteBinlogPosFinder(tctx *tcontext.Context, db *conn.BaseDB, syncCfg replication.BinlogSyncerConfig, enableGTID bool) *binlogPosFinder

func PositionFromPosStr

func PositionFromPosStr(str string) (gmysql.Position, error)

PositionFromPosStr constructs a mysql.Position from a string representation like `(mysql-bin.000001, 2345)`.

func PositionFromStr

func PositionFromStr(s string) (gmysql.Position, error)

PositionFromStr constructs a mysql.Position from a string representation like `mysql-bin.000001:2345`.

func ReadSortedBinlogFromDir

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

ReadSortedBinlogFromDir reads and returns all binlog files (sorted ascending by binlog filename and sequence number).

func RealMySQLPos

func RealMySQLPos(pos gmysql.Position) (gmysql.Position, error)

RealMySQLPos parses a relay position and returns a mysql position and whether error occurs if parsed successfully and `RelaySubDirSuffix` in binlog filename exists, sets position Name to `originalPos.BinlogBaseName + binlogFilenameSep + originalPos.BinlogSeq`. if parsed failed returns the given position and the traced error.

func RemoveRelaySubDirSuffix

func RemoveRelaySubDirSuffix(pos gmysql.Position) gmysql.Position

RemoveRelaySubDirSuffix removes relay dir suffix from binlog filename of a position. for example: mysql-bin|000001.000002 -> mysql-bin.000002.

func VerifyBinlogPos

func VerifyBinlogPos(pos string) (*gmysql.Position, error)

VerifyBinlogPos verify binlog pos string.

Types

type FileSizes

type FileSizes []binlogSize

FileSizes is a list of binlog filename and size.

func GetBinaryLogs

func GetBinaryLogs(ctx *tcontext.Context, db *conn.BaseDB) (FileSizes, error)

GetBinaryLogs returns binlog filename and size of upstream.

func GetLocalBinaryLogs

func GetLocalBinaryLogs(dir string) (FileSizes, error)

func (FileSizes) After

func (b FileSizes) After(fromFile gmysql.Position) int64

After returns the total size of binlog after `fromFile` in FileSizes.

type Location

type Location struct {
	// a structure represents the file offset in binlog file
	Position gmysql.Position

	// used to distinguish injected events by DM when it's not 0
	Suffix int
	// contains filtered or unexported fields
}

Location identifies the location of binlog events.

func MustZeroLocation

func MustZeroLocation(flavor string) Location

MustZeroLocation returns a new Location. The flavor must not be empty. in DM the flavor is adjusted before write to etcd.

func NewLocation

func NewLocation(pos gmysql.Position, gset gmysql.GTIDSet) Location

NewLocation creates a new Location from given binlog position and GTID.

func ZeroLocation

func ZeroLocation(flavor string) (Location, error)

ZeroLocation returns a new Location. The flavor should not be empty.

func (Location) Clone

func (l Location) Clone() Location

Clone clones a same Location.

func (Location) CloneWithFlavor

func (l Location) CloneWithFlavor(flavor string) Location

CloneWithFlavor clones the location, and if the GTIDSet is nil, will create a GTIDSet with specified flavor.

func (*Location) CopyWithoutSuffixFrom

func (l *Location) CopyWithoutSuffixFrom(from Location)

CopyWithoutSuffixFrom copies a same Location without suffix. Note that gtidSet is shared.

func (Location) GTIDSetStr

func (l Location) GTIDSetStr() string

GTIDSetStr returns gtid set's string.

func (*Location) GetGTID

func (l *Location) GetGTID() gmysql.GTIDSet

GetGTID return gtidSet of Location. NOTE: for most cases you should clone before call Update on the returned GTID set, unless you know there's no other reference using the GTID set.

func (*Location) ResetSuffix

func (l *Location) ResetSuffix()

ResetSuffix set suffix to 0.

func (*Location) SetGTID

func (l *Location) SetGTID(gset gmysql.GTIDSet) error

SetGTID set new gtid for location. TODO: don't change old Location and return a new one to copy-on-write.

func (Location) String

func (l Location) String() string

func (*Location) Update

func (l *Location) Update(gtidStr string) error

Update will update GTIDSet of Location. caller should be aware that this will change the GTID set of other copies. TODO: don't change old Location and return a new one to copy-on-write.

type PosType

type PosType int
const (
	InvalidBinlogPos PosType = iota
	BelowLowerBoundBinlogPos
	InRangeBinlogPos
	AboveUpperBoundBinlogPos
)

func (PosType) String

func (b PosType) String() string

type SourceStatus

type SourceStatus struct {
	Location   Location
	Binlogs    FileSizes
	UpdateTime time.Time
}

SourceStatus collects all information of upstream.

func GetSourceStatus

func GetSourceStatus(tctx *tcontext.Context, db *conn.BaseDB, flavor string) (*SourceStatus, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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