-
Notifications
You must be signed in to change notification settings - Fork 987
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
added query event in dummy event handler #791
Open
axfor
wants to merge
4
commits into
go-mysql-org:master
Choose a base branch
from
axfor:feature-axx
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d6fe43b
added query event in dummyEventHandler
axfor 4167292
added comment that OnQueryEvent has lower priority than OnDDL event
axfor 1e774c8
Update canal/handler.go
axfor 3c52422
Improve the parameters and pos saving logic of the OnQueryEvent function
axfor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -142,21 +142,18 @@ func (c *Canal) runSyncBinlog() error { | |||||||||||
continue | ||||||||||||
} | ||||||||||||
for _, stmt := range stmts { | ||||||||||||
nodes := parseStmt(stmt) | ||||||||||||
for _, node := range nodes { | ||||||||||||
if node.db == "" { | ||||||||||||
node.db = string(e.Schema) | ||||||||||||
} | ||||||||||||
if err = c.updateTable(ev.Header, node.db, node.table); err != nil { | ||||||||||||
return errors.Trace(err) | ||||||||||||
} | ||||||||||||
} | ||||||||||||
nodes := parseDDLStmt(stmt) | ||||||||||||
if len(nodes) > 0 { | ||||||||||||
savePos = true | ||||||||||||
force = true | ||||||||||||
// Now we only handle Table Changed DDL, maybe we will support more later. | ||||||||||||
if err = c.eventHandler.OnDDL(ev.Header, pos, e); err != nil { | ||||||||||||
return errors.Trace(err) | ||||||||||||
err := c.handleDDLEvent(ev, e, nodes, pos) | ||||||||||||
if err != nil { | ||||||||||||
c.cfg.Logger.Errorf("handle ddl event err %v", err) | ||||||||||||
} | ||||||||||||
} else { | ||||||||||||
savePos, force, err = c.handleQueryEvent(ev.Header, stmt, pos, e) | ||||||||||||
if err != nil { | ||||||||||||
c.cfg.Logger.Errorf("handle query event err %v", err) | ||||||||||||
} | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
@@ -183,7 +180,7 @@ type node struct { | |||||||||||
table string | ||||||||||||
} | ||||||||||||
|
||||||||||||
func parseStmt(stmt ast.StmtNode) (ns []*node) { | ||||||||||||
func parseDDLStmt(stmt ast.StmtNode) (ns []*node) { | ||||||||||||
switch t := stmt.(type) { | ||||||||||||
case *ast.RenameTableStmt: | ||||||||||||
for _, tableInfo := range t.TableToTables { | ||||||||||||
|
@@ -231,6 +228,7 @@ func (c *Canal) updateTable(header *replication.EventHeader, db, table string) ( | |||||||||||
} | ||||||||||||
return | ||||||||||||
} | ||||||||||||
|
||||||||||||
func (c *Canal) updateReplicationDelay(ev *replication.BinlogEvent) { | ||||||||||||
var newDelay uint32 | ||||||||||||
now := uint32(time.Now().Unix()) | ||||||||||||
|
@@ -336,3 +334,32 @@ func (c *Canal) CatchMasterPos(timeout time.Duration) error { | |||||||||||
|
||||||||||||
return c.WaitUntilPos(pos, timeout) | ||||||||||||
} | ||||||||||||
|
||||||||||||
// handleDDLEvent is handle DDL event | ||||||||||||
func (c *Canal) handleDDLEvent(ev *replication.BinlogEvent, e *replication.QueryEvent, nodes []*node, pos mysql.Position) error { | ||||||||||||
for _, node := range nodes { | ||||||||||||
if node.db == "" { | ||||||||||||
node.db = string(e.Schema) | ||||||||||||
} | ||||||||||||
if err := c.updateTable(ev.Header, node.db, node.table); err != nil { | ||||||||||||
return errors.Trace(err) | ||||||||||||
} | ||||||||||||
} | ||||||||||||
if len(nodes) > 0 { | ||||||||||||
axfor marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
// Now we only handle Table Changed DDL, maybe we will support more later. | ||||||||||||
if err := c.eventHandler.OnDDL(ev.Header, pos, e); err != nil { | ||||||||||||
return errors.Trace(err) | ||||||||||||
} | ||||||||||||
} | ||||||||||||
return nil | ||||||||||||
} | ||||||||||||
|
||||||||||||
// handleQueryEvent is handle some common query events (e.g., DDL,CREATE or DROP USER,GRANT) | ||||||||||||
// DDL event use handleDDLEvent, others use the handleQueryEvent | ||||||||||||
func (c *Canal) handleQueryEvent(header *replication.EventHeader, stmt ast.StmtNode, pos mysql.Position, e *replication.QueryEvent) (bool, bool, error) { | ||||||||||||
savePos, force, err := c.eventHandler.OnQueryEvent(header, stmt, pos, e) | ||||||||||||
if err != nil { | ||||||||||||
return savePos, force, errors.Trace(err) | ||||||||||||
} | ||||||||||||
return savePos, force, nil | ||||||||||||
Comment on lines
+361
to
+364
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use named return in this interface, or explain what's the meaning of two
bool
s in comments. So users of this library will understand when they implement this interface.