本文整理匯總了Golang中github.com/youtube/vitess/go/vt/binlog/proto.StreamEvent.Timestamp方法的典型用法代碼示例。如果您正苦於以下問題:Golang StreamEvent.Timestamp方法的具體用法?Golang StreamEvent.Timestamp怎麽用?Golang StreamEvent.Timestamp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/youtube/vitess/go/vt/binlog/proto.StreamEvent
的用法示例。
在下文中一共展示了StreamEvent.Timestamp方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: transactionToEvent
func (evs *EventStreamer) transactionToEvent(trans *proto.BinlogTransaction) error {
var err error
var insertid int64
for _, stmt := range trans.Statements {
switch stmt.Category {
case proto.BL_SET:
if strings.HasPrefix(stmt.Sql, binlogSetInsertID) {
insertid, err = strconv.ParseInt(stmt.Sql[binlogSetInsertIDLen:], 10, 64)
if err != nil {
binlogStreamerErrors.Add("EventStreamer", 1)
log.Errorf("%v: %s", err, stmt.Sql)
}
}
case proto.BL_DML:
var dmlEvent *proto.StreamEvent
dmlEvent, insertid, err = evs.buildDMLEvent(stmt.Sql, insertid)
if err != nil {
dmlEvent = &proto.StreamEvent{
Category: "ERR",
Sql: stmt.Sql,
}
}
dmlEvent.Timestamp = trans.Timestamp
if err = evs.sendEvent(dmlEvent); err != nil {
return err
}
case proto.BL_DDL:
ddlEvent := &proto.StreamEvent{
Category: "DDL",
Sql: stmt.Sql,
Timestamp: trans.Timestamp,
}
if err = evs.sendEvent(ddlEvent); err != nil {
return err
}
case proto.BL_UNRECOGNIZED:
unrecognized := &proto.StreamEvent{
Category: "ERR",
Sql: stmt.Sql,
Timestamp: trans.Timestamp,
}
if err = evs.sendEvent(unrecognized); err != nil {
return err
}
default:
binlogStreamerErrors.Add("EventStreamer", 1)
log.Errorf("Unrecognized event: %v: %s", stmt.Category, stmt.Sql)
}
}
posEvent := &proto.StreamEvent{
Category: "POS",
TransactionID: trans.TransactionID,
Timestamp: trans.Timestamp,
}
if err = evs.sendEvent(posEvent); err != nil {
return err
}
return nil
}
示例2: transactionToEvent
func (evs *EventStreamer) transactionToEvent(trans *proto.BinlogTransaction) error {
var err error
var timestamp int64
var insertid int64
for _, stmt := range trans.Statements {
switch stmt.Category {
case proto.BL_SET:
if bytes.HasPrefix(stmt.Sql, BINLOG_SET_TIMESTAMP) {
if timestamp, err = strconv.ParseInt(string(stmt.Sql[len(BINLOG_SET_TIMESTAMP):]), 10, 64); err != nil {
return fmt.Errorf("%v: %s", err, stmt.Sql)
}
} else if bytes.HasPrefix(stmt.Sql, BINLOG_SET_INSERT) {
if insertid, err = strconv.ParseInt(string(stmt.Sql[len(BINLOG_SET_INSERT):]), 10, 64); err != nil {
return fmt.Errorf("%v: %s", err, stmt.Sql)
}
} else {
return fmt.Errorf("unrecognized: %s", stmt.Sql)
}
case proto.BL_DML:
var dmlEvent *proto.StreamEvent
dmlEvent, insertid, err = evs.buildDMLEvent(stmt.Sql, insertid)
if err != nil {
return fmt.Errorf("%v: %s", err, stmt.Sql)
}
dmlEvent.Timestamp = timestamp
if err = evs.sendEvent(dmlEvent); err != nil {
return err
}
case proto.BL_DDL:
ddlEvent := &proto.StreamEvent{
Category: "DDL",
Sql: string(stmt.Sql),
Timestamp: timestamp,
}
if err = evs.sendEvent(ddlEvent); err != nil {
return err
}
case proto.BL_UNRECOGNIZED:
unrecognized := &proto.StreamEvent{
Category: "ERR",
Sql: string(stmt.Sql),
Timestamp: timestamp,
}
if err = evs.sendEvent(unrecognized); err != nil {
return err
}
}
}
posEvent := &proto.StreamEvent{Category: "POS", GroupId: trans.GroupId}
if err = evs.sendEvent(posEvent); err != nil {
return err
}
return nil
}