ivy_moonlink Technical Design

ivy_moonlink is the Rust engine that synchronizes data and maintains columnstore mirrors for real-time analytics in IvorySQL 6.0. It tracks source tables through an initial copy and WAL-based logical replication, applies committed changes to each mirror, and persists mirror data in Apache Iceberg snapshots. See the ivy_moonlink source repository.

1. Processes and module responsibilities

In a standard IvorySQL deployment, preloading pg_mooncake registers a background worker named moonlink. At startup, the worker restores registered mirrors and listens on moonlink.sock under mooncake.data_directory. pg_mooncake sends mirror management requests over this Unix socket. The DuckDB scan extension uses the same interface to get the schema and scan state. A separate logical replication connection receives changes from the source.

Rust module Responsibility

moonlink_connectors

Uses COPY for the initial copy and receives logical replication messages through pgoutput. It decodes source column types and row values and dispatches changes by source table.

moonlink

Maintains transaction changes, Arrow column batches, and row location indexes for each mirror. It prepares scan state, writes Parquet, and commits Iceberg snapshots.

moonlink_backend

Coordinates mirror registration, recovery, and reads, and tracks replication, commit, and persistence progress for each mirror.

moonlink_service and moonlink_rpc

Provide the Unix socket service and request protocol for mirror management and scans.

2. Initial copy and incremental replication

The initial copy uses a consistent source snapshot and its associated WAL position (LSN). Moonlink can split the table into ranges so multiple COPY connections import the same snapshot and read in parallel. The snapshot’s LSN marks where incremental replay picks up, avoiding duplicate application of changes included in the initial copy.

During incremental replication, the replication connection sends row changes to the corresponding mirror. The source transaction’s commit message marks when its changes can become visible. Moonlink can process a large streamed transaction in batches, with its changes becoming queryable after the whole transaction commits. If the source transaction aborts, those changes never become visible.

3. Columnstore persistence and Iceberg snapshots

Moonlink organizes row changes into Arrow column batches. When it applies an update or delete, it uses the old row to locate the file or batch and row position, then records a deletion marker. An update also writes a new row version.

Background persistence writes batches of changes to Parquet data files with the corresponding deletion information, then commits Iceberg metadata that references those files. External engines read the snapshot described by the committed metadata. Between Iceberg commits, Moonlink can keep applying source transactions and materialize the applied changes in temporary Parquet for mirror scans. DuckDB can read both the persisted files and that newer data, so mirror queries and external Iceberg reads may see different progress. See the ivy_mooncake technical design for the scan protocol.

4. Replication progress and restart recovery

commit_lsn indicates how far a mirror has applied committed changes, and flush_lsn indicates how far it has persisted them to Iceberg. For healthy mirrors that share a replication stream, the slowest persistence position determines the confirmed_flush_lsn that Moonlink acknowledges to the source. This lets the source retain WAL needed for recovery.

On restart, Moonlink restores mirror state from its registry and the latest Iceberg snapshot for each mirror, then resumes replay from the logical replication slot. Use mooncake.bgworker_status() to check whether the worker is listening and mooncake.list_tables() to inspect each mirror’s commit and persistence progress. See the ivy_mooncake user guide for installation and examples.