Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用sqlparser替换正则进行queryevent的解析 #382

Merged
merged 19 commits into from
May 15, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
call onddl at end
  • Loading branch information
lintanghui committed May 10, 2019
commit 11e96ce4a134da85aeccb9e7233ce83751185c64
19 changes: 9 additions & 10 deletions canal/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,20 @@ func (c *Canal) runSyncBinlog() error {
stmts, _, err := c.parser.Parse(string(e.Query), "", "")
if err != nil {
log.Errorf("parse query(%s) err %v", e.Query, err)
lintanghui marked this conversation as resolved.
Show resolved Hide resolved
continue
return errors.Trace(err)
}
for _, stmt := range stmts {
nodes := parseStmt(stmt)
for _, node := range nodes {
if err = c.updateTable(node.db, node.table); err != nil {
return errors.Trace(err)
}
}
if len(nodes) > 0 {
savePos = true
lintanghui marked this conversation as resolved.
Show resolved Hide resolved
force = true
}
for _, node := range nodes {
if err = c.updateTable(node.db, node.table, e, pos, ev.Header.Timestamp); err != nil {
// Now we only handle Table Changed DDL, maybe we will support more later.
if err = c.eventHandler.OnDDL(pos, e); err != nil {
return errors.Trace(err)
}
}
lintanghui marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -195,17 +199,12 @@ func parseStmt(stmt ast.StmtNode) (ns []*node) {
return
}

func (c *Canal) updateTable(db, table string, e *replication.QueryEvent, pos mysql.Position, ts uint32) (err error) {
func (c *Canal) updateTable(db, table string) (err error) {
c.ClearTableCache([]byte(db), []byte(table))
log.Infof("table structure changed, clear table cache: %s.%s\n", db, table)
if err = c.eventHandler.OnTableChanged(db, table); err != nil && errors.Cause(err) != schema.ErrTableNotExist {
return errors.Trace(err)
}

// Now we only handle Table Changed DDL, maybe we will support more later.
if err = c.eventHandler.OnDDL(pos, e); err != nil {
return errors.Trace(err)
}
return
}
func (c *Canal) handleRowsEvent(e *replication.BinlogEvent) error {
Expand Down