Expand description
MySQL binlog replication CDC source connector. MySQL binlog replication CDC source connector.
This module implements a MySQL CDC source that reads change events from MySQL binary log (binlog) replication stream. It supports:
- GTID-based and file/position-based replication
- Row-based replication format (INSERT/UPDATE/DELETE events)
- Table filtering with include/exclude patterns
- SSL/TLS connections
- Automatic schema discovery via TABLE_MAP events
- Z-set changelog format
§Architecture
MySQL Server
│
│ Binlog Replication Protocol
▼
┌─────────────────────────────────────────┐
│ MySqlCdcSource │
│ ┌─────────────┐ ┌─────────────────┐ │
│ │ Decoder │ │ TableCache │ │
│ │ (binlog → │ │ (TABLE_MAP → │ │
│ │ messages) │ │ Arrow schema) │ │
│ └─────────────┘ └─────────────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────────────────────────────┐ │
│ │ ChangeEvent │ │
│ │ (Z-set with before/after) │ │
│ └─────────────────────────────────┘ │
└─────────────────────────────────────────┘
│
▼
RecordBatch (Arrow)§Example
ⓘ
use laminar_connectors::cdc::mysql::{MySqlCdcSource, MySqlCdcConfig};
let config = MySqlCdcConfig {
host: "localhost".to_string(),
port: 3306,
username: "replicator".to_string(),
password: "secret".to_string(),
database: Some("mydb".to_string()),
server_id: 12345,
use_gtid: true,
..Default::default()
};
let mut source = MySqlCdcSource::new(config);
source.open(&Default::default()).await?;
while let Some(batch) = source.poll_batch(1000).await? {
// Process CDC events as Arrow RecordBatch
println!("Received {} rows", batch.num_rows());
}Modules§
- mysql_
io - MySQL CDC binlog I/O integration module.
- mysql_
type - MySQL column type constants.
Structs§
- Begin
Message - Transaction begin message (from GTID event).
- Binlog
Position - Position in the MySQL binlog.
- Change
Event - A CDC change event from MySQL binlog.
- Commit
Message - Transaction commit message (from XID event).
- Delete
Message - Row delete message.
- Gtid
- A MySQL Global Transaction Identifier (GTID).
- Gtid
Range - A range of transaction IDs for a single source.
- GtidSet
- A set of GTIDs representing a position in the replication stream.
- Insert
Message - Row insert message.
- Metrics
Snapshot - A snapshot of metrics values at a point in time.
- MySql
CdcConfig - Configuration for the MySQL CDC source connector.
- MySql
CdcMetrics - Metrics for MySQL CDC source connector.
- MySql
CdcSource - MySQL binlog CDC source connector.
- MySql
Column - MySQL column metadata from TABLE_MAP_EVENT.
- Query
Message - Query event (typically DDL).
- Rotate
Message - Rotate event (binlog file change).
- RowData
- Row data containing column values.
- Table
Cache - Cache of table schemas indexed by table ID.
- Table
Info - Table schema information from TABLE_MAP_EVENT.
- Table
MapMessage - Table map message (schema definition for row events).
- Update
Message - Row update message.
- Update
RowData - Update row data with before and after images.
Enums§
- Binlog
Message - A decoded binlog message from MySQL replication.
- CdcOperation
- CDC operation types.
- Column
Value - A single column value.
- Decoder
Error - Decoder errors.
- Snapshot
Mode - How to handle the initial snapshot when no prior checkpoint exists.
- SslMode
- SSL connection mode for MySQL.
Functions§
- cdc_
envelope_ schema - Builds the CDC envelope schema for MySQL CDC records.
- column_
value_ to_ json - Converts a single column value to JSON for the CDC envelope.
- config_
key_ specs - Returns the configuration key specifications for
MySQLCDC source. - delete_
to_ events - Converts a DELETE message to change events.
- events_
to_ record_ batch - Converts change events to a
RecordBatchwith CDC metadata + row data. - insert_
to_ events - Converts an INSERT message to change events.
- mysql_
type_ name - Returns the human-readable name of a MySQL type.
- mysql_
type_ to_ arrow - Converts a MySQL type ID to an Arrow
DataType. - mysql_
type_ to_ sql - SQL type string for DDL generation.
- register_
mysql_ cdc_ source - Registers the MySQL CDC source connector factory.
- row_
to_ json - Converts a row to JSON object.
- update_
to_ events - Converts an UPDATE message to change events.