聊聊canal-go的position

本文主要研究一下canal-go的positiongit

Position

canal-go-v1.0.7/protocol/Position/Position.gogithub

package position

type Position interface {
}
复制代码
  • Position.go定义了一个Position接口

MetaqPosition

canal-go-v1.0.7/protocol/Position/metaq_position.gobash

package position

type MetaqPosition struct {
	Topic    string
	MsgNewId string
	Offset   int64
}
复制代码
  • MetaqPosition定义了Topic、MsgNewId、Offset属性

TimePosition

canal-go-v1.0.7/protocol/Position/time_position.goui

package position

type TimePosition struct {
	Timestamp int64
}

func NewTimePosition(timestamp int64) *TimePosition {
	tstamp := &TimePosition{Timestamp: timestamp}
	return tstamp
}
复制代码
  • TimePosition定义了Timestamp属性,NewTimePosition方法实例化TimePosition

EntryPosition

canal-go-v1.0.7/protocol/Position/entry_position.gospa

package position

const (
	EVENTIDENTITY_SEGMENT = 3
	EVENTIDENTITY_SPLIT   = 5
)

type EntryPosition struct {
	TimePosition
	Included    bool
	JournalName string
	Position    int64
	ServerId    int64
}

func NewEntryPosition(journalName string, position int64, timestamp int64, serverId int64, Included bool) *EntryPosition {
	entryPosition := &EntryPosition{TimePosition{timestamp}, false, journalName, position, serverId}
	return entryPosition
}
复制代码
  • EntryPosition定义了TimePosition、Included、JournalName、Position、ServerId属性;NewEntryPosition方法实例一个EntryPosition

LogPosition

go-projects/canal-go-v1.0.7/protocol/Position/log_position.gocode

package position

type LogPosition struct {
	Identity LogIdentity
	Postion  EntryPosition
}
复制代码
  • LogPosition定义了LogIdentity、EntryPosition属性

小结

canal-go定义了Position、MetaqPosition、TimePosition、EntryPosition、LogPositionserver

doc

相关文章
相关标签/搜索