Skip to content

Arbitrary improvements (take 2)#464

Open
danolivo wants to merge 5 commits into
mainfrom
arbitrary-improvements-take-2
Open

Arbitrary improvements (take 2)#464
danolivo wants to merge 5 commits into
mainfrom
arbitrary-improvements-take-2

Conversation

@danolivo
Copy link
Copy Markdown
Contributor

@danolivo danolivo commented May 8, 2026

Summary

A grab-bag of independent cleanups in contrib/spock. None of them change user-visible behaviour; each commit stands on its own and can be reviewed separately.

  • PG18 compatibility for --exclude-extension. The flag is new in Postgres 18, so its use is now gated behind a version check rather than relying on always-present API.
  • Drop Win32 support. Removes the Windows-only command exec, temp-path resolution, argument quoting, and associated typedefs. Spock has been POSIX-only in practice — the dead paths just complicated the build matrix and the typedef list.
  • spock_disable_subscription warning comment. Documents that the function's effect can be silently lost if the caller forgets to commit, which has caused coding errors before.
  • spock--6.0.0-devel.sql UI tidy-up. Regroups the head install script into feature sections and normalises every CREATE FUNCTION to a single multi-line shape, so the script reads as a user-facing API rather than insertion-order history. Upgrade scripts are untouched.

@danolivo danolivo self-assigned this May 8, 2026
@danolivo danolivo added the enhancement New feature or request label May 8, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

Removes Windows-specific header and exec code, consolidates Unix execution path, changes temp-directory discovery to TMPDIR with /tmp fallback, prunes Windows typedef entries, and expands the SQL migration with new catalogs, node/subscription APIs, sync controls, and apply/progress plumbing.

Changes

Windows Support Removal

Layer / File(s) Summary
Header and Exec Path
include/spock_sync.h, src/spock_sync.c
Removed QuoteWindowsArgv() declaration; <sys/wait.h> included unconditionally; removed Windows exec implementation and kept fork/execv/waitpid path.
Temp Directory Handling
src/spock.c
spock_temp_directory_assing_hook now uses TMPDIR with "/tmp" fallback; removed GetTempPath() branch.
Typedef Cleanup
utils/pgindent/typedefs.list
Removed Windows-related typedef/token entries used by pgindent.

SQL Extension API Reorganization

Layer / File(s) Summary
Catalog Schema Expansion
sql/spock--6.0.0-devel.sql
Adds catalog scaffolding and tables for replication-set metadata, sequence state, dependency, queue, PII, and resolutions.
Node & Subscription Declarations
sql/spock--6.0.0-devel.sql
Adds C-backed node-management and subscription-management declarations (node_create/drop, slot naming, sub_create/drop, helpers).
Subscription Sync & Helpers
sql/spock--6.0.0-devel.sql
Adds sub_alter_sync() and sub_resync_table() plus table sync helpers and replication-set operations.
Apply Progress & Utilities
sql/spock--6.0.0-devel.sql
Reorganizes apply progress views/functions, lag tracking, apply-worker polling, channel stats, and reintroduces spock.md5_agg and version helpers.

C Code Adjustments

Layer / File(s) Summary
Docs and Version Guards
src/spock_exception_handler.c, src/spock_failover_slots.c, src/spock_sync.c
Expanded spock_disable_subscription comment; conditional BackgroundWorker bgw for PG < 18; build_exclude_extension_string() and its dump_structure() usage wrapped with PG_VERSION_NUM >= 170000.

Poem

🐰 I nudged out Windows-specific lines,

Chose TMPDIR where sunlight shines,
SQL catalogs stretch and grow,
Sync and progress streams now flow,
A rabbit hops — the changes sow.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is vague and generic. 'Arbitrary improvements (take 2)' does not convey meaningful information about what was actually changed. Replace with a more specific title that summarizes the main changes, such as 'Drop Win32 support and add PG18 compatibility' or list the key improvements.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description is related to and accurately summarizes the changeset, covering the main improvements including Win32 support removal, PG18 compatibility, and SQL script tidying.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch arbitrary-improvements-take-2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 8, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 duplication

Metric Results
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/spock_sync.c (1)

156-174: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Lower version gate to PG17 — --exclude-extension ships in PG17, not PG18.

The --exclude-extension pg_dump option was introduced in PostgreSQL 17 (commit 522ed12f, March 2024), not PG18. As written, build_exclude_extension_string() is compiled out on PG17 builds, causing extensions in skip_extension[] to be silently dumped even though pg_dump 17 supports the flag.

Change PG_VERSION_NUM >= 180000 to PG_VERSION_NUM >= 170000 at:

  • Line 156 (function definition)
  • Line 239 (call site in dump_structure())
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/spock_sync.c` around lines 156 - 174, The build currently gates
build_exclude_extension_string() behind PG_VERSION_NUM >= 180000 but the
--exclude-extension option exists in PG17; change the preprocessor condition to
PG_VERSION_NUM >= 170000 in both the function definition around
build_exclude_extension_string and at its call site in dump_structure() so the
function is compiled and used for PG17+ builds; update the `#if/`#endif macro
checks referencing PG_VERSION_NUM accordingly.
🧹 Nitpick comments (1)
sql/spock--6.0.0-devel.sql (1)

743-751: 💤 Low value

Inconsistent CREATE OR REPLACE FUNCTION and stale upgrade-script comment.

Every other function declaration in this install script uses plain CREATE FUNCTION. CREATE OR REPLACE is a no-op in a fresh install (the function cannot pre-exist after \quit), and it cuts against this PR's stated goal of normalizing declarations to a uniform shape. The trailing -- Changed from int to bigint comment is also a leftover from an upgrade script and is meaningless in the head install file.

♻️ Proposed cleanup
-CREATE OR REPLACE FUNCTION spock.get_apply_worker_status(
-  OUT worker_pid    bigint, -- Changed from int to bigint
+CREATE FUNCTION spock.get_apply_worker_status(
+  OUT worker_pid    bigint,
   OUT worker_dboid  int,
   OUT worker_subid  bigint,
   OUT worker_status text
 )
 RETURNS SETOF record
 AS 'MODULE_PATHNAME', 'get_apply_worker_status'
 LANGUAGE C STABLE;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sql/spock--6.0.0-devel.sql` around lines 743 - 751, Replace the non-standard
declaration and stale comment for the function spock.get_apply_worker_status:
change the header from "CREATE OR REPLACE FUNCTION" to "CREATE FUNCTION" and
remove the trailing upgrade-script comment "-- Changed from int to bigint" (and
any similar leftover comments around the OUT parameter worker_pid) so the
declaration matches the other functions' plain CREATE FUNCTION form and contains
no stale upgrade notes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/spock_sync.c`:
- Around line 156-174: The build currently gates
build_exclude_extension_string() behind PG_VERSION_NUM >= 180000 but the
--exclude-extension option exists in PG17; change the preprocessor condition to
PG_VERSION_NUM >= 170000 in both the function definition around
build_exclude_extension_string and at its call site in dump_structure() so the
function is compiled and used for PG17+ builds; update the `#if/`#endif macro
checks referencing PG_VERSION_NUM accordingly.

---

Nitpick comments:
In `@sql/spock--6.0.0-devel.sql`:
- Around line 743-751: Replace the non-standard declaration and stale comment
for the function spock.get_apply_worker_status: change the header from "CREATE
OR REPLACE FUNCTION" to "CREATE FUNCTION" and remove the trailing upgrade-script
comment "-- Changed from int to bigint" (and any similar leftover comments
around the OUT parameter worker_pid) so the declaration matches the other
functions' plain CREATE FUNCTION form and contains no stale upgrade notes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7dfbb6d9-866e-4b79-a518-83cd1c9e8aea

📥 Commits

Reviewing files that changed from the base of the PR and between f0a3d64 and f883fab.

📒 Files selected for processing (7)
  • include/spock_sync.h
  • sql/spock--6.0.0-devel.sql
  • src/spock.c
  • src/spock_exception_handler.c
  • src/spock_failover_slots.c
  • src/spock_sync.c
  • utils/pgindent/typedefs.list
💤 Files with no reviewable changes (3)
  • include/spock_sync.h
  • src/spock.c
  • utils/pgindent/typedefs.list

Comment thread src/spock_sync.c Outdated
danolivo added 5 commits May 12, 2026 08:45
It is just the fact that --exclude-extension has been introduced in
Postgres 18.
Drop Win32-specific code paths including exec_cmd_win32(), GetTempPath()
temp directory resolution, Windows argument quoting, and related type
definitions. Spock targets POSIX-only environments.
It may be unclear to detect if someone forget to commit after the call of this
function wiping out the result. So, add a comment to reduce number of coding
errors.
Group the head install script by feature area and normalise function
signatures to a single style, so the script reads as a coherent
user-facing interface rather than the accumulated insertion-order
history it had become.

No functional changes; upgrade scripts untouched.
As mentioned in the review it is available since PostgreSQL 17.
@danolivo danolivo force-pushed the arbitrary-improvements-take-2 branch from f883fab to e44418a Compare May 12, 2026 07:09
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/spock_sync.c (1)

1461-1505: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Register slot cleanup before creating the slot.

If spock_create_slot_and_read_progress() throws after CREATE_REPLICATION_SLOT succeeds, this catch block only resumes apply workers. The cleanup callback is installed later, so the new remote slot can be left behind retaining WAL until another retry/manual cleanup. Either wrap this call in the existing PG_ENSURE_ERROR_CLEANUP(...) scope, or do a best-effort slot drop here before rethrowing.

Also applies to: 1513-1515

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/spock_sync.c` around lines 1461 - 1505, The call to
spock_create_slot_and_read_progress can create a replication slot before the
cleanup callback is registered, leaving the slot and WAL behind if an exception
is thrown; wrap the spock_create_slot_and_read_progress call in a
PG_ENSURE_ERROR_CLEANUP scope (or otherwise register the slot-drop cleanup
callback before calling it) so the cleanup is guaranteed on error, or
alternatively add a best-effort drop inside the PG_CATCH before PG_RE_THROW: use
origin_conn and sub->slot_name to drop the newly created slot (via the existing
slot-drop helper or a PQexec/pg_drop_replication_slot call) and clear any
PQresult, then continue with the current error flow.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sql/spock--6.0.0-devel.sql`:
- Line 663: Summary: Demote or remove noisy RAISE NOTICE tracing in the internal
helper so it doesn't surface on every sync run. Locate the RAISE NOTICE call
that emits "SPOCK cswp slot=% v_lsn=%" using the p_slot_name and v_lsn variables
(and the similar RAISE NOTICE calls in the same helper around the block at lines
709-715) and either change it to a lower-visibility level like RAISE DEBUG/LOG
or remove the statement entirely; ensure you apply the same change to the other
NOTICE lines in that helper for consistent behavior.

---

Outside diff comments:
In `@src/spock_sync.c`:
- Around line 1461-1505: The call to spock_create_slot_and_read_progress can
create a replication slot before the cleanup callback is registered, leaving the
slot and WAL behind if an exception is thrown; wrap the
spock_create_slot_and_read_progress call in a PG_ENSURE_ERROR_CLEANUP scope (or
otherwise register the slot-drop cleanup callback before calling it) so the
cleanup is guaranteed on error, or alternatively add a best-effort drop inside
the PG_CATCH before PG_RE_THROW: use origin_conn and sub->slot_name to drop the
newly created slot (via the existing slot-drop helper or a
PQexec/pg_drop_replication_slot call) and clear any PQresult, then continue with
the current error flow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c149bee6-1f5f-4e85-aaa8-13f55734b9a7

📥 Commits

Reviewing files that changed from the base of the PR and between f883fab and e44418a.

📒 Files selected for processing (7)
  • include/spock_sync.h
  • sql/spock--6.0.0-devel.sql
  • src/spock.c
  • src/spock_exception_handler.c
  • src/spock_failover_slots.c
  • src/spock_sync.c
  • utils/pgindent/typedefs.list
💤 Files with no reviewable changes (3)
  • src/spock.c
  • utils/pgindent/typedefs.list
  • include/spock_sync.h
✅ Files skipped from review due to trivial changes (1)
  • src/spock_exception_handler.c
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/spock_failover_slots.c


CREATE FUNCTION spock.sub_alter_sync(subscription_name name, truncate boolean DEFAULT false)
RETURNS boolean STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'spock_alter_subscription_synchronize';
RAISE NOTICE 'SPOCK cswp slot=% v_lsn=%', p_slot_name, v_lsn;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Drop the NOTICE-level tracing from this internal helper.

These RAISE NOTICE calls will surface on every sync run, so this turns an internal helper into user-visible log/client noise. Please demote them to DEBUG/LOG or remove them before merge.

Also applies to: 709-715

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sql/spock--6.0.0-devel.sql` at line 663, Summary: Demote or remove noisy
RAISE NOTICE tracing in the internal helper so it doesn't surface on every sync
run. Locate the RAISE NOTICE call that emits "SPOCK cswp slot=% v_lsn=%" using
the p_slot_name and v_lsn variables (and the similar RAISE NOTICE calls in the
same helper around the block at lines 709-715) and either change it to a
lower-visibility level like RAISE DEBUG/LOG or remove the statement entirely;
ensure you apply the same change to the other NOTICE lines in that helper for
consistent behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants