Skip to content

replication version preflight - #106

Merged
isdaniel merged 1 commit into
mainfrom
fix/replication-version-preflight
Jul 22, 2026
Merged

replication version preflight#106
isdaniel merged 1 commit into
mainfrom
fix/replication-version-preflight

Conversation

@isdaniel

@isdaniel isdaniel commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Refactor relation metadata handling to use a structured type for improved clarity and maintainability

Summary by CodeRabbit

  • New Features

    • Added PostgreSQL version preflight checks for replication slots, slot updates, slot inspection, and base backups.
    • Unsupported options now return clear errors before database commands are sent.
    • Added compatibility support for newer PostgreSQL features, including failover slots and incremental base backups.
  • Bug Fixes

    • Improved replication event handling for updates and deletes, including relation metadata and key-column decoding.
    • Strengthened integration coverage for logical replication workflows across PostgreSQL versions.

@codspeed-hq

codspeed-hq Bot commented Jul 21, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 50 untouched benchmarks


Comparing fix/replication-version-preflight (f924c43) with main (436f7f1)

Open in CodSpeed

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.69967% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.73%. Comparing base (436f7f1) to head (f924c43).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/connection/native/connection.rs 84.44% 7 Missing ⚠️
src/protocol.rs 95.94% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #106      +/-   ##
==========================================
+ Coverage   94.61%   94.73%   +0.11%     
==========================================
  Files          27       27              
  Lines       20417    20623     +206     
==========================================
+ Hits        19318    19537     +219     
+ Misses       1099     1086      -13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces client-side server-version preflight checks for replication SQL commands (such as creating, altering, and reading replication slots, as well as base backups) to prevent opaque server-side syntax errors on unsupported PostgreSQL versions. It also refactors the relation_metadata helper in the protocol module to return a structured RelationMetadata struct instead of a complex tuple, and adds a comprehensive integration test suite (version_preflight.rs) along with corresponding unit tests. I have no feedback to provide as there are no review comments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@isdaniel

Copy link
Copy Markdown
Owner Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces client-side server-version preflight checks for PostgreSQL replication commands (such as creating, altering, reading replication slots, and base backups) to catch unsupported options early with clear client-side errors. It also refactors relation_metadata to return a structured RelationMetadata instead of a tuple, and adds corresponding integration and unit tests. A critical issue was identified in the new integration tests where drop_slot attempts to execute a SELECT query on a replication connection, which will fail with a protocol error; using the native drop_replication_slot method is recommended instead.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread integration-tests/version_preflight.rs
@isdaniel
isdaniel force-pushed the fix/replication-version-preflight branch 2 times, most recently from d64fb17 to 76e49b4 Compare July 22, 2026 02:07
@isdaniel

Copy link
Copy Markdown
Owner Author

/gemini review

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e141f798-3315-4cd5-b98a-e72a9f88a3a1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
📝 Walkthrough

Walkthrough

Changes

The change adds PostgreSQL version preflight checks before replication SQL execution, wires them into both connection implementations, adds integration coverage for CDC and PG17+ slot operations, and restructures relation metadata decoding around a dedicated struct.

Replication preflight and validation

Layer / File(s) Summary
PostgreSQL version preflight rules
src/sql_builder.rs
Adds and tests version gates for replication slots, slot reads, and base backups, including PostgreSQL 15, 17, and 18 requirements.
Connection API preflight enforcement
src/connection/libpq.rs, src/connection/native/connection.rs
Both connection implementations validate server capabilities before generating or executing replication SQL.
End-to-end preflight integration validation
Cargo.toml, integration-tests/version_preflight.rs, .github/workflows/ci-checks.yml
Adds ignored PostgreSQL integration tests for CDC streaming and PG17+ slot operations, plus CI cleanup and test execution wiring.
Structured relation metadata decoding
src/protocol.rs, src/stream.rs
Replaces tuple-based relation metadata with RelationMetadata and updates update/delete decoding and related tests.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ReplicationConnection
  participant sql_builder
  participant PostgreSQL
  Client->>ReplicationConnection: invoke replication operation
  ReplicationConnection->>sql_builder: check server version and options
  sql_builder-->>ReplicationConnection: validation result
  ReplicationConnection->>PostgreSQL: execute supported replication SQL
Loading

Suggested reviewers: lucacappelletti94

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately captures the main addition of PostgreSQL replication version preflight checks.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/replication-version-preflight

Comment @coderabbitai help to get the list of available commands.

@isdaniel

Copy link
Copy Markdown
Owner Author

/gemini review

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@isdaniel

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds client-side PostgreSQL server-version “preflight” checks for replication-related SQL (slot create/alter/read and base backup) so unsupported options fail early with clear configuration errors, and refactors relation metadata handling to use a structured type to improve decode-path clarity.

Changes:

  • Introduces version-gated preflight helpers in sql_builder and wires them into both libpq and native connection backends before issuing SQL.
  • Refactors relation_metadata to return a RelationMetadata struct and updates decoding + tests accordingly.
  • Adds a new integration test (version_preflight) and runs it in CI; bumps a couple of Rust dependencies.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/stream.rs Updates tests to use the new structured relation metadata return type.
src/sql_builder.rs Adds server-version preflight checks for replication slot and base backup SQL.
src/protocol.rs Introduces RelationMetadata struct and updates message decoding + tests.
src/connection/native/connection.rs Calls preflight checks before issuing version-gated SQL commands.
src/connection/libpq.rs Calls preflight checks before issuing version-gated SQL commands.
integration-tests/version_preflight.rs Adds live-server integration coverage for preflight + a CDC smoke test.
Cargo.toml Adds the new integration test target and bumps dev/runtime deps.
Cargo.lock Updates lockfile for dependency bumps.
.github/workflows/ci-checks.yml Runs the new integration test in CI and adds slot cleanup before it.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/sql_builder.rs
Comment thread src/sql_builder.rs
@isdaniel

Copy link
Copy Markdown
Owner Author

@copilot review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/sql_builder.rs:481

  • There is a double space in this comment (“with its”), which looks like a typo and can hurt readability/searchability.
// The builders above are pure and hold no server-version state by design. The preflight below is the separate, equally-pure gate a *connection* applies (with  its known `server_version()`) before issuing a version-gated command, so an unsupported option fails with an actionable client-side error instead of an opaque server-side `syntax error`. Only the `libpq` / `rustls-tls` backends call these, so the whole group lives in a feature-gated module: the parser-only / no_std (`--no-default-features`) build compiles it out entirely — no callers, no `dead_code`, no per-item `allow`.

Copilot AI commented Jul 22, 2026

Copy link
Copy Markdown

@copilot review

Reviewed the PR changes. Two issues addressed in commit 7b2a22e:

  1. Double-space typo in the version_preflight module comment (with its knownwith its known).

  2. Slot-type-incompatible options silently ignoredbuild_create_slot_sql now returns a ReplicationError::config for slot-type mismatches that were previously silently dropped:

    • two_phase on a PHYSICAL slot → "two_phase is only supported for logical replication slots"
    • snapshot on a PHYSICAL slot → "snapshot is only supported for logical replication slots"
    • reserve_wal on a LOGICAL slot → "reserve_wal is only supported for physical replication slots"

    New test cases cover all three guards. The version-preflight function (check_create_slot_version) correctly skips physical slots since the builder now handles slot-type validation before any SQL is emitted.

…oved clarity and maintainability

Update dependencies: bump tokio to 1.53.1 and serde_json to 1.0.151
Add server-version preflight checks for replication slot operations and base backup options
Add preflight checks for replication slot and base backup options based on PostgreSQL version
@isdaniel
isdaniel force-pushed the fix/replication-version-preflight branch from 7b2a22e to f924c43 Compare July 22, 2026 04:40
@isdaniel
isdaniel merged commit 547b721 into main Jul 22, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants