{"record":{"id":"eea16422abfe55f3","repo":"risingwavelabs/risingwave","slug":"sql-server-min-lsn-is-null","errorCode":null,"errorMessage":"SQL Server min_lsn is NULL","messagePattern":"SQL Server min_lsn is NULL","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/connector/src/source/cdc/enumerator/mod.rs","lineNumber":353,"sourceCode":"                hex_string.push_str(&format!(\"{:02x}\", byte));\n            }\n            hex_string.push(':');\n            for byte in &bytes[8..10] {\n                hex_string.push_str(&format!(\"{:02x}\", byte));\n            }\n            Ok(hex_string)\n        };\n\n        let max_lsn = row\n            .try_get::<&[u8], usize>(0)?\n            .map(lsn_bytes_to_hex)\n            .transpose()?\n            .ok_or_else(|| anyhow!(\"SQL Server max_lsn is NULL\"))?;\n        let min_lsn = row\n            .try_get::<&[u8], usize>(1)?\n            .map(lsn_bytes_to_hex)\n            .transpose()?\n            .ok_or_else(|| anyhow!(\"SQL Server min_lsn is NULL\"))?;\n\n        Ok(Some((min_lsn, max_lsn)))\n    }\n\n    async fn monitor_sql_server_lsns(&mut self) -> ConnectorResult<()> {\n        let lsns = self.query_sql_server_lsns().await.with_context(|| {\n            format!(\n                \"failed to query SQL Server LSNs for source {}\",\n                self.source_id\n            )\n        })?;\n        if let Some((min_lsn, max_lsn)) = lsns {\n            let labels = vec![self.source_id.to_string()];\n\n            if let Some(value) = Self::sql_server_lsn_to_i64(&min_lsn) {\n                get_or_create_guarded_int_gauge(\n                    &mut self.sqlserver_cdc_upstream_min_lsn,\n                    &self.metrics.sqlserver_cdc_upstream_min_lsn,","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/connector/src/source/cdc/enumerator/mod.rs#L335-L371","documentation":"Same pattern as the max_lsn check: the min_lsn column, computed as `MIN(sys.fn_cdc_get_min_lsn(capture_instance))` over `cdc.change_tables`, is NULL, so hex conversion is impossible and this error is thrown. NULL here typically means no capture instances exist for the change tables.","triggerScenarios":"The LSN query returns a row whose second column (min_lsn) is NULL — `cdc.change_tables` has rows but `fn_cdc_get_min_lsn` yields NULL, or aggregates to NULL over an empty set.","commonSituations":"CDC table cleanup jobs removed capture instances; capture instances were dropped while the RW source still monitors them; database restored without restoring CDC metadata; low water mark never initialized.","solutions":["Re-enable CDC capture instances on the source table (`sys.sp_cdc_enable_table`)","Verify `SELECT capture_instance FROM cdc.change_tables` returns the expected instances","Restart the CDC capture job so the low water mark is established","If the table was dropped/altered, recreate the RW CDC source against a valid capture instance"],"exampleFix":"// re-create capture instance\nEXEC sys.sp_cdc_enable_table\n  @source_schema = N'dbo', @source_name = N'my_table',\n  @role_name = NULL;","handlingStrategy":"validation","validationCode":"// Precheck on SQL Server:\n// SELECT COUNT(*) FROM cdc.change_tables;\n// SELECT MIN(sys.fn_cdc_get_min_lsn(capture_instance)) FROM cdc.change_tables;","typeGuard":null,"tryCatchPattern":"match res {\n    Err(e) if e.to_string().contains(\"min_lsn is NULL\") => {\n        warn!(\"CDC min LSN unavailable; check capture instances on cdc.change_tables\");\n    }\n    other => other?,\n}","preventionTips":["Keep capture instances intact; do not drop tables under an active CDC source","Recreate capture instances after database restores","Monitor cdc.change_tables for cleanup-job side effects"],"tags":["cdc","sql-server","lsn","null-value"],"backgroundTag":"unexpected-response-shape","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}