Skip to content

Arbitrary improvements (take 2)#464

Open
danolivo wants to merge 4 commits intomainfrom
arbitrary-improvements-take-2
Open

Arbitrary improvements (take 2)#464
danolivo wants to merge 4 commits intomainfrom
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 added 4 commits May 8, 2026 10:57
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.
@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

This PR removes Windows platform support and reorganizes the Spock extension SQL API. Changes eliminate Windows-specific headers, exec implementations, and temp directory handling across C code; remove Windows typedef entries; and substantially expand the SQL migration with new catalog tables, subscription/replication management functions, apply progress tracking, and sync event handling.

Changes

Windows Support Removal

Layer / File(s) Summary
Header and Include Changes
include/spock_sync.h, src/spock_sync.c
QuoteWindowsArgv() declaration removed from header; <sys/wait.h> included unconditionally instead of guarded by WIN32.
Windows Execution Removal
src/spock_sync.c
exec_cmd_win32() implementation and command-line quoting utilities deleted; exec_cmd() simplified to use only fork/exec/waitpid path.
Temp Directory Handling
src/spock.c
Platform-specific GetTempPath() code path removed; function now always uses TMPDIR environment variable with "/tmp" fallback.
Typedef Cleanup
utils/pgindent/typedefs.list
Windows-related typedef entries (BY_HANDLE_FILE_INFORMATION, DWORD, LPVOID, SC_HANDLE, SERVICE_STATUS_HANDLE, win32_deadchild_waitinfo) removed from formatter configuration.

SQL Extension API Reorganization

Layer / File(s) Summary
Catalog Schema Expansion
sql/spock--6.0.0-devel.sql
Adds comprehensive catalog tables for replication-set metadata, sequence tracking, dependency bookkeeping, queue state, PIIs, and conflict resolution.
Node Management
sql/spock--6.0.0-devel.sql
Introduces node creation, deletion, interface management, and node info functions; adds get_country() SQL helper.
Subscription Management
sql/spock--6.0.0-devel.sql
Adds functions for subscription creation/alteration, sync control, table resynchronization, and status inspection; includes sub_alter_sync(), sub_resync_table(), sub_show_table(), sub_wait_for_sync(), table_wait_for_sync().
Replication Set and DDL
sql/spock--6.0.0-devel.sql
Introduces sequence sync helper; adds replication-set management (create/alter/drop, table/sequence operations, partitions). Defines DDL replication entrypoints for single and batched commands.
Apply Progress Tracking
sql/spock--6.0.0-devel.sql
Re-defines apply progress views and per-peer progress function; introduces spock.lag_tracker view with lag metrics and apply-worker status polling helpers.
Channel Statistics
sql/spock--6.0.0-devel.sql
Adds channel statistics functions and derived views for per-table and summary statistics.
Sync Event Handling
sql/spock--6.0.0-devel.sql
Introduces sync_event primitive; changes spock.wait_for_sync_event() signature from origin_id oid to origin name with internal node resolution.
Apply Control and Conflict Resolution
sql/spock--6.0.0-devel.sql
Adds apply-control helpers and conflict/exception support functions (cleanup, stats, reset, commit-timestamp/LSN helpers, repair-mode).
Delta Apply Function
sql/spock--6.0.0-devel.sql
Adds overloaded spock.delta_apply(regclass, name, boolean) that manages security labels on columns and adjusts replica identity based on label presence.

C Code Adjustments

Layer / File(s) Summary
Documentation and Version Guards
src/spock_exception_handler.c, src/spock_failover_slots.c, src/spock_sync.c
Exception handler documentation expanded on transaction semantics; BackgroundWorker variable in failover slots conditionally declared for PostgreSQL < 18; build_exclude_extension_string() wrapped in version guard for PostgreSQL >= 18.

Poem

🐰 Windows support cast away,
Unix paths now reign and sway,
Spock's SQL grows strong and bright,
Subscriptions, sync, and progress light!
Code springs clean with every bound. 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Arbitrary improvements (take 2)' is vague and uses generic language that does not clearly convey the specific changes made in the pull request. Use a more descriptive title that captures the primary improvements, such as 'Drop Win32 support and add PG18 compatibility improvements' or 'Remove Windows-specific code and improve PostgreSQL 18 compatibility.'
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly relates to the changeset by explaining each type of change, including Win32 removal, PG18 compatibility, documentation updates, and SQL reorganization.
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.

✏️ 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
* So, don't care about duplicates.
*/

#if PG_VERSION_NUM >= 180000
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I hadn't noticed --exclude-extension before, but it looks like it got added in Postgres 17.

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