Skip to content

Commit

Permalink
BinlogEvent: publish ServerID() function (#16713)
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
  • Loading branch information
shlomi-noach committed Sep 15, 2024
1 parent 646bfd4 commit fe28d72
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go/mysql/binlog_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ type BinlogEvent interface {

// Timestamp returns the timestamp from the event header.
Timestamp() uint32
// ServerID returns the server ID from the event header.
ServerID() uint32

// Format returns a BinlogFormat struct based on the event data.
// This is only valid if IsFormatDescription() returns true.
Expand Down
4 changes: 4 additions & 0 deletions go/mysql/binlog_event_filepos.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ func (ev filePosFakeEvent) Timestamp() uint32 {
return ev.timestamp
}

func (ev filePosFakeEvent) ServerID() uint32 {
return 1
}

func (ev filePosFakeEvent) Format() (BinlogFormat, error) {
return BinlogFormat{}, nil
}
Expand Down
2 changes: 2 additions & 0 deletions go/mysql/binlog_event_make_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ func TestRowsEvent(t *testing.T) {
require.True(t, reflect.DeepEqual(gotRows, rows), "NewRowsEvent().Rows() got Rows:\n%v\nexpected:\n%v", gotRows, rows)

assert.NotZero(t, event.Timestamp())
assert.NotZero(t, event.ServerID())
}

func TestHeartbeatEvent(t *testing.T) {
Expand All @@ -384,6 +385,7 @@ func TestHeartbeatEvent(t *testing.T) {
require.NotNil(t, event)
assert.True(t, event.IsHeartbeat())
assert.Zero(t, event.Timestamp())
assert.NotZero(t, event.ServerID())
}

func TestRotateRotateEvent(t *testing.T) {
Expand Down

0 comments on commit fe28d72

Please sign in to comment.