Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,63 @@ All notable changes to dbmazz will be documented here.

## [Unreleased]

### Added

- **Schema evolution for the StarRocks and Snowflake sinks.** Source-side
`ALTER TABLE ADD COLUMN` is now propagated automatically to the target table
in both sinks, bringing them to parity with the Postgres sink (which gained
this in v1.7.0). The conservative policy is shared across all three sinks:
ADD applies, DROP/MODIFY/RENAME log a warning and require operator
intervention via the snapshot trigger. Closes the silent data-loss window
where new source columns were dropped by Stream Load (StarRocks) or skipped
by the MERGE projection (Snowflake).
- **Shared `compute_schema_evolution_plan` module** at
`src/connectors/sinks/schema_evolution.rs` consumed by all three sinks. The
per-sink dialect-specific DDL lives in
`<sink>/schema_evolution.rs` modules.
- **`schema_evolution_skipped_total` metric** exposed at
`GET /api/v1/cdc/metrics`. Cumulative count of `SchemaChange` events the
sink could not auto-apply because the target table doesn't satisfy the
sink's prerequisite (StarRocks degraded mode). Non-zero values indicate
the daemon emitted `WARN: schema change skipped` log entries that the
operator should review.

### Changed

- **StarRocks sink: server version 3.2.0 is now a hard requirement.** The
daemon validates `current_version()` at setup and refuses to start against
older clusters. Older versions don't support `fast_schema_evolution`, which
is necessary for non-blocking ALTER application on the runtime path.
- **StarRocks sink: per-table `fast_schema_evolution=true` is recommended.**
Tables without the property continue to operate (degraded mode) but skip
schema evolution with a loud `WARN` per affected table at setup and per
skipped event at runtime. To enable schema evolution on an existing table,
recreate it via CTAS — the property is creation-only in StarRocks.
- **Snowflake sink: `ALTER TABLE` privilege on the target schema is now
required.** Implicitly validated at setup via the existing audit-column
ALTER. Runtime ALTER failures halt the pipeline with the Snowflake error
surfaced verbatim in `/api/v1/health` `error_detail`.
- **Snowflake sink: `source_schemas` is now shared between the writer and the
normalizer** via `Arc<RwLock<Vec<SourceTableSchema>>>`. After a successful
schema-evolution batch, the writer takes a write lock and updates the
schema; the normalizer takes a read lock at the start of each drain cycle
so the MERGE generator projects post-evolution columns. Replaces the
previous frozen snapshot captured at setup time.
- **`SinkResult` struct gained a `schema_evolution_skipped: u64` field.** The
pipeline aggregates per-batch skip counts into the global metric.

### Fixed

- **Silent data loss when a source table gained a new column mid-stream
(StarRocks and Snowflake sinks).** Previously, `CdcRecord::SchemaChange`
events fell into a no-op `match` arm in both sinks (commits `c131f0d7` for
StarRocks, `685edfa9` for Snowflake). New columns flowed through to the
data-write phase but were filtered silently by Stream Load
(`max_filter_ratio`) or skipped by the MERGE projection
(`_DATA:"col"::TYPE`). This was scoped out of the v1.7.0 PR
(`internal-docs/pg-sink-schema-evolution-solution.md` §3 Non-goals);
this change closes that deuda.

## [2.1.0] - 2026-04-23

### Changed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dbmazz"
version = "2.1.0"
version = "2.2.0"
edition = "2021"
license = "Elastic-2.0"
# Minimum Supported Rust Version.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ The CLI runs on Linux and macOS (`amd64` and `arm64`).

| Source | Sink | Status | Notes |
|---|---|:---:|---|
| PostgreSQL 12+ | **StarRocks** | ✅ Stable | JSON Stream Load, partial-update for TOAST columns, audit columns auto-managed |
| PostgreSQL 12+ | **StarRocks 3.2+** | ✅ Stable | JSON Stream Load, partial-update for TOAST columns, audit columns auto-managed, schema evolution requires per-table `fast_schema_evolution=true` |
| PostgreSQL 12+ | **PostgreSQL 15+** | ✅ Stable | Binary `COPY` → raw table → `MERGE` normalizer; supports hard delete |
| PostgreSQL 12+ | **Snowflake** | ✅ Stable | Parquet → PUT (stage) → `COPY INTO` → background `MERGE`; JWT key-pair auth supported |
| PostgreSQL 12+ | **Snowflake** | ✅ Stable | Parquet → PUT (stage) → `COPY INTO` → background `MERGE`; JWT key-pair auth supported; requires `ALTER TABLE` privilege on target schema |
| PostgreSQL 12+ | S3 / Iceberg | 🚧 Roadmap | Tracked in [issues](https://github.com/ez-cdc/dbmazz/issues) |
| MySQL | * | 🚧 Roadmap | The source layer is generic; PostgreSQL is the only implementation today |

Expand Down
47 changes: 47 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,53 @@ every option documented inline. The default location is
|---|---|---|
| `DBMAZZ_CONTROL_PORT` | `50051` | Port the internal HTTP control plane binds to (health, status, metrics, control). Formerly `GRPC_PORT`; the legacy name is still read for rolling compatibility. |

## Sink-specific requirements

Each sink has its own server-side prerequisites that the operator must satisfy
**before** starting dbmazz. The daemon validates these at setup time and fails
loud with an actionable error message if they are missing.

### StarRocks

| Requirement | Why | How to satisfy |
|---|---|---|
| Server version ≥ 3.2.0 | Older versions do not support `fast_schema_evolution`; runtime ALTER would be asynchronous and slow | Upgrade your StarRocks cluster |
| Target tables created by the operator | dbmazz does not create tables (different table types, distribution keys, partitions are operator decisions) | `CREATE TABLE ... PROPERTIES('fast_schema_evolution' = 'true')` ahead of time |
| Per-table `fast_schema_evolution=true` (recommended) | Without it, schema evolution operates in **degraded mode**: dbmazz arranca, logs a loud `WARN` per affected table, and skips ALTER for that table on every `SchemaChange` event. The daemon does not fail, but new columns added in source are NOT propagated. | At table creation: include `PROPERTIES('fast_schema_evolution' = 'true')`. The property is creation-only — to add it to an existing table, recreate via CTAS. |
| MySQL protocol port (default 9030) | DDL operations (audit columns, schema evolution) flow through the MySQL protocol | Open the port in your network |

### Snowflake

| Requirement | Why | How to satisfy |
|---|---|---|
| `ALTER TABLE` privilege on target schema | dbmazz applies `ALTER TABLE ADD COLUMN` for audit columns at setup and for new source columns at runtime | `GRANT ALTER ON ALL TABLES IN SCHEMA <db>.<schema> TO ROLE <role>` (or use a role with OWNERSHIP) |
| Warehouse + role + database configured via env vars | dbmazz uses these for COPY INTO / MERGE | See `SINK_SNOWFLAKE_*` env vars above |
| Target tables created by the operator | dbmazz does not create tables; CLUSTER BY, transient/permanent, and other Snowflake-specific decisions are operator-owned | `CREATE TABLE ...` ahead of time |
| Key-pair JWT auth (recommended over password) | Lower auth-related rotation overhead; `SINK_SNOWFLAKE_PRIVATE_KEY_PATH` env var | See [Snowflake key-pair auth docs](https://docs.snowflake.com/en/user-guide/key-pair-auth) |

### PostgreSQL (sink)

| Requirement | Why | How to satisfy |
|---|---|---|
| PostgreSQL 15+ | dbmazz uses `MERGE` (added in PG 15) | Upgrade |
| `CREATE` privilege on target database | dbmazz creates `_dbmazz` schema, raw table, metadata, schema-tracking, and target tables | `GRANT CREATE ON DATABASE <db> TO <role>` |
| (Existing PG sink behavior) target tables created by dbmazz | The PG sink **does** create target tables if they don't exist (legacy behavior; not symmetric with SR/SF) | No action needed |

## Observability

The HTTP control plane exposes runtime metrics at `GET /api/v1/cdc/metrics`. Notable counters:

| Field | Description |
|---|---|
| `events_per_second` | Throughput of CDC events processed in the last second. |
| `lag_bytes` | Difference between `current_lsn` and `confirmed_lsn` (PostgreSQL source). |
| `lag_events` | Pending events queued in the in-memory pipeline channel. |
| `replication_lag_ms` | End-to-end lag from source commit timestamp to sink ack. |
| `schema_evolution_skipped_total` | Cumulative count of `SchemaChange` events skipped because the target table doesn't satisfy the sink's schema-evolution prerequisite (e.g. StarRocks `fast_schema_evolution=true` not set). A non-zero value here means the daemon emitted a `WARN: schema change skipped` log somewhere — review the logs for the specific table/column. |
| `total_events_processed` | Cumulative event count since daemon start. |
| `total_batches_sent` | Cumulative batches flushed to sink. |
| `cpu_millicores` | Process CPU usage (1000 = 1 full core). |

## Logging

| Variable | Default | Description |
Expand Down
4 changes: 2 additions & 2 deletions src/connectors/sinks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
//! sink.write_batch(records).await?;
//! ```

pub(crate) mod schema_evolution;

#[cfg(feature = "sink-postgres")]
pub mod postgres;
#[cfg(feature = "sink-snowflake")]
Expand Down Expand Up @@ -124,8 +126,6 @@ mod tests {
#[cfg(feature = "sink-snowflake")]
#[test]
fn test_create_snowflake_sink() {
use serial_test::serial;

std::env::set_var("SINK_SNOWFLAKE_ACCOUNT", "test_account");
std::env::set_var("SINK_SNOWFLAKE_WAREHOUSE", "COMPUTE_WH");

Expand Down
7 changes: 2 additions & 5 deletions src/connectors/sinks/postgres/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,7 @@ impl Sink for PostgresSink {

async fn write_batch(&mut self, records: Vec<CdcRecord>) -> Result<SinkResult> {
if records.is_empty() {
return Ok(SinkResult {
records_written: 0,
bytes_written: 0,
last_position: None,
});
return Ok(SinkResult::default());
}

// Track last position for checkpoint
Expand Down Expand Up @@ -339,6 +335,7 @@ impl Sink for PostgresSink {
records_written,
bytes_written,
last_position,
schema_evolution_skipped: 0,
})
}

Expand Down
Loading