Skip to content

Commit 1d97bd2

Browse files
authored
Merge pull request #8501 from dolthub/fulghum/binlog-fixes
Bug fixes for replication
2 parents 6364199 + e197477 commit 1d97bd2

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

go/libraries/doltcore/sqle/binlogreplication/binlog_primary_streamer.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ func (streamer *binlogStreamer) startStream(ctx *sql.Context, conn *mysql.Conn,
8181

8282
case <-streamer.ticker.C:
8383
logrus.Debug("sending binlog heartbeat")
84-
if err := sendHeartbeat(conn, binlogFormat, *binlogEventMeta); err != nil {
84+
currentLogFilename := filepath.Base(streamer.currentLogFile.Name())
85+
if err := sendHeartbeat(conn, binlogFormat, *binlogEventMeta, currentLogFilename); err != nil {
8586
return err
8687
}
8788
if err := conn.FlushBuffer(); err != nil {
@@ -254,10 +255,14 @@ func (m *binlogStreamerManager) removeStreamer(streamer *binlogStreamer) {
254255
}
255256
}
256257

257-
func sendHeartbeat(conn *mysql.Conn, binlogFormat *mysql.BinlogFormat, binlogEventMeta mysql.BinlogEventMetadata) error {
258+
// sendHeartbeat sends a heartbeat event over |conn| using the specified |binlogFormat| and |binlogEventMeta| as well
259+
// as |currentLogFilename| to create the event payload.
260+
func sendHeartbeat(conn *mysql.Conn, binlogFormat *mysql.BinlogFormat, binlogEventMeta mysql.BinlogEventMetadata, currentLogFilename string) error {
258261
binlogEventMeta.Timestamp = uint32(0) // Timestamp is zero for a heartbeat event
259262
logrus.WithField("log_position", binlogEventMeta.NextLogPosition).Tracef("sending heartbeat")
260263

261-
binlogEvent := mysql.NewHeartbeatEvent(*binlogFormat, binlogEventMeta)
264+
// MySQL 8.4 requires that we pass the binlog filename in the heartbeat; previous versions accepted
265+
// heartbeat events without a filename, but those cause crashes on MySQL 8.4.
266+
binlogEvent := mysql.NewHeartbeatEventWithLogFile(*binlogFormat, binlogEventMeta, currentLogFilename)
262267
return conn.WriteBinlogEvent(binlogEvent, false)
263268
}

go/libraries/doltcore/sqle/binlogreplication/binlog_primary_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var doltReplicationPrimarySystemVars = map[string]string{
3333
"log_bin": "1",
3434
"enforce_gtid_consistency": "ON",
3535
"gtid_mode": "ON",
36+
"server_id": "42",
3637
}
3738

3839
// TestBinlogPrimary_BinlogNotEnabled tests that when binary logging is NOT enabled, primary commands such as
@@ -1024,9 +1025,6 @@ func setupForDoltToMySqlReplication() {
10241025
primaryDatabase = replicaDatabase
10251026
replicaDatabase = tempDatabase
10261027

1027-
// On the Primary, make sure we have a unique, non-zero SERVER_ID set
1028-
primaryDatabase.MustExec("set GLOBAL SERVER_ID=42;")
1029-
10301028
// Set the session's timezone to UTC, to avoid TIMESTAMP test values changing
10311029
// when they are converted to UTC for storage.
10321030
replicaDatabase.MustExec("SET @@time_zone = '+0:00';")

go/libraries/doltcore/sqle/binlogreplication/system_variable_utils.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020

2121
"github.com/dolthub/go-mysql-server/sql"
22+
"github.com/dolthub/go-mysql-server/sql/types"
2223
)
2324

2425
// getServerId returns the @@server_id global system variable value. If the value of @@server_id is 0 or is not a
@@ -29,7 +30,14 @@ func getServerId() (uint32, error) {
2930
return 0, fmt.Errorf("global variable 'server_id' not found")
3031
}
3132

32-
if i, ok := value.(uint32); ok {
33+
// Attempt to convert the server_id value into a UINT32, in case it has been loaded as a string
34+
// through global JSON configuration.
35+
convertedValue, _, err := types.Uint32.Convert(value)
36+
if err != nil {
37+
return 0, err
38+
}
39+
40+
if i, ok := convertedValue.(uint32); ok {
3341
if i == 0 {
3442
return 0, fmt.Errorf("@@server_id is zero – must be set to a non-zero value")
3543
}

0 commit comments

Comments
 (0)