From 733b2a81a53e31ad49833dcf710796c1ca1cf781 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Thu, 5 Sep 2024 08:44:55 +0300 Subject: [PATCH] BinlogEvent: publish ServerID() function Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/mysql/binlog_event.go | 2 ++ go/mysql/binlog_event_filepos.go | 4 ++++ go/mysql/binlog_event_make_test.go | 2 ++ 3 files changed, 8 insertions(+) diff --git a/go/mysql/binlog_event.go b/go/mysql/binlog_event.go index 5e5ce01eac3..1e26c62e12f 100644 --- a/go/mysql/binlog_event.go +++ b/go/mysql/binlog_event.go @@ -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. diff --git a/go/mysql/binlog_event_filepos.go b/go/mysql/binlog_event_filepos.go index 8a2976da80d..c71c8346964 100644 --- a/go/mysql/binlog_event_filepos.go +++ b/go/mysql/binlog_event_filepos.go @@ -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 } diff --git a/go/mysql/binlog_event_make_test.go b/go/mysql/binlog_event_make_test.go index 32401bfa401..be1ae7130b5 100644 --- a/go/mysql/binlog_event_make_test.go +++ b/go/mysql/binlog_event_make_test.go @@ -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) { @@ -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) {