Skip to content

Commit 2c27d94

Browse files
authored
change FillZeroLog config name and add to canal (#1053)
* change config name and add to canal * change config name in readme
1 parent 23711c9 commit 2c27d94

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import (
6262
"github.com/go-mysql-org/go-mysql/replication"
6363
"os"
6464
)
65-
// Create a binlog syncer with a unique server id, the server id must be different from other MySQL's.
65+
// Create a binlog syncer with a unique server id, the server id must be different from other MySQL's.
6666
// flavor is mysql or mariadb
6767
cfg := replication.BinlogSyncerConfig {
6868
ServerID: 100,
@@ -137,7 +137,7 @@ Query: DROP TABLE IF EXISTS `test_replication` /* generated by server */
137137

138138
MariaDB 11.4+ introduced an optimization where events written through transaction or statement cache have `LogPos=0` so they can be copied directly to the binlog without computing the real end position. This optimization improves performance but makes position tracking unreliable for replication clients that need to track LogPos of events inside transactions.
139139

140-
To address this, a `MariaDBDynamicLogPos` configuration option is available:
140+
To address this, a `FillZeroLogPos` configuration option is available:
141141

142142
```go
143143
cfg := replication.BinlogSyncerConfig {
@@ -148,24 +148,24 @@ cfg := replication.BinlogSyncerConfig {
148148
User: "root",
149149
Password: "",
150150
// Enable dynamic LogPos calculation for MariaDB 11.4+
151-
MariaDBDynamicLogPos: true,
151+
FillZeroLogPos: true,
152152
}
153153
```
154154

155155
**Behavior:**
156-
- When `MariaDBDynamicLogPos` is `true` and flavor is `mariadb`, the library automatically:
156+
- When `FillZeroLogPos` is `true` and flavor is `mariadb`, the library automatically:
157157
- Adds `BINLOG_SEND_ANNOTATE_ROWS_EVENT` flag to binlog dump commands. This ensures correct position tracking by making the server send `ANNOTATE_ROWS_EVENT` events which are needed for accurate position calculation.
158-
- Calculates LogPos dynamically for events with `LogPos=0` that are not artificial.
158+
- Calculates LogPos dynamically for events with `LogPos=0` that are not artificial.
159159
- Only works with MariaDB flavor; has no effect with MySQL.
160160
- Should be set to `true` if tracking of LogPos inside transactions is required.
161161

162162
## Canal
163163

164164
Canal is a package that can sync your MySQL into everywhere, like Redis, Elasticsearch.
165165

166-
First, canal will dump your MySQL data then sync changed data using binlog incrementally.
166+
First, canal will dump your MySQL data then sync changed data using binlog incrementally.
167167

168-
You must use ROW format for binlog, full binlog row image is preferred, because we may meet some errors when primary key changed in update for minimal or noblob row image.
168+
You must use ROW format for binlog, full binlog row image is preferred, because we may meet some errors when primary key changed in update for minimal or noblob row image.
169169

170170
A simple example:
171171

@@ -214,9 +214,9 @@ You can see [go-mysql-elasticsearch](https://github.com/go-mysql-org/go-mysql-el
214214

215215
## Client
216216

217-
Client package supports a simple MySQL connection driver which you can use it to communicate with MySQL server.
217+
Client package supports a simple MySQL connection driver which you can use it to communicate with MySQL server.
218218

219-
For an example see [`example_client_test.go`](client/example_client_test.go). You can run this testable example with
219+
For an example see [`example_client_test.go`](client/example_client_test.go). You can run this testable example with
220220
`go test -v ./client -run Example`.
221221

222222
Tested MySQL versions for the client include:
@@ -263,7 +263,7 @@ conn.Execute() / conn.Begin() / etc...
263263

264264
## Server
265265

266-
Server package supplies a framework to implement a simple MySQL server which can handle the packets from the MySQL client.
266+
Server package supplies a framework to implement a simple MySQL server which can handle the packets from the MySQL client.
267267
You can use it to build your own MySQL proxy. The server connection is compatible with MySQL 5.5, 5.6, 5.7, and 8.0 versions,
268268
so that most MySQL clients should be able to connect to the Server without modifications.
269269

@@ -519,7 +519,7 @@ We pass all tests in https://github.com/bradfitz/go-sql-test using go-mysql driv
519519

520520
Logging uses [log/slog](https://pkg.go.dev/log/slog) and by default is sent to standard out.
521521

522-
For the old logging package `github.com/siddontang/go-log/log`, a converting package
522+
For the old logging package `github.com/siddontang/go-log/log`, a converting package
523523
`https://github.com/serprex/slog-siddontang` is available.
524524
## How to migrate to this repo
525525
To change the used package in your repo it's enough to add this `replace` directive to your `go.mod`:

canal/canal.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ func (c *Canal) prepareSyncer() error {
466466
Dialer: c.cfg.Dialer,
467467
Localhost: c.cfg.Localhost,
468468
EventCacheCount: c.cfg.EventCacheCount,
469+
FillZeroLogPos: c.cfg.FillZeroLogPos,
470+
469471
RowsEventDecodeFunc: func(event *replication.RowsEvent, data []byte) error {
470472
pos, err := event.DecodeHeader(data)
471473
if err != nil {

canal/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ type Config struct {
113113
// the default value is 10240.
114114
// if you table contain large columns, you can decrease this value to avoid OOM.
115115
EventCacheCount int
116+
117+
// FillZeroLogPos enables dynamic LogPos calculation for MariaDB.
118+
// When enabled, automatically adds BINLOG_SEND_ANNOTATE_ROWS_EVENT flag
119+
// to ensure correct position calculation in MariaDB 11.4+.
120+
// Only works with MariaDB flavor.
121+
FillZeroLogPos bool
116122
}
117123

118124
func NewConfigWithFile(name string) (*Config, error) {

replication/binlogsyncer.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ type BinlogSyncerConfig struct {
128128

129129
EventCacheCount int
130130

131-
// MariaDBDynamicLogPos enables dynamic LogPos calculation for MariaDB.
131+
// FillZeroLogPos enables dynamic LogPos calculation for MariaDB.
132132
// When enabled, automatically adds BINLOG_SEND_ANNOTATE_ROWS_EVENT flag
133133
// to ensure correct position calculation in MariaDB 11.4+.
134134
// Only works with MariaDB flavor.
135-
MariaDBDynamicLogPos bool
135+
FillZeroLogPos bool
136136

137137
// SynchronousEventHandler is used for synchronous event handling.
138138
// This should not be used together with StartBackupWithHandler.
@@ -516,8 +516,8 @@ func (b *BinlogSyncer) writeBinlogDumpCommand(p mysql.Position) error {
516516
pos += 4
517517

518518
dumpCommandFlag := b.cfg.DumpCommandFlag
519-
if b.cfg.MariaDBDynamicLogPos && b.cfg.Flavor == mysql.MariaDBFlavor {
520-
// Add BINLOG_SEND_ANNOTATE_ROWS_EVENT flag when MariaDBDynamicLogPos is enabled.
519+
if b.cfg.FillZeroLogPos && b.cfg.Flavor == mysql.MariaDBFlavor {
520+
// Add BINLOG_SEND_ANNOTATE_ROWS_EVENT flag when FillZeroLogPos is enabled.
521521
// This ensures the server sends ANNOTATE_ROWS_EVENT events which are needed
522522
// for correct LogPos calculation in MariaDB 11.4+, where some events have LogPos=0.
523523
dumpCommandFlag |= BINLOG_SEND_ANNOTATE_ROWS_EVENT
@@ -966,12 +966,12 @@ func (b *BinlogSyncer) handleEventAndACK(s *BinlogStreamer, e *BinlogEvent, need
966966

967967
// shouldCalculateDynamicLogPos determines if we should calculate LogPos dynamically for MariaDB events.
968968
// This is needed for MariaDB 11.4+ when:
969-
// 1. MariaDBDynamicLogPos is enabled
969+
// 1. FillZeroLogPos is enabled
970970
// 2. We're using MariaDB flavor
971971
// 3. The event has LogPos=0 (indicating server didn't set it)
972972
// 4. The event is not artificial (not marked with LOG_EVENT_ARTIFICIAL_F flag)
973973
func (b *BinlogSyncer) shouldCalculateDynamicLogPos(e *BinlogEvent) bool {
974-
return b.cfg.MariaDBDynamicLogPos &&
974+
return b.cfg.FillZeroLogPos &&
975975
b.cfg.Flavor == mysql.MariaDBFlavor &&
976976
e.Header.LogPos == 0 &&
977977
(e.Header.Flags&LOG_EVENT_ARTIFICIAL_F) == 0

0 commit comments

Comments
 (0)