#27260·risingwave

bug(cdc): mysql-cdc on MariaDB crash-loops forever on `SET STATEMENT ... FOR <stmt>` binlog events

Author: yuhao-suCreated Sep 25, 2026Updated Sep 28, 2026
Labelstype/bugA-cdcmysql-cdc

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>:

  1. Debezium's MySQL DDL parser can't parse the MariaDB-only SET STATEMENT ... FOR prefix, and the Debezium engine stops.
  2. RisingWave restarts the engine about every 2 s from the last committed offset, which is before the event.
  3. 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) and main. Both are on Debezium 3.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

  1. RisingWave's mysql-cdc always runs Debezium's MySqlConnector, which uses the MySQL ANTLR grammar (java/connector-node/risingwave-connector-service/src/main/resources/mysql.properties:2). SET STATEMENT ... FOR exists only in Debezium's MariaDB grammar (setStatementFor in MariaDBParser.g4).
  2. Debezium 3.2.4 BinlogStreamingChangeEventSource.handleQueryEvent strips the SET STATEMENT ... FOR prefix (removeSetStatement) only for its XA / DML checks. Both the DDL filter (schema.ddlFilter().test(sql)) and schema.parseStreamingDdl(partition, sql, ...) (line 742) get the raw SQL. Debezium main has the same code.
  3. schema.history.internal.skip.unparseable.ddl defaults to false, so the ParsingException stops 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_up is set by the meta-side enumerator tick (src/meta/src/stream/source_manager/worker.rs, tick(); on main, the CDC tick queries the upstream binlog list). It stays 1 while 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}, with Binary log position adjusted from 0 to 4 on 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=0 offset may deserve its own look.
  • 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)

bash
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
sql
-- 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 error pairs, all at mysql-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 INT

Workaround (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:

bash
# 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 declares SchemaHistory.DDL_FILTER with Field.createInternal(...), which prepends internal., so the effective key is internal.schema.history.internal.ddl.filter.
    • debezium.schema.history.internal.ddl.filter is accepted and shows up in the Starting MySqlConnectorTask config 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 risectl call 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 FLUSH filter crash-looped again on the wrapped ALTER TABLE in the repro.
    • So the real fix has to be in the parser path (fix 1 below).

Proposed fix

  1. Strip the SET STATEMENT ... FOR prefix before the DDL filter and the parser. SET STATEMENT only sets session variables for the duration of the wrapped statement, so removing it doesn't change the statement's schema effect. RisingWave already overrides io.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.
  2. Alternatively, use Debezium's MariaDB connector/grammar when the upstream is MariaDB. This is a larger change: offset and GTID handling differ.
  3. Let ALTER SOURCE ... CONNECTOR WITH set debezium.* keys, or at least the DDL filter and skip keys, for CDC sources. Then this kind of mitigation doesn't need risectl.
  4. 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