bug(cdc): mysql-cdc on MariaDB crash-loops forever on `SET STATEMENT ... FOR <stmt>` binlog events
Summary
A mysql-cdc source whose upstream is MariaDB stops ingesting for good once the binlog contains a Query event of the form SET STATEMENT <var>=<value> FOR <statement>:
- Debezium's MySQL DDL parser can't parse the MariaDB-only
SET STATEMENT ... FORprefix, and the Debezium engine stops. - RisingWave restarts the engine about every 2 s from the last committed offset, which is before the event.
- The engine fails on the same event again, forever.
No data flows after that point. Nothing reports the problem either: the source health gauge stays up, and the upstream only sees connections opening and closing normally.
We hit this on AWS RDS for MariaDB, where the managed automation ran SET STATEMENT max_statement_time=60 FOR flush table. A user DDL with the same wrapper fails the same way, for example SET STATEMENT lock_wait_timeout=5 FOR ALTER TABLE .... Both cases were reproduced end-to-end with MariaDB 11.4 + RisingWave v3.0.3 (see below).
Environment
- RisingWave
release-3.0(v3.0.x) andmain. Both are on Debezium3.2.4.Final(java/pom.xml). - Upstream: AWS RDS for MariaDB,
binlog_format=ROW.
Symptom
Compute node log chain. It repeats every ~2 s, always at the same binlog position:
Error during binlog processing ...
Producer failure io.debezium.DebeziumException: Error processing binlog event
at io.debezium.connector.binlog.BinlogStreamingChangeEventSource.handleEvent(BinlogStreamingChangeEventSource.java:593)
Caused by: io.debezium.text.ParsingException: DDL statement couldn't be parsed. Please open a Jira issue with the statement 'SET STATEMENT max_statement_time=60 FOR flush table'
no viable alternative at input 'SET STATEMENT max_statement_time'
at io.debezium.connector.mysql.antlr.MySqlAntlrDdlParser.parseTree(MySqlAntlrDdlParser.java:75)
at io.debezium.connector.binlog.BinlogDatabaseSchema.parseStreamingDdl(BinlogDatabaseSchema.java:258)
at io.debezium.connector.binlog.BinlogStreamingChangeEventSource.handleQueryEvent(BinlogStreamingChangeEventSource.java:742)
engine#<source_id> terminated with error. message: org.apache.kafka.connect.errors.ConnectException: An exception occurred in the change event producer. This connector will be stopped.
Cdc engine failed ...
Starting MySqlConnectorTask with configuration: ...Root cause
- RisingWave's
mysql-cdcalways runs Debezium'sMySqlConnector, which uses the MySQL ANTLR grammar (java/connector-node/risingwave-connector-service/src/main/resources/mysql.properties:2).SET STATEMENT ... FORexists only in Debezium's MariaDB grammar (setStatementForinMariaDBParser.g4). - Debezium 3.2.4
BinlogStreamingChangeEventSource.handleQueryEventstrips theSET STATEMENT ... FORprefix (removeSetStatement) only for its XA / DML checks. Both the DDL filter (schema.ddlFilter().test(sql)) andschema.parseStreamingDdl(partition, sql, ...)(line 742) get the raw SQL. Debeziummainhas the same code. schema.history.internal.skip.unparseable.ddldefaults tofalse, so theParsingExceptionstops the connector. RisingWave then restarts the engine from an offset before the event, so the loop never ends.
Impact
- Stalled source. The source stays stalled until someone intervenes by hand. Every table, MV and sink fed by it stops updating.
- Health doesn't see it.
source_status_is_upis set by the meta-side enumerator tick (src/meta/src/stream/source_manager/worker.rs,tick(); onmain, the CDC tick queries the upstream binlog list). It stays1while the compute-side Debezium engine crash-loops. - Upstream load. Every restart opens a new JDBC connection and a new binlog dump connection.
- On MariaDB the committed offset stays at the start of the current binlog file:
{file=..., pos=0, row=1}, withBinary log position adjusted from 0 to 4on every restart. We saw this in production and in the repro. - So every restart re-streams the file from its beginning up to the failing event. In production this meant tens of MB/s of continuous egress from the upstream.
- The
pos=0offset may deserve its own look.
- On MariaDB the committed offset stays at the start of the current binlog file:
- Binlog retention. If the upstream purges the stuck binlog file before the fix, the only way back is a full re-snapshot.
Reproduction
End-to-end in Docker (verified: MariaDB 11.4.13 + RisingWave v3.0.3)
docker network create rw-mariadb-repro
docker run -d --name repro-mariadb --network rw-mariadb-repro -p 13306:3306 \
-e MARIADB_ROOT_PASSWORD=pw -e MARIADB_DATABASE=testdb mariadb:11.4 \
--log-bin=mysql-bin --binlog-format=ROW --binlog-row-image=FULL --server-id=1
docker run -d --name repro-rw --network rw-mariadb-repro -p 4566:4566 risingwavelabs/risingwave:v3.0.3-- MariaDB
CREATE TABLE testdb.t (id INT PRIMARY KEY, v VARCHAR(20));
INSERT INTO testdb.t VALUES (1, 'a');
-- RisingWave
CREATE SOURCE s WITH (connector = 'mysql-cdc', hostname = 'repro-mariadb', port = '3306',
username = 'root', password = 'pw', database.name = 'testdb', server.id = '5454');
CREATE TABLE t (id INT PRIMARY KEY, v VARCHAR) FROM s TABLE 'testdb.t';
-- row 1 arrives; a later INSERT (2,'b') also arrives
-- MariaDB
SET STATEMENT max_statement_time=60 FOR FLUSH TABLES;
INSERT INTO testdb.t VALUES (3, 'c');Binlog. SHOW BINLOG EVENTS has mysql-bin.000002 995 Query 1 1110 SET STATEMENT max_statement_time=60 FOR FLUSH TABLES.
RisingWave. It logs the error chain above:
Error during binlog processing. Last offset stored = {..., file=mysql-bin.000002, pos=995, ...}, binlog reader near position = mysql-bin.000002/995
Caused by: io.debezium.text.ParsingException: DDL statement couldn't be parsed. Please open a Jira issue with the statement 'SET STATEMENT max_statement_time=60 FOR FLUSH TABLES'
engine#6 terminated with error. ... This connector will be stopped.- Over 30 s there were 19
Starting MySqlConnectorTask/terminated with errorpairs, all atmysql-bin.000002/995. - Row 3 never arrives.
Wrapped ALTER. The same happens with a wrapped ALTER on a captured table, tested on a second source: SET STATEMENT lock_wait_timeout=5 FOR ALTER TABLE testdb.t2 ADD COLUMN c INT fails with no viable alternative at input 'SET STATEMENT lock_wait_timeout', and that source crash-loops too.
Parser level (Debezium 3.2.4 MySqlAntlrDdlParser)
FAIL | SET STATEMENT max_statement_time=60 FOR flush table
OK | flush table
FAIL | SET STATEMENT lock_wait_timeout=5 FOR ALTER TABLE t ADD COLUMN c INTWorkaround (only for statements that are safe to drop)
Verified in production on a release-3.0 build and in the Docker repro above.
ALTER SOURCE ... CONNECTOR WITH (...) can't set debezium.* keys: the mysql-cdc allowlist in src/connector/src/allow_alter_on_fly_fields.rs has only 6 keys. risectl skips the allowlist (skip_alter_on_fly_check), so use it to add a DDL filter for the offending statement:
# in the meta pod/container; single_node needs RW_META_ADDR=http://127.0.0.1:5690
risingwave ctl meta alter-source-properties-safe --source-id <source_id> \
--props '{"debezium.internal.schema.history.internal.ddl.filter": "<Debezium default ddl.filter list>,SET STATEMENT .* FOR FLUSH .*"}'- Use the
internal.key. Debezium declaresSchemaHistory.DDL_FILTERwithField.createInternal(...), which prependsinternal., so the effective key isinternal.schema.history.internal.ddl.filter.debezium.schema.history.internal.ddl.filteris accepted and shows up in theStarting MySqlConnectorTaskconfig log, but it's silently ignored.- In the repro, the source kept crash-looping with that key (26 restarts in 40 s). With the
internal.key, the stuck row arrived about 10 s after the change and streaming resumed. new MySqlConnectorConfig(config).ddlFilter()confirms it: the first key leaves the default filter in place.
- Copy the default patterns. The value replaces Debezium's default filter list, which includes the RDS heartbeat patterns, so repeat the default patterns and append the new one.
- Definition rewrite on older builds. On builds without #26923, this
risectlcall rewrites the source definition with the quoting bug that #26923 fixes. - No safe workaround for wrapped DDL on captured tables. The workaround only covers statements that are safe to drop, like
FLUSH.- Filtering the ALTER, or setting
debezium.schema.history.internal.skip.unparseable.ddl=true, lets the source continue, but the schema change is lost and the schema drifts silently. - Even a source that already had the
FOR FLUSHfilter crash-looped again on the wrappedALTER TABLEin the repro. - So the real fix has to be in the parser path (fix 1 below).
- Filtering the ALTER, or setting
Proposed fix
- Strip the
SET STATEMENT ... FORprefix before the DDL filter and the parser.SET STATEMENTonly sets session variables for the duration of the wrapped statement, so removing it doesn't change the statement's schema effect. RisingWave already overridesio.debezium.connector.mysql.MySqlStreamingChangeEventSource, but the query-event handling lives in the binlog base class. So this needs an override there, a wrapper around the DDL parser, or an upstream Debezium fix. - Alternatively, use Debezium's MariaDB connector/grammar when the upstream is MariaDB. This is a larger change: offset and GTID handling differ.
- Let
ALTER SOURCE ... CONNECTOR WITHsetdebezium.*keys, or at least the DDL filter and skip keys, for CDC sources. Then this kind of mitigation doesn't needrisectl. - Surface compute-side engine failures in source health. For example, mark the source down, or emit an error event, after N consecutive engine failures at the same offset.
Source: risingwavelabs/risingwave