risingwave_connector/source/cdc/
postgres.rs1use std::collections::BTreeMap;
16
17use risingwave_common::bail;
18use risingwave_pb::secret::PbSecretRef;
19
20use crate::error::ConnectorResult;
21use crate::source::cdc::{
22 CdcSourceDdlValidator, CdcSourceExternalTableIdentifier, CdcSourceRuntimeFlags,
23 CdcSourceTypeTrait, Postgres, check_alter_with_options_inner, check_common_with_options,
24};
25
26impl CdcSourceRuntimeFlags for Postgres {
29 const CAN_AUTO_SCHEMA_CHANGE: bool = true;
30 const CAN_BACKFILL: bool = true;
31 const CAN_BACKFILL_IN_PARALLEL: bool = true;
32 const CAN_USE_TRANSACTION_METADATA: bool = true;
33 const NEEDS_OFFSET_COMMIT_ON_CHECKPOINT: bool = true;
34}
35
36impl CdcSourceDdlValidator for Postgres {
39 fn check_and_fill_create_with_options(
40 props: &mut BTreeMap<String, String>,
41 secret_refs: &BTreeMap<String, PbSecretRef>,
42 ) -> ConnectorResult<()> {
43 check_common_with_options::<Self>(props, secret_refs)?;
44 match props.get("slot.name") {
45 None => {
46 let uuid = uuid::Uuid::new_v4();
49 props.insert("slot.name".into(), format!("rw_cdc_{}", uuid.simple()));
50 }
51 Some(slot_name) => {
52 if !slot_name
56 .chars()
57 .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_')
58 || slot_name.len() > 63
59 {
60 bail!(
61 "Invalid replication slot name: {:?}. Valid replication slot name must contain only digits, lowercase characters and underscores with length <= 63",
62 slot_name
63 );
64 }
65 }
66 }
67
68 if !props.contains_key("schema.name") {
69 props.insert("schema.name".into(), "public".into());
71 }
72 if !props.contains_key("publication.name") {
73 let uuid = uuid::Uuid::new_v4();
76 props.insert(
77 "publication.name".into(),
78 format!("rw_publication_{}", uuid.simple()),
79 );
80 }
81 if !props.contains_key("publication.create.enable") {
82 props.insert("publication.create.enable".into(), "true".into());
84 }
85 Ok(())
86 }
87
88 fn check_alter_with_options(
89 props: &BTreeMap<String, String>,
90 secret_refs: &BTreeMap<String, PbSecretRef>,
91 ) -> ConnectorResult<()> {
92 check_common_with_options::<Self>(props, secret_refs)?;
93 check_alter_with_options_inner(
94 Self::CDC_CONNECTOR_NAME,
95 props,
96 secret_refs,
97 &[
98 "cdc.source.wait.streaming.start.timeout",
99 "debezium.max.queue.size",
100 "debezium.queue.memory.ratio",
101 "debezium.heartbeat.interval.ms",
102 "hostname",
103 "port",
104 "password",
105 ],
106 )
107 }
108}
109
110impl CdcSourceExternalTableIdentifier for Postgres {}