本文主要研究一下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


codecraft
11.9k 声望2k 粉丝

当一个代码的工匠回首往事时,不因虚度年华而悔恨,也不因碌碌无为而羞愧,这样,当他老的时候,可以很自豪告诉世人,我曾经将代码注入生命去打造互联网的浪潮之巅,那是个很疯狂的时代,我在一波波的浪潮上留下...


引用和评论

0 条评论