Skip to main content

risingwave_connector/source/cdc/
mysql.rs

1// Copyright 2026 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::collections::BTreeMap;
16
17use rand::Rng;
18use risingwave_pb::secret::PbSecretRef;
19
20use crate::error::ConnectorResult;
21use crate::source::cdc::{
22    CdcSourceDdlValidator, CdcSourceExternalTableIdentifier, CdcSourceRuntimeFlags,
23    CdcSourceTypeTrait, Mysql, check_alter_with_options_inner, check_common_with_options,
24};
25
26// ------- Runtime flags -------
27
28impl CdcSourceRuntimeFlags for Mysql {
29    const CAN_AUTO_SCHEMA_CHANGE: bool = true;
30    const CAN_BACKFILL: bool = true;
31    const CAN_USE_TRANSACTION_METADATA: bool = true;
32    const NEEDS_NON_EMPTY_INITIAL_OFFSET: bool = true;
33}
34
35// ------- DDL validation -------
36
37impl CdcSourceDdlValidator for Mysql {
38    fn check_and_fill_create_with_options(
39        props: &mut BTreeMap<String, String>,
40        secret_refs: &BTreeMap<String, PbSecretRef>,
41    ) -> ConnectorResult<()> {
42        check_common_with_options::<Self>(props, secret_refs)?;
43        // Generate a random server id for mysql cdc source if needed
44        // `server.id` (in the range from 1 to 2^32 - 1). This value MUST be unique across whole replication
45        // group (that is, different from any other server id being used by any master or slave)
46        props
47            .entry("server.id".to_owned())
48            .or_insert(rand::rng().random_range(1..u32::MAX).to_string());
49        Ok(())
50    }
51
52    fn check_alter_with_options(
53        props: &BTreeMap<String, String>,
54        secret_refs: &BTreeMap<String, PbSecretRef>,
55    ) -> ConnectorResult<()> {
56        check_common_with_options::<Self>(props, secret_refs)?;
57        check_alter_with_options_inner(
58            Self::CDC_CONNECTOR_NAME,
59            props,
60            secret_refs,
61            &[
62                "cdc.source.wait.streaming.start.timeout",
63                "debezium.max.queue.size",
64                "debezium.queue.memory.ratio",
65                "hostname",
66                "port",
67                "password",
68            ],
69        )
70    }
71}
72
73// ------- External table identifier -------
74
75impl CdcSourceExternalTableIdentifier for Mysql {}