@@ -16,6 +16,7 @@ package plan
1616
1717import (
1818 "github.com/dolthub/go-mysql-server/sql"
19+ "github.com/dolthub/go-mysql-server/sql/binlogreplication"
1920 "github.com/dolthub/go-mysql-server/sql/types"
2021)
2122
@@ -27,47 +28,33 @@ const DynamicPrivilege_BinlogAdmin = "binlog_admin"
2728// mysqldump, mysqlbinlog, and mariadb-binlog read these binary events from log files and output them as base64-encoded
2829// BINLOG statements for replay.
2930//
30- // This implementation supports row-based replication (RBR) events, which is the modern standard for MySQL/MariaDB
31- // replication (default since MySQL 5.7+ and MariaDB 10.2+).
32- //
33- // The base64 string is split by newlines and decoded into a buffer of raw binlog events. Each event begins with a
34- // 19-byte header containing the event type at byte 4 and event length at bytes 9-12. The buffer is processed
35- // sequentially, dispatching each event to a handler based on its type.
36- //
37- // FORMAT_DESCRIPTION_EVENT stores binlog format metadata in session state. This metadata includes header sizes for each
38- // event type and the checksum algorithm (OFF, CRC32, or UNDEF). Subsequent events require this metadata to parse their
39- // headers and determine whether checksums are present.
40- //
41- // TABLE_MAP_EVENT creates a mapping from a table ID to the database name, table name, and column metadata. Row events
42- // reference tables by ID rather than name for encoding efficiency. The mapping is stored in a global cache for use by
43- // subsequent row events.
44- //
45- // WRITE_ROWS_EVENT, UPDATE_ROWS_EVENT, and DELETE_ROWS_EVENT contain binary-encoded row data. Before parsing row data,
46- // any CRC32 checksum appended to the event must be stripped. Checksums verify data integrity during network
47- // transmission and disk storage but are not part of the event payload structure.
48- //
49- // Transaction boundary and metadata events are silently ignored since each BINLOG statement is auto-committed and full
50- // replication semantics are not required for mysqldump replay.
51- //
52- // QUERY_EVENT (statement-based replication) is not currently supported. Statement-based replication is deprecated in
53- // favor of row-based replication to correctly support non-deterministic functions.
31+ // The BINLOG statement execution is delegated to the BinlogReplicaController. The base64-encoded event data is decoded
32+ // and passed to the controller's ConsumeBinlogEvents method for processing. This allows integrators like Dolt to handle
33+ // BINLOG statement execution using their existing binlog replication infrastructure.
5434//
5535// See https://dev.mysql.com/doc/refman/8.4/en/binlog.html for the BINLOG statement specification.
5636type Binlog struct {
57- Base64Str string
58- Catalog sql. Catalog
37+ Base64Str string
38+ ReplicaController binlogreplication. BinlogReplicaController
5939}
6040
6141var _ sql.Node = (* Binlog )(nil )
42+ var _ BinlogReplicaControllerCommand = (* Binlog )(nil )
6243
6344// NewBinlog creates a new Binlog node.
64- func NewBinlog (base64Str string , catalog sql. Catalog ) * Binlog {
45+ func NewBinlog (base64Str string ) * Binlog {
6546 return & Binlog {
6647 Base64Str : base64Str ,
67- Catalog : catalog ,
6848 }
6949}
7050
51+ // WithBinlogReplicaController implements the BinlogReplicaControllerCommand interface.
52+ func (b * Binlog ) WithBinlogReplicaController (controller binlogreplication.BinlogReplicaController ) sql.Node {
53+ nc := * b
54+ nc .ReplicaController = controller
55+ return & nc
56+ }
57+
7158func (b * Binlog ) String () string {
7259 return "BINLOG"
7360}
0 commit comments