本文整理汇总了Golang中github.com/youtube/vitess/go/vt/binlog/proto.StreamEvent类的典型用法代码示例。如果您正苦于以下问题:Golang StreamEvent类的具体用法?Golang StreamEvent怎么用?Golang StreamEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StreamEvent类的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
}