()
| 47 | |
| 48 | #[tokio::main] |
| 49 | async fn main() -> Result<(), anyhow::Error> { |
| 50 | tracing_subscriber::fmt() |
| 51 | .with_env_filter(EnvFilter::from_default_env()) |
| 52 | .init(); |
| 53 | |
| 54 | let mut config = tiberius::Config::new(); |
| 55 | |
| 56 | config.host("localhost"); |
| 57 | config.port(1433); |
| 58 | config.database("materialize"); |
| 59 | config.authentication(tiberius::AuthMethod::sql_server("SA", "password123?")); |
| 60 | config.trust_cert(); |
| 61 | |
| 62 | // Open one client to stream changes. |
| 63 | let tunnel = TunnelConfig::Direct { |
| 64 | resolved_addresses: Default::default(), |
| 65 | }; |
| 66 | let mz_config = Config::new(config.clone(), tunnel.clone(), InTask::No); |
| 67 | let mut client_1 = Client::connect(mz_config).await?; |
| 68 | tracing::info!("connection 1 successful!"); |
| 69 | |
| 70 | let capture_instances = ["materialize_t1", "materialize_t2"]; |
| 71 | let metrics = LoggingSqlServerCdcMetrics; |
| 72 | let mut cdc_handle = client_1.cdc(capture_instances, metrics); |
| 73 | |
| 74 | cdc_handle.wait_for_ready().await?; |
| 75 | |
| 76 | // Open a second client that we can use to cleanup the underlying change tables. |
| 77 | let mz_config = Config::new(config.clone(), tunnel, InTask::No); |
| 78 | let mut client_2 = Client::connect(mz_config).await?; |
| 79 | tracing::info!("connection 2 successful!"); |
| 80 | |
| 81 | let tables = mz_sql_server_util::inspect::get_tables_for_capture_instance( |
| 82 | &mut client_2, |
| 83 | capture_instances, |
| 84 | ) |
| 85 | .await?; |
| 86 | let mut instance_to_lsn = BTreeMap::new(); |
| 87 | |
| 88 | for table in tables { |
| 89 | // Get an initial snapshot of the table. |
| 90 | let (lsn, snapshot) = cdc_handle |
| 91 | .snapshot(&table, 1, mz_repr::GlobalId::User(1)) |
| 92 | .await?; |
| 93 | |
| 94 | instance_to_lsn.insert(Arc::clone(&table.capture_instance.name), lsn); |
| 95 | |
| 96 | let mut snapshot = std::pin::pin!(snapshot); |
| 97 | while let Some(result) = snapshot.next().await { |
| 98 | let row = result?; |
| 99 | tracing::info!("snapshot: {} {row:?}", &table.capture_instance.name); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // Initialize all capture instances at the LSN we just snapshotted. |
| 104 | for instance in capture_instances { |
| 105 | let lsn = instance_to_lsn |
| 106 | .remove(instance) |
nothing calls this directly
no test coverage detected