序
本文主要研究一下 canal-go 的 position
Position
canal-go-v1.0.7/protocol/Position/Position.go
package position
type Position interface {}
- Position.go 定义了一个 Position 接口
MetaqPosition
canal-go-v1.0.7/protocol/Position/metaq_position.go
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.go
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.go
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.go
package position
type LogPosition struct {
Identity LogIdentity
Postion EntryPosition
}
- LogPosition 定义了 LogIdentity、EntryPosition 属性
小结
canal-go 定义了 Position、MetaqPosition、TimePosition、EntryPosition、LogPosition
doc
- Position