Skip to content
Open
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
88 changes: 83 additions & 5 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ default = ["sink-starrocks", "sink-postgres", "sink-snowflake"]
sink-starrocks = ["dep:curl", "dep:mysql_async", "dep:openssl-sys"]
# --- Optional: MySQL source ---
mysql-source = ["dep:mysql_async", "dep:mysql_common", "mysql_async?/binlog"]
# --- Optional: Oracle sink ---
oracle-sink = ["dep:oracle"]
sink-postgres = []
sink-snowflake = [
"dep:reqwest", "dep:arrow", "dep:parquet",
Expand Down Expand Up @@ -75,6 +77,9 @@ uuid = { version = "1", features = ["v4"], optional = true }
# --- Optional: MySQL source ---
mysql_common = { version = "=0.32.4", features = ["binlog"], optional = true }

# --- Optional: Oracle sink ---
oracle = { version = "0.6", features = ["chrono"], optional = true }

[dev-dependencies]
serial_test = "3.0"
mysql_async = "0.34"
Expand Down
80 changes: 80 additions & 0 deletions Dockerfile.oracle
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# syntax=docker/dockerfile:1.6
#
# Multi-stage build for dbmazz with oracle-sink feature.
#
# This Dockerfile compiles dbmazz with the oracle-sink feature and includes
# Oracle Instant Client in the runtime stage for libclntsh.so (needed by
# the oracle crate at runtime via dlopen).
#
# Usage:
# docker build -t dbmazz-oracle:dev -f Dockerfile.oracle .
#
# For multi-arch builds (slower — QEMU emulates the Rust compiler):
# docker buildx build --platform linux/amd64,linux/arm64 \
# -t dbmazz-oracle:dev -f Dockerfile.oracle .
#
# Security: runs as non-root user (uid 65532), HEALTHCHECK configured.
# Binary: dynamically linked against glibc (debian:bookworm-slim).

FROM rust:bookworm AS builder
WORKDIR /app

# ---- Layer 0: system dependencies for compilation ----
RUN apt-get update && apt-get install -y --no-install-recommends \
libssl-dev unzip curl ca-certificates && \
rm -rf /var/lib/apt/lists/*

# ---- Layer 1: fetch dependencies (cached unless Cargo.toml/lock changes) ----
COPY Cargo.toml Cargo.lock ./
RUN mkdir -p src && touch src/lib.rs
RUN cargo fetch --locked

# ---- Layer 2: real source + real build ----
COPY src/ src/
RUN cargo build --release --features oracle-sink --locked

# ====================================================================
# Runtime stage
# ====================================================================
FROM debian:bookworm-slim

# Install runtime deps: ca-certificates, curl (healthcheck), libaio1 (OCI)
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates curl libaio1 unzip \
&& rm -rf /var/lib/apt/lists/* \
&& useradd --system --no-create-home --uid 65532 dbmazz

# Download and install Oracle Instant Client Basic Light (provides libclntsh.so)
# Multi-arch: detects arm64 vs x86_64 at build time with uname -m
# Docs: https://www.oracle.com/database/technologies/instant-client.html
RUN arch=$(uname -m); \
case "$arch" in \
aarch64|arm64) \
url="https://download.oracle.com/otn_software/linux/instantclient/2326200/instantclient-basiclite-linux.arm64-23.26.2.0.0.zip"; \
dir="instantclient_23_26" ;; \
*) \
url="https://download.oracle.com/otn_software/linux/instantclient/2326200/instantclient-basiclite-linux.x64-23.26.2.0.0dbru.zip"; \
dir="instantclient_23_26" ;; \
esac; \
echo "Downloading Oracle Instant Client for $arch from $url"; \
curl -fsSL "$url" -o /tmp/ic.zip \
&& unzip -q /tmp/ic.zip -d /opt/oracle \
&& rm /tmp/ic.zip \
&& ln -s "/opt/oracle/${dir}" /opt/oracle/instantclient \
&& echo "/opt/oracle/instantclient" > /etc/ld.so.conf.d/oracle-instantclient.conf \
&& ldconfig

# Copy the compiled binary from builder
COPY --from=builder /app/target/release/dbmazz /usr/local/bin/dbmazz

ENV LD_LIBRARY_PATH=/opt/oracle/instantclient:${LD_LIBRARY_PATH}

USER dbmazz

EXPOSE 50051

HEALTHCHECK --interval=10s --timeout=3s --start-period=30s --retries=3 \
CMD curl -sf http://127.0.0.1:50051/api/v1/health || exit 1

ENTRYPOINT ["/usr/local/bin/dbmazz"]
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Full Docker reference (env vars, healthcheck, persisting state, build-from-sourc
| 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; requires `ALTER TABLE` privilege on target schema |
| PostgreSQL 12+ | **Oracle 12c+** | ✅ Stable | Direct MERGE (upsert) to Oracle tables via `oracle` crate (kubo/rust-oracle). See [`src/connectors/sinks/oracle/README.md`](src/connectors/sinks/oracle/README.md). |
| PostgreSQL 12+ | S3 / Iceberg | 🚧 Roadmap | Tracked in [issues](https://github.com/ez-cdc/dbmazz/issues) |
| MySQL 5.7+ / 8.0+ | All sinks | 🧪 Beta | Binlog-based with GTID-aware checkpointing. See [`docs/mysql-source.md`](docs/mysql-source.md). |

Expand All @@ -135,9 +136,10 @@ Adding a new sink is intentionally small: implement a 6-method `Sink` trait and
PostgreSQL (source) dbmazz Sink (target)
┌──────────────┐ ┌────────────────────┐ ┌──────────────┐
│ WAL │ logical │ WAL Handler │ │ StarRocks │
│ (INSERT, │ replication │ │ │ │ PostgreSQL │
│ UPDATE, │ ────────────▶ │ ▼ │ │ Snowflake │
│ DELETE) │ (pgoutput) │ source/converter │ │ │
│ (INSERT, │ replication │ │ │ │ Oracle │
│ UPDATE, │ ────────────▶ │ ▼ │ │ PostgreSQL │
│ DELETE) │ (pgoutput) │ source/converter │ │ Snowflake │
│ │ │ │ │ │ │
│ │ │ │ │ │ │
│ │ │ ▼ │ │ │
│ │ │ Pipeline │ write │ │
Expand Down
7 changes: 7 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ src/
│ │ ├── merge_generator.rs Dynamic MERGE SQL generation
│ │ ├── setup.rs DDL: raw table, metadata, target tables
│ │ └── types.rs PG → PG type mapping
│ ├── oracle/ Oracle sink
│ │ ├── mod.rs OracleSink (MERGE via kubo/rust-oracle)
│ │ ├── merge_generator.rs MERGE SQL generation (Oracle dialect)
│ │ ├── schema_tracking.rs Schema state cache
│ │ ├── setup.rs DDL: metadata table, target tables
│ │ ├── types.rs DataType → Oracle type mapping
│ │ └── README.md Connector documentation
│ └── snowflake/ Snowflake sink
│ ├── mod.rs SnowflakeSink (Parquet → PUT → COPY INTO → MERGE)
│ ├── client.rs HTTP client (password + JWT auth, SQL execution)
Expand Down
14 changes: 11 additions & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ every option documented inline. The default location is

| Variable | Default | Description |
|---|---|---|
| `SINK_TYPE` | `starrocks` | Sink connector type: `starrocks`, `postgres`, or `snowflake`. |
| `SINK_URL` | — | Sink connection URL. For StarRocks: `http://host:8030` (FE HTTP). For PostgreSQL: `postgres://...`. For Snowflake: ignored (use `SINK_SNOWFLAKE_ACCOUNT`). |
| `SINK_TYPE` | `starrocks` | Sink connector type: `starrocks`, `postgres`, `snowflake`, or `oracle`. |
| `SINK_URL` | — | Sink connection URL. For StarRocks: `http://host:8030` (FE HTTP). For PostgreSQL: `postgres://...`. For Oracle: `//host:1521/service_name`. For Snowflake: ignored (use `SINK_SNOWFLAKE_ACCOUNT`). |
| `SINK_PORT` | `9030` | Additional port when needed (e.g., StarRocks MySQL protocol port for DDL). |
| `SINK_DATABASE` | — (required) | Target database name. |
| `SINK_SCHEMA` | `public` | Target schema (PostgreSQL) or `PUBLIC` (Snowflake). StarRocks does not use this. |
| `SINK_SCHEMA` | `public` | Target schema (PostgreSQL) or database (Oracle) or `PUBLIC` (Snowflake). StarRocks does not use this. |
| `SINK_USER` | `root` | Authentication username. |
| `SINK_PASSWORD` | *(empty)* | Authentication password. |

Expand Down Expand Up @@ -90,6 +90,14 @@ loud with an actionable error message if they are missing.
| 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) |

### Oracle (sink)

| Requirement | Why | How to satisfy |
|---|---|---|
| Oracle Instant Client (Basic Light) at runtime | The `oracle` (kubo/rust-oracle) crate wraps ODPI-C, which loads `libclntsh.so` via `dlopen` | Use the `dbmazz-oracle` Docker image (bundles Instant Client). On bare metal, install Oracle Instant Client and set `LD_LIBRARY_PATH`. |
| Target schema must exist | The sink creates tables within the target schema but does not create the schema | `CREATE USER <schema> IDENTIFIED BY <password>; GRANT CONNECT, RESOURCE TO <schema>;` |
| Oracle tables created by dbmazz | The Oracle sink **does** create target tables if they don't exist (mirroring source schemas with Oracle-compatible column types) | No action needed — the sink handles DDL automatically during `setup()` |

### PostgreSQL (sink)

| Requirement | Why | How to satisfy |
Expand Down
Loading
Loading