Skip to content

Add spock.log_verbosity and spock.apply_change_logging GUCs#477

Open
ibrarahmad wants to merge 2 commits into
mainfrom
SPOC-551
Open

Add spock.log_verbosity and spock.apply_change_logging GUCs#477
ibrarahmad wants to merge 2 commits into
mainfrom
SPOC-551

Conversation

@ibrarahmad
Copy link
Copy Markdown
Contributor

@ibrarahmad ibrarahmad commented May 20, 2026

log_verbosity (normal|verbose) promotes spock DEBUG1/DEBUG2 to LOG. apply_change_logging (none|key_only|verbose) emits per-change JSON from the apply worker: action/schema/table/pk/origin/commit_ts in key_only, plus old/new row data in verbose. DDL is logged in both non-none modes. Both GUCs are PGC_SUSET (SET / SIGHUP reload).

TAP coverage in tests/tap/t/044_apply_change_logging.pl - 24/24.

SPOC-551

log_verbosity (normal|verbose) promotes spock DEBUG1/DEBUG2 to LOG.
apply_change_logging (none|key_only|verbose) emits per-change JSON
from the apply worker: action/schema/table/pk/origin/commit_ts in
key_only, plus old/new row data in verbose.  DDL is logged in both
non-none modes.  Both GUCs are PGC_SUSET (SET / SIGHUP reload).

TAP coverage in tests/tap/t/044_apply_change_logging.pl - 24/24.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

Adds two GUCs and debug-routing macros, implements JSON serialization and public logging APIs, emits structured change logs before apply/DDL execution, updates debug sites and sync exec_cmd code, and adds TAP tests validating logging behavior.

Changes

Spock Apply Worker Change Logging

Layer / File(s) Summary
Log Configuration and Debug Routing Foundation
include/spock.h, src/spock.c
Declares spock_log_verbosity and spock_apply_change_logging GUCs, defines SpockLogVerbosity and SpockApplyChangeLogging enums, introduces SPOCK_DEBUG1/SPOCK_DEBUG2 macros that conditionally promote debug messages based on verbosity, and registers both GUCs during module initialization.
Change Log API and Implementation
include/spock_change_log.h, src/spock_change_log.c
Exposes spock_log_apply_change() and spock_log_apply_ddl() via a forward-declared header and implements JSON serialization helpers (append_json_value, append_row_json, append_change_log_header) plus the two logging functions that emit LOG-level JSON records with header, pk, and optional old/new payloads.
Apply Worker Integration
src/spock_apply.c
Includes spock_change_log.h and emits change logs before performing row-level DML in handle_insert/handle_update/handle_delete and before executing queued SQL/DDL in handle_sql, passing relation, tuple pointers (or NULL), and origin name.
Debug Routing and Common Code Updates
src/spock_common.c, src/spock_dependency.c
Switches selected debug ereport sites to use SPOCK_DEBUG1/SPOCK_DEBUG2 and adds the spock.h include where required so debug routing honors spock_log_verbosity.
Sync exec_cmd / WIN32 Adjustments
src/spock_sync.c
Reorganizes WIN32/non-WIN32 exec_cmd dispatch, unconditionally includes <sys/wait.h>, adjusts PG_VERSION_NUM guards for extension-exclusion logic, and updates guarded code regions.
End-to-End Test Coverage
tests/tap/schedule, tests/tap/t/044_apply_change_logging.pl
Adds scheduled TAP test 044_apply_change_logging and a test script that verifies the two GUCs, toggles spock.apply_change_logging, replicates INSERT/UPDATE/DDL, asserts expected spock apply change JSON records in key-only/verbose modes, and confirms none disables logging.

Poem

🐇 I nibble logs in tidy JSON rows,
verbosity set high, the garden grows.
Before each apply I hop and write,
PKs and rows in lantern-light.
Hooray — change logs sparkle through the night!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 68.75% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly matches the main change in the PR: adding two new spock GUCs (spock.log_verbosity and spock.apply_change_logging).
Description check ✅ Passed The description is directly related to the changeset, detailing the new GUCs' behavior, their configuration levels, and test coverage.
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 SPOC-551

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Infer (1.2.0)
src/spock_change_log.c

src/spock_change_log.c:16:10: fatal error: 'postgres.h' file not found
16 | #include "postgres.h"
| ^~~~~~~~~~~~
1 error generated.
Error: the following clang command did not run successfully:
/opt/infer-linux-x86_64-v1.2.0/lib/infer/facebook-clang-plugins/clang/install/bin/clang-18
@/tmp/coderabbit-infer/66ba3cd1a8ab84e6b4b5b1d0fcba49e34f34d31c-046ce4fe6d5140e3/tmp/clang_command_.tmp.3dd993.txt
++Contents of '/tmp/coderabbit-infer/66ba3cd1a8ab84e6b4b5b1d0fcba49e34f34d31c-046ce4fe6d5140e3/tmp/clang_command_.tmp.3dd993.txt':
"-cc1" "-load"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../../facebook-clang-plugins/libtooling/build/FacebookClangPlugin.dylib"
"-add-plugin" "BiniouASTExporter" "-plugin-arg-BiniouASTExporter" "-"
"-plugin-arg-BiniouASTExporter" "PREPEND_CURRENT_DIR=1"
"-plugin-arg-BiniouASTExporter" "MAX_STRING_SIZE=65535" "-cc1" "-triple"
"x86_64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free"
"-clea

... [truncated 698 characters] ...

/infer-linux-x86_64-v1.2.0/lib/infer/facebook-clang-plugins/clang/install/lib/clang/18/include"
"-internal-isystem" "/usr/local/include" "-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
"-internal-externc-isystem" "/usr/include/x86_64-linux-gnu"
"-internal-externc-isystem" "/include" "-internal-externc-isystem"
"/usr/include" "-Wno-ignored-optimization-argument" "-Wno-everything"
"-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf"
"-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o"
"/tmp/coderabbit-infer/046ce4fe6d5140e3/file.o" "-x" "c"
"src/spock_change_log.c" "-O0" "-fno-builtin" "-include"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../lib/clang_wrappers/global_defines.h"
"-Wno-everything"

src/spock_apply.c

src/spock_apply.c:12:10: fatal error: 'postgres.h' file not found
12 | #include "postgres.h"
| ^~~~~~~~~~~~
1 error generated.
Error: the following clang command did not run successfully:
/opt/infer-linux-x86_64-v1.2.0/lib/infer/facebook-clang-plugins/clang/install/bin/clang-18
@/tmp/coderabbit-infer/66ba3cd1a8ab84e6b4b5b1d0fcba49e34f34d31c-f72196100ba30b8c/tmp/clang_command_.tmp.c69a95.txt
++Contents of '/tmp/coderabbit-infer/66ba3cd1a8ab84e6b4b5b1d0fcba49e34f34d31c-f72196100ba30b8c/tmp/clang_command_.tmp.c69a95.txt':
"-cc1" "-load"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../../facebook-clang-plugins/libtooling/build/FacebookClangPlugin.dylib"
"-add-plugin" "BiniouASTExporter" "-plugin-arg-BiniouASTExporter" "-"
"-plugin-arg-BiniouASTExporter" "PREPEND_CURRENT_DIR=1"
"-plugin-arg-BiniouASTExporter" "MAX_STRING_SIZE=65535" "-cc1" "-triple"
"x86_64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free"
"-clear-ast

... [truncated 683 characters] ...

"/opt/infer-linux-x86_64-v1.2.0/lib/infer/facebook-clang-plugins/clang/install/lib/clang/18/include"
"-internal-isystem" "/usr/local/include" "-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
"-internal-externc-isystem" "/usr/include/x86_64-linux-gnu"
"-internal-externc-isystem" "/include" "-internal-externc-isystem"
"/usr/include" "-Wno-ignored-optimization-argument" "-Wno-everything"
"-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf"
"-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o"
"/tmp/coderabbit-infer/f72196100ba30b8c/file.o" "-x" "c"
"src/spock_apply.c" "-O0" "-fno-builtin" "-include"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../lib/clang_wrappers/global_defines.h"
"-Wno-everything"

src/spock_sync.c

src/spock_sync.c:13:10: fatal error: 'postgres.h' file not found
13 | #include "postgres.h"
| ^~~~~~~~~~~~
1 error generated.
Error: the following clang command did not run successfully:
/opt/infer-linux-x86_64-v1.2.0/lib/infer/facebook-clang-plugins/clang/install/bin/clang-18
@/tmp/coderabbit-infer/66ba3cd1a8ab84e6b4b5b1d0fcba49e34f34d31c-a6c6b1e749970934/tmp/clang_command_.tmp.4bae89.txt
++Contents of '/tmp/coderabbit-infer/66ba3cd1a8ab84e6b4b5b1d0fcba49e34f34d31c-a6c6b1e749970934/tmp/clang_command_.tmp.4bae89.txt':
"-cc1" "-load"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../../facebook-clang-plugins/libtooling/build/FacebookClangPlugin.dylib"
"-add-plugin" "BiniouASTExporter" "-plugin-arg-BiniouASTExporter" "-"
"-plugin-arg-BiniouASTExporter" "PREPEND_CURRENT_DIR=1"
"-plugin-arg-BiniouASTExporter" "MAX_STRING_SIZE=65535" "-cc1" "-triple"
"x86_64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free"
"-clear-ast-

... [truncated 680 characters] ...

"/opt/infer-linux-x86_64-v1.2.0/lib/infer/facebook-clang-plugins/clang/install/lib/clang/18/include"
"-internal-isystem" "/usr/local/include" "-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
"-internal-externc-isystem" "/usr/include/x86_64-linux-gnu"
"-internal-externc-isystem" "/include" "-internal-externc-isystem"
"/usr/include" "-Wno-ignored-optimization-argument" "-Wno-everything"
"-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf"
"-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o"
"/tmp/coderabbit-infer/a6c6b1e749970934/file.o" "-x" "c"
"src/spock_sync.c" "-O0" "-fno-builtin" "-include"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../lib/clang_wrappers/global_defines.h"
"-Wno-everything"


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 20, 2026

Up to standards ✅

🟢 Issues 1 medium

Results:
1 new issue

Category Results
Complexity 1 medium

View in Codacy

🟢 Metrics 31 complexity · 0 duplication

Metric Results
Complexity 31
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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/tap/t/044_apply_change_logging.pl (1)

20-30: ⚡ Quick win

Add a test case for skipped DML in TRANSDISCARD/SUB_DISABLE modes.

Current coverage is strong for normal apply flow, but it doesn’t assert that skipped DML in exception replay modes does not emit apply-change records. Adding this would close a high-risk gap in logging correctness.

🤖 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 `@tests/tap/t/044_apply_change_logging.pl` around lines 20 - 30, Add a new test
in the same TAP file that verifies skipped DML under the TRANSDISCARD and
SUB_DISABLE replay modes does not emit apply-change JSON log records: set
apply_change_logging to key_only (and repeat for verbose), configure
publisher/subscriber, perform DML on the publisher that will be skipped on the
subscriber by triggering TRANSDISCARD and SUB_DISABLE replay behavior, capture
the subscriber server logs (same log-capture helpers used elsewhere in this test
file), and assert that no apply-change JSON lines (those containing
action/schema/table/pk and, for verbose, new row data) are present for the
skipped DML; name the test case clearly (e.g., "skipped DML in
TRANSDISCARD/SUB_DISABLE produces no apply_change_logging records") so it’s easy
to find.
🤖 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 `@src/spock_apply.c`:
- Around line 1414-1416: The apply-change log is emitted even when DML was
intentionally skipped under exception-replay modes TRANSDISCARD/SUB_DISABLE;
update the three spots that call spock_log_apply_change (the INSERT block with
newtup, the UPDATE block with oldtup/newtup, and the DELETE block with oldtup)
to only call spock_log_apply_change when the operation both did not fail and was
actually applied — i.e., change the guard from if (!failed) to if (!failed &&
!<skip-dml-flag>), where <skip-dml-flag> checks the current exception replay
mode (TRANSDISCARD or SUB_DISABLE) or otherwise detects that DML was skipped;
use the existing symbols for those modes so the check reflects the code’s
exception replay state and ensures no “applied change” log is produced for
skipped operations.

---

Nitpick comments:
In `@tests/tap/t/044_apply_change_logging.pl`:
- Around line 20-30: Add a new test in the same TAP file that verifies skipped
DML under the TRANSDISCARD and SUB_DISABLE replay modes does not emit
apply-change JSON log records: set apply_change_logging to key_only (and repeat
for verbose), configure publisher/subscriber, perform DML on the publisher that
will be skipped on the subscriber by triggering TRANSDISCARD and SUB_DISABLE
replay behavior, capture the subscriber server logs (same log-capture helpers
used elsewhere in this test file), and assert that no apply-change JSON lines
(those containing action/schema/table/pk and, for verbose, new row data) are
present for the skipped DML; name the test case clearly (e.g., "skipped DML in
TRANSDISCARD/SUB_DISABLE produces no apply_change_logging records") so it’s easy
to find.
🪄 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: ebbbe842-5466-4b4d-86ca-e2caf912cda8

📥 Commits

Reviewing files that changed from the base of the PR and between 3886058 and 771775f.

📒 Files selected for processing (10)
  • include/spock.h
  • include/spock_change_log.h
  • src/spock.c
  • src/spock_apply.c
  • src/spock_change_log.c
  • src/spock_common.c
  • src/spock_dependency.c
  • src/spock_sync.c
  • tests/tap/schedule
  • tests/tap/t/044_apply_change_logging.pl

Comment thread src/spock_apply.c Outdated
Comment thread src/spock.c
Comment thread src/spock_apply.c Outdated
Comment thread src/spock_change_log.c Outdated
@mason-sharp mason-sharp changed the title SPOC-551: add spock.log_verbosity and spock.apply_change_logging GUCs Add spock.log_verbosity and spock.apply_change_logging GUCs May 24, 2026
Comment thread src/spock_change_log.c Outdated
Comment thread src/spock_apply.c Outdated
Comment thread src/spock.c
@danolivo danolivo added the skip-test-nightly Skip this PR in the nightly TAP workflow label May 25, 2026
Move spock_log_apply_change() for INSERT/UPDATE/DELETE ahead of the
apply attempt and drop the !failed guard, so every IUD that reaches
the apply path is logged regardless of success, failure, or skip
under TRANSDISCARD/SUB_DISABLE; replace the local append_json_string
helper with PostgreSQL's escape_json from utils/json.h.  Resolve
conflicts in src/spock_sync.c and tests/tap/schedule against main,
and fix the test's log-path lookup to honour TESTLOGDIR.
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)

16-16: ⚠️ Potential issue | 🔴 Critical

Fix WIN32 build break: <sys/wait.h> and UNIX-only exec_cmd() appear unguarded in src/spock_sync.c.

  • src/spock_sync.c includes #include <sys/wait.h> in the main include block (no nearby #ifdef WIN32 guards shown), but <sys/wait.h> isn’t available on Windows.
  • The only exec_cmd() implementation visible here is UNIX-oriented (pid_t, fork/exec-style); no WIN32-specific exec_cmd alternative (exec_cmd_win32/CreateProcess) is present in the shown code.

Run on Windows will likely fail at the header include and/or during compilation of the UNIX-only code.

🤖 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` at line 16, The file includes the UNIX-only header
<sys/wait.h> and contains a UNIX-style exec_cmd implementation (uses
pid_t/fork/exec) unguarded, breaking WIN32 builds; wrap the include and the UNIX
exec_cmd implementation in proper platform guards (e.g., `#if` !defined(_WIN32) /
`#endif`) so <sys/wait.h> and the fork/exec-based exec_cmd are only compiled on
POSIX, and provide either a Win32 alternative declaration or call to a
Windows-specific implementation (e.g., exec_cmd_win32/CreateProcess) for _WIN32
builds so compilation on Windows succeeds; update references to exec_cmd to use
the platform-appropriate implementation or a common wrapper function name where
needed.
🤖 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`:
- Line 16: The file includes the UNIX-only header <sys/wait.h> and contains a
UNIX-style exec_cmd implementation (uses pid_t/fork/exec) unguarded, breaking
WIN32 builds; wrap the include and the UNIX exec_cmd implementation in proper
platform guards (e.g., `#if` !defined(_WIN32) / `#endif`) so <sys/wait.h> and the
fork/exec-based exec_cmd are only compiled on POSIX, and provide either a Win32
alternative declaration or call to a Windows-specific implementation (e.g.,
exec_cmd_win32/CreateProcess) for _WIN32 builds so compilation on Windows
succeeds; update references to exec_cmd to use the platform-appropriate
implementation or a common wrapper function name where needed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 09849b26-cd7c-4c9b-93d5-be6a02003286

📥 Commits

Reviewing files that changed from the base of the PR and between 771775f and 6fae92b.

📒 Files selected for processing (5)
  • src/spock_apply.c
  • src/spock_change_log.c
  • src/spock_sync.c
  • tests/tap/schedule
  • tests/tap/t/044_apply_change_logging.pl
✅ Files skipped from review due to trivial changes (1)
  • tests/tap/schedule

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 (2)
src/spock_apply.c (1)

2393-2409: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Missing DDL apply-change logs in replay skip modes.

Line 2395 enters the TRANSDISCARD/SUB_DISABLE skip path and bypasses handle_sql(), so the DDL log call at Line 2365 never runs. That drops spock apply change JSON for queued SQL/DDL in exactly the skipped/replay path this feature is meant to expose.

Suggested fix
+/* Extract queued SQL scalar as raw string (shared by execute/skip paths). */
+static char *
+extract_queued_sql(QueuedMessage *queued_message)
+{
+    /* move current JSON scalar validation/extraction logic from handle_sql() here */
+}
+
 static void
 handle_sql(QueuedMessage *queued_message, bool tx_just_started, char **sql)
 {
-    /* Validate the json and extract the SQL string from it. */
-    ...
+    *sql = extract_queued_sql(queued_message);
     spock_log_apply_ddl(*sql, remote_origin_name);
     spock_execute_sql_command(*sql, queued_message->role, tx_just_started);
 }
 
 ...
 if (exception_behaviour == TRANSDISCARD ||
     exception_behaviour == SUB_DISABLE)
 {
-    sql = JsonbToCString(NULL, &queued_message->message->root, 0);
+    sql = extract_queued_sql(queued_message);
+    spock_log_apply_ddl(sql, remote_origin_name);
     exception_command_counter++;
     failed = false;
 }
🤖 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_apply.c` around lines 2393 - 2409, When exception_behaviour is
TRANSDISCARD or SUB_DISABLE the current branch extracts sql with JsonbToCString
and skips calling handle_sql(), which prevents emitting the DDL "spock apply
change" log; modify the TRANSDISCARD/SUB_DISABLE branch in spock_apply.c so
after sql = JsonbToCString(...) and before incrementing
exception_command_counter/setting failed you invoke the same logging path used
in the normal apply path (i.e. emit the apply-change JSON/log entry for
queued_message->message and sql) — mirror the log call that handle_sql() or the
code at the earlier log site uses so skipped/replay DDL still gets recorded
while keeping the skip behavior for execution. Ensure you reference
MyApplyWorker->use_try_block, exception_behaviour, TRANSDISCARD, SUB_DISABLE,
JsonbToCString, queued_message, exception_command_counter and failed in the
change.
src/spock_sync.c (1)

16-16: ⚠️ Potential issue | 🔴 Critical

Potential Windows build break: unguarded <sys/wait.h> + fork()/waitpid() in src/spock_sync.c

🤖 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` at line 16, The unguarded `#include` <sys/wait.h> and use of
POSIX APIs (fork(), waitpid()) in src/spock_sync.c will break Windows builds;
wrap the include and any code that calls fork()/waitpid() in platform checks
(e.g. `#if` !defined(_WIN32) || defined(HAVE_SYS_WAIT_H) ... `#endif`) and provide a
Windows-safe alternative or stub for the spock sync path (use
CreateProcess/WaitForSingleObject or return a clear "not supported on Windows"
error). Specifically, guard the <sys/wait.h> include and all occurrences of
fork() and waitpid() so Windows compiles, or add `#ifdef` _WIN32 branches that
implement equivalent behavior or disable the feature.
🤖 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_apply.c`:
- Around line 2393-2409: When exception_behaviour is TRANSDISCARD or SUB_DISABLE
the current branch extracts sql with JsonbToCString and skips calling
handle_sql(), which prevents emitting the DDL "spock apply change" log; modify
the TRANSDISCARD/SUB_DISABLE branch in spock_apply.c so after sql =
JsonbToCString(...) and before incrementing exception_command_counter/setting
failed you invoke the same logging path used in the normal apply path (i.e. emit
the apply-change JSON/log entry for queued_message->message and sql) — mirror
the log call that handle_sql() or the code at the earlier log site uses so
skipped/replay DDL still gets recorded while keeping the skip behavior for
execution. Ensure you reference MyApplyWorker->use_try_block,
exception_behaviour, TRANSDISCARD, SUB_DISABLE, JsonbToCString, queued_message,
exception_command_counter and failed in the change.

In `@src/spock_sync.c`:
- Line 16: The unguarded `#include` <sys/wait.h> and use of POSIX APIs (fork(),
waitpid()) in src/spock_sync.c will break Windows builds; wrap the include and
any code that calls fork()/waitpid() in platform checks (e.g. `#if`
!defined(_WIN32) || defined(HAVE_SYS_WAIT_H) ... `#endif`) and provide a
Windows-safe alternative or stub for the spock sync path (use
CreateProcess/WaitForSingleObject or return a clear "not supported on Windows"
error). Specifically, guard the <sys/wait.h> include and all occurrences of
fork() and waitpid() so Windows compiles, or add `#ifdef` _WIN32 branches that
implement equivalent behavior or disable the feature.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5980fd5a-34c1-424f-b966-4660e1f83bc9

📥 Commits

Reviewing files that changed from the base of the PR and between 6fae92b and 66ba3cd.

📒 Files selected for processing (5)
  • src/spock_apply.c
  • src/spock_change_log.c
  • src/spock_sync.c
  • tests/tap/schedule
  • tests/tap/t/044_apply_change_logging.pl
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/tap/t/044_apply_change_logging.pl

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

Labels

skip-test-nightly Skip this PR in the nightly TAP workflow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants