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

feat: RowsEvent include NextPos(include name) #1007

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion canal/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (h *dumpParseHandler) Data(db string, table string, values []string) error
}
}

events := newRowsEvent(tableInfo, InsertAction, [][]interface{}{vs}, nil)
events := newRowsEvent(tableInfo, InsertAction, [][]interface{}{vs}, nil, nil)
return h.c.eventHandler.OnRow(events)
}

Expand Down
7 changes: 6 additions & 1 deletion canal/rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package canal
import (
"fmt"

"github.com/go-mysql-org/go-mysql/mysql"

"github.com/go-mysql-org/go-mysql/replication"
"github.com/go-mysql-org/go-mysql/schema"
)
Expand All @@ -26,15 +28,18 @@ type RowsEvent struct {
Rows [][]interface{}
// Header can be used to inspect the event
Header *replication.EventHeader
// NextPos including binlog name
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comment that when the RowsEvent is generated from dump stage, this field is nil.

nit: because your requirement only needs binlog name, how about only store binlog name here? we can discuss it before you accept my comment

NextPos *mysql.Position
}

func newRowsEvent(table *schema.Table, action string, rows [][]interface{}, header *replication.EventHeader) *RowsEvent {
func newRowsEvent(table *schema.Table, action string, rows [][]interface{}, header *replication.EventHeader, nextPos *mysql.Position) *RowsEvent {
e := new(RowsEvent)

e.Table = table
e.Action = action
e.Rows = rows
e.Header = header
e.NextPos = nextPos

e.handleUnsigned()

Expand Down
6 changes: 3 additions & 3 deletions canal/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (c *Canal) handleEvent(ev *replication.BinlogEvent) error {
}
case *replication.RowsEvent:
// we only focus row based event
err = c.handleRowsEvent(ev)
err = c.handleRowsEvent(ev, pos)
if err != nil {
c.cfg.Logger.Errorf("handle rows event at (%s, %d) error %v", pos.Name, curPos, err)
return errors.Trace(err)
Expand Down Expand Up @@ -262,7 +262,7 @@ func (c *Canal) updateReplicationDelay(ev *replication.BinlogEvent) {
atomic.StoreUint32(c.delay, newDelay)
}

func (c *Canal) handleRowsEvent(e *replication.BinlogEvent) error {
func (c *Canal) handleRowsEvent(e *replication.BinlogEvent, nextPos mysql.Position) error {
ev := e.Event.(*replication.RowsEvent)

// Caveat: table may be altered at runtime.
Expand Down Expand Up @@ -290,7 +290,7 @@ func (c *Canal) handleRowsEvent(e *replication.BinlogEvent) error {
default:
return errors.Errorf("%s not supported now", e.Header.EventType)
}
events := newRowsEvent(t, action, ev.Rows, e.Header)
events := newRowsEvent(t, action, ev.Rows, e.Header, &nextPos)
return c.eventHandler.OnRow(events)
}

Expand Down
Loading