Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
8149f59
Add spock_create_subscriber — bootstrap a subscriber from a physical …
rasifr Jun 22, 2026
3915a74
spock_create_subscriber: drop legacy paths and extension usage
rasifr Jun 22, 2026
b6760d0
Added usage document for spock_create_subscriber
rasifr Jun 22, 2026
d427523
spock_create_subscriber address review feedback
rasifr Jul 22, 2026
0b6f150
spock_create_subscriber: add bidirectional join plumbing
rasifr Jul 9, 2026
214956d
spock_create_subscriber: add TAP test for --bidirectional plumbing
rasifr Jul 13, 2026
cea4396
spock_create_subscriber: physical backup, catalog strip, repset restore
rasifr Jul 28, 2026
033a8df
spock_create_subscriber: add --postgresql-auto-conf override
rasifr Aug 5, 2026
fe6ce5b
spock_create_subscriber: trace every query and step at -v -v
rasifr Aug 6, 2026
b76f80b
spock_create_subscriber: catchup subscription phase
rasifr Aug 6, 2026
4f6a49f
spock_create_subscriber: bring n3 live with bidirectional replication
rasifr Aug 20, 2026
f3a1a6c
spock_create_subscriber: unify peer/source loops in the reverse-sub p…
rasifr Aug 24, 2026
f204e58
spock_create_subscriber: simplify and strengthen option parsing
rasifr Aug 27, 2026
ab83feb
spock_create_subscriber: break main() into lifecycle phases
rasifr Aug 27, 2026
6c76c1b
spock_create_subscriber: liveness-aware stall watchdog for big transa…
rasifr Sep 7, 2026
7c0f627
spock_create_subscriber: WAL-retention test; expand bidirectional TAP…
rasifr Sep 7, 2026
c6de66a
pgindent run
rasifr Sep 7, 2026
f195454
spock_create_subscriber: fix manifest JSON parsing on PG15/16
rasifr Sep 7, 2026
5618f6c
Keep spock_output usable as an output plugin on PG18+
rasifr Sep 16, 2026
3a35b9d
SPOC-607 hardening: failure-matrix, cleanup idempotency, forwarded-di…
rasifr Sep 16, 2026
7de51ad
081_bidir_join_forwarded_discard_abort: fix race between catchup and …
rasifr Sep 21, 2026
87510b1
081_bidir_join_forwarded_discard_abort: unlink stale rendezvous markers
rasifr Sep 21, 2026
40cc01f
tests: disable 077_bidir_join_lww_conflict pending the tiebreaker fix
rasifr Sep 21, 2026
d7be2b7
spock_create_subscriber: fix cleanup, orphaned-resource and recovery-…
rasifr Oct 7, 2026
c1fa270
tests: cover spock_create_subscriber base backup, cleanup and guards
rasifr Oct 7, 2026
6458605
spock_create_subscriber: keep source secrets off the command line and…
rasifr Oct 7, 2026
94c7474
tests: check spock_create_subscriber keeps secrets out of output
rasifr Oct 7, 2026
c2fedf5
spock_create_subscriber: create the subscription disabled, then enabl…
rasifr Nov 10, 2026
0437e83
spock_create_subscriber: keep the manifest until --cleanup confirms r…
rasifr Nov 10, 2026
aee9105
spock_create_subscriber: record join status in the manifest
rasifr Nov 10, 2026
ee90757
spock_create_subscriber: fix restore point reuse and failure-path cle…
rasifr Nov 11, 2026
569aa8b
spock_create_subscriber: handle SIGINT/SIGTERM outside the signal han…
rasifr Nov 18, 2026
7510665
spock_create_subscriber: validate the new node's configuration
rasifr Nov 18, 2026
abae58c
spock_create_subscriber: reject --apply-delay and --text-types with -…
rasifr Nov 18, 2026
9a9759d
spock_create_subscriber: fix the recovery hint for a promoted data di…
rasifr Nov 18, 2026
ccf6d2e
docs: describe the bidirectional options of spock_create_subscriber
rasifr Nov 18, 2026
46ec9de
tests: add bidirectional join under sustained write load
rasifr Nov 18, 2026
0fdf454
spock_create_subscriber: require the source's subscriptions to select…
rasifr Nov 18, 2026
7dea0f9
spock_create_subscriber: raise --stall-timeout default to 1800s
rasifr Nov 18, 2026
56e70da
Check bidirectional join preconditions before any slot or backup.
rasifr Nov 26, 2026
4b97dfa
Split the bidirectional activation into catchup and publish passes.
rasifr Nov 26, 2026
eac9115
Wait for outbound slots to reach a fixed WAL position before a join.
rasifr Nov 26, 2026
3a91e28
Close gaps in the bidirectional join preflight found in review.
rasifr Nov 27, 2026
c902872
Address review findings on the bidirectional join.
rasifr Nov 30, 2026
cf8c2fc
Move the manifest code of spock_create_subscriber to its own file.
rasifr Nov 30, 2026
b1e9baf
Move the general helpers of spock_create_subscriber to common.c.
rasifr Nov 30, 2026
b4632a9
Move the bidirectional join's preflight checks to preflight.c.
rasifr Nov 30, 2026
37d7b28
Address the third and fourth rounds of review findings on the join ut…
rasifr Nov 30, 2026
2ad093e
Apply pgindent to the join utility.
rasifr Nov 30, 2026
11b6e0b
Address review findings on the join utility.
rasifr Dec 1, 2026
30994e4
Run the new node under sub_disable until forwarding is cleared.
rasifr Dec 1, 2026
1f64756
Simplify --cleanup: refuse another run's records, drop --force.
rasifr Dec 1, 2026
20aa589
Move the slowest join failure-path tests to the nightly schedule.
rasifr Dec 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
results
regression_output
tmp_check
spock_create_subscriber
/utils/spock_create_subscriber/spock_create_subscriber
/utils/spock_create_subscriber/.deps/
/utils/spock_create_subscriber/spock_fe.c
.vimrc
*.o
*.so
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ EXTENSION = spock
PGFILEDESC = "spock - multi-master replication"

MODULES = spock_output
SUBDIRS = utils/spock_create_subscriber

# Lookup source directory
vpath % src src/compat/$(PGVER)
Expand Down
141 changes: 141 additions & 0 deletions docs/creating_subscriber_nodes.md

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions docs/modify/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ There are several tools and scripts you can use to add a node to a cluster; the

[pgBackRest](add_node_pgbackrest.md) is an open-source tool that you can use to add a node to a replicating cluster with minimal interruption.

* **Use spock_create_subscriber to Clone a Provider or Join a Multi-Master Cluster**

[`spock_create_subscriber`](../creating_subscriber_nodes.md) clones a node with `pg_basebackup` and starts the copy as a Spock subscriber; with `--bidirectional` it joins the new node to an existing multi-master cluster, subscribing it to every existing node and every existing node to it.

23 changes: 21 additions & 2 deletions include/spock_injection.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* spock_injection.h
* Injection point support for the Spock extension.
*
* Two named injection points are defined, one per side of the wire:
* Four named injection points are defined:
*
* SPOCK_WORKER_DELAY() – subscriber side, at apply-worker
* start/finish sites ('spock-worker-delay').
Expand All @@ -26,6 +26,18 @@
* insertion exists to survive, and the one
* a concurrent local writer produces for
* real.
* SPOCK_FORWARDED_APPLY_ERROR() – subscriber side, right before a
* forwarded-origin row change is applied
* to the heap ('spock-forwarded-apply-
* error'). Lets a test attach an
* 'error'-mode injection point (core's
* injection_points extension) to force
* an error-class exception on a
* forwarded transaction, e.g. during a
* bidirectional-join catchup, to verify
* the transaction aborts rather than
* silently committing with a missing
* row.
*
* SPOCK_RANDOM_DELAYS defined – the worker and output-plugin points call
* spock_random_delay() directly; fires
Expand All @@ -35,7 +47,10 @@
* a worker or transaction boundary, and a
* sleep averaging 50 ms on every applied
* row puts the regression suite hours past
* any sensible timeout.
* any sensible timeout. The same goes for
* SPOCK_FORWARDED_APPLY_ERROR(), which is
* also a no-op: a random sleep does not
* serve an error-injection point.
* USE_INJECTION_POINTS defined – all expand to INJECTION_POINT(); the
* core injection_points module can
* attach to any name when needed.
Expand Down Expand Up @@ -83,6 +98,7 @@ extern void spock_random_delay(void);
/* Per-row: delaying here would take the suite hours. See above. */
#define SPOCK_INSERT_CONFLICT_STALL() ((void) 0)
#define SPOCK_APPLY_UPDATE_STALL() ((void) 0)
#define SPOCK_FORWARDED_APPLY_ERROR() ((void) 0)

#elif defined(USE_INJECTION_POINTS)

Expand All @@ -94,12 +110,14 @@ extern void spock_random_delay(void);
#define SPOCK_INSERT_CONFLICT_STALL() \
INJECTION_POINT("spock-insert-conflict-stall", NULL)
#define SPOCK_APPLY_UPDATE_STALL() INJECTION_POINT("spock-apply-update-stall", NULL)
#define SPOCK_FORWARDED_APPLY_ERROR() INJECTION_POINT("spock-forwarded-apply-error", NULL)
#else
#define SPOCK_WORKER_DELAY() INJECTION_POINT("spock-worker-delay")
#define SPOCK_OUTPUT_TXN_STALL() INJECTION_POINT("spock-output-txn-stall")
#define SPOCK_INSERT_CONFLICT_STALL() \
INJECTION_POINT("spock-insert-conflict-stall")
#define SPOCK_APPLY_UPDATE_STALL() INJECTION_POINT("spock-apply-update-stall")
#define SPOCK_FORWARDED_APPLY_ERROR() INJECTION_POINT("spock-forwarded-apply-error")
#endif

#else
Expand All @@ -108,6 +126,7 @@ extern void spock_random_delay(void);
#define SPOCK_OUTPUT_TXN_STALL() ((void) 0)
#define SPOCK_INSERT_CONFLICT_STALL() ((void) 0)
#define SPOCK_APPLY_UPDATE_STALL() ((void) 0)
#define SPOCK_FORWARDED_APPLY_ERROR() ((void) 0)

#endif /* SPOCK_RANDOM_DELAYS / USE_INJECTION_POINTS */

Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ nav:
- Updating the Postgres Version with a Rolling Update: modify/zodan/zodan_rolling_pg_version_tutorial.md
- Upgrading the Postgres Version In Place with pg_upgrade: modify/pg_upgrade_rolling_tutorial.md
- Adding a Node with Minimal Downtime with pgBackRest: modify/add_node_pgbackrest.md
- Creating a Subscriber Node with spock_create_subscriber: creating_subscriber_nodes.md
- Recovering from Catastrophic Node Failure: recovery/catastrophic_node_failure.md
- Monitoring a Cluster:
- Monitoring the Configuration and Health of a Cluster: monitoring/index.md
Expand Down
27 changes: 27 additions & 0 deletions src/spock_apply_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#include "spock_apply_heap.h"
#include "spock_apply.h"
#include "spock_exception_handler.h"
#include "spock_injection.h"
#include "spock.h"

typedef struct ApplyExecutionData
Expand Down Expand Up @@ -111,6 +112,23 @@ static void build_delta_tuple(SpockRelation *rel, SpockTupleData *oldtup,
#endif
static bool physatt_in_attmap(SpockRelation *rel, int attid);

/*
* Is the row currently being applied part of a transaction whose origin is
* not this apply worker's direct provider -- i.e. a forwarded-origin
* change (cascade or bidirectional-join forwarding)?
*
* replorigin_session_origin mirrors handle_origin()'s remote_origin_id for
* the duration of the transaction (spock_apply.c), so this is the same
* first-order test handle_origin() itself uses, without needing any of
* spock_apply.c's file-static transaction state visible here.
*/
static inline bool
is_forwarded_origin_apply(void)
{
return replorigin_session_origin != InvalidRepOriginId &&
replorigin_session_origin != (RepOriginId) MySubscription->origin->id;
}

/*
* Executor state preparation for evaluation of constraint expressions,
* indexes and triggers for the specified relation.
Expand Down Expand Up @@ -1239,6 +1257,9 @@ spock_apply_heap_insert(SpockRelation *rel, SpockTupleData *newtup)
slot_fill_defaults(rel, estate, remoteslot);
MemoryContextSwitchTo(oldctx);

if (is_forwarded_origin_apply())
SPOCK_FORWARDED_APPLY_ERROR();

EvalPlanQualInit(&epqstate, estate, NULL, NIL, -1, NIL);

/*
Expand Down Expand Up @@ -1463,6 +1484,9 @@ spock_apply_heap_update(SpockRelation *rel, SpockTupleData *oldtup,

MemoryContextSwitchTo(oldctx);

if (is_forwarded_origin_apply())
SPOCK_FORWARDED_APPLY_ERROR();

/* Find the current local tuple */
EvalPlanQualInit(&epqstate, estate, NULL, NIL, -1, NIL);
ExecOpenIndices(edata->targetRelInfo, false);
Expand Down Expand Up @@ -1586,6 +1610,9 @@ spock_apply_heap_delete(SpockRelation *rel, SpockTupleData *oldtup)

MemoryContextSwitchTo(oldctx);

if (is_forwarded_origin_apply())
SPOCK_FORWARDED_APPLY_ERROR();

/* Find the current local tuple */
EvalPlanQualInit(&epqstate, estate, NULL, NIL, -1, NIL);
ExecOpenIndices(edata->targetRelInfo, false);
Expand Down
35 changes: 31 additions & 4 deletions src/spock_fe.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int
find_other_exec_version(const char *argv0, const char *target,
uint32 *version, char *retpath)
{
char cmd[MAXPGPATH];
char cmd[4 * MAXPGPATH + 32]; /* retpath, every quote escaped */
char cmd_output[1024];
FILE *output;
int pre_dot = 0,
Expand All @@ -59,7 +59,31 @@ find_other_exec_version(const char *argv0, const char *target,
"/%s%s", target, EXE);

/* And request the version from the program */
#ifndef WIN32
{
/* quote retpath as one shell word, whatever characters it holds */
size_t n = 0;
const char *q;

cmd[n++] = '\'';
for (q = retpath; *q && n < sizeof(cmd) - 16; q++)
{
if (*q == '\'')
{
cmd[n++] = '\'';
cmd[n++] = '\\';
cmd[n++] = '\'';
cmd[n++] = '\'';
}
else
cmd[n++] = *q;
}
cmd[n] = '\0';
strlcat(cmd, "' --version", sizeof(cmd));
}
#else
snprintf(cmd, sizeof(cmd), "\"%s\" --version", retpath);
#endif

if ((output = popen(cmd, "r")) == NULL)
{
Expand Down Expand Up @@ -226,10 +250,12 @@ appendPQExpBufferConnstrValue(PQExpBuffer buf, const char *str)
bool needquotes;

/*
* If the string consists entirely of plain ASCII characters, no need to
* quote it. This is quite conservative, but better safe than sorry.
* If the string is one or more plain ASCII characters, no need to quote
* it. An empty string must default to needing quotes -- an unquoted
* empty value doesn't parse as empty, it swallows the entire next
* "keyword=value" token.
*/
needquotes = false;
needquotes = true;
for (s = str; *s; s++)
{
if (!((*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z') ||
Expand All @@ -238,6 +264,7 @@ appendPQExpBufferConnstrValue(PQExpBuffer buf, const char *str)
needquotes = true;
break;
}
needquotes = false;
}

if (needquotes)
Expand Down
8 changes: 7 additions & 1 deletion tests/docker/Dockerfile-step-1.el9
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ ARG PG_REF=
ARG SPOCK_RANDOM_DELAYS=
# When set to any non-empty value, PostgreSQL is configured with
# --enable-injection-points, so spock_injection.h's USE_INJECTION_POINTS
# branch is compiled. Must be combined with an empty SPOCK_RANDOM_DELAYS.
# branch is compiled, and the injection_points test module (PostgreSQL 17 and
# later) is installed, which the TAP tests that attach injection points load.
# Must be combined with an empty SPOCK_RANDOM_DELAYS.
ARG ENABLE_INJECTION_POINTS=

# Export as environment variables for build-time and runtime
Expand Down Expand Up @@ -214,6 +216,10 @@ RUN set -eux && \
echo "========================================" && \
make install > /dev/null && \
make -C contrib install > /dev/null && \
if [ -n "${ENABLE_INJECTION_POINTS}" ] && \
[ -d src/test/modules/injection_points ]; then \
make -C src/test/modules/injection_points install > /dev/null; \
fi && \
echo "PostgreSQL installation complete"

# ==============================================================================
Expand Down
39 changes: 39 additions & 0 deletions tests/regress/expected/conflict_stat.out
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,45 @@ SELECT spock.reset_subscription_stats(:test_sub_id);
(1 row)

TRUNCATE spock.exception_log;
-- ============================================================
-- Test spock.get_subscription_stats() against a disabled subscription
-- whose apply worker has never run (PG18 stats hooks guard, read side).
-- The pgstat entry is created at CREATE SUBSCRIPTION time regardless of
-- "enabled", so this must return a well-defined all-zero row, not crash.
-- ============================================================
BEGIN;
SELECT 1 FROM spock.sub_create(
subscription_name := 'test_subscription_disabled',
provider_dsn := (SELECT provider_dsn FROM spock_regress_variables()) || ' user=super',
replication_sets := '{}',
synchronize_structure := false,
synchronize_data := false,
forward_origins := '{}',
enabled := false);
?column?
----------
1
(1 row)

COMMIT;
SELECT sub_id AS disabled_sub_id FROM spock.subscription
WHERE sub_name = 'test_subscription_disabled' \gset
SELECT confl_update_missing,
confl_insert_exists,confl_update_origin_differs,confl_update_exists,
confl_delete_origin_differs,confl_delete_missing,confl_delete_exists,
stats_reset
FROM spock.get_subscription_stats(:disabled_sub_id);
confl_update_missing | confl_insert_exists | confl_update_origin_differs | confl_update_exists | confl_delete_origin_differs | confl_delete_missing | confl_delete_exists | stats_reset
----------------------+---------------------+-----------------------------+---------------------+-----------------------------+----------------------+---------------------+-------------
0 | 0 | 0 | 0 | 0 | 0 | 0 |
(1 row)

SELECT spock.sub_drop('test_subscription_disabled');
sub_drop
----------
1
(1 row)

-- Cleanup
\c :provider_dsn
SELECT spock.replicate_ddl($$ DROP TABLE public.conflict_ue_test CASCADE; $$);
Expand Down
29 changes: 29 additions & 0 deletions tests/regress/sql/conflict_stat.sql
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,35 @@ FROM spock.get_subscription_stats(:test_sub_id);
SELECT spock.reset_subscription_stats(:test_sub_id);
TRUNCATE spock.exception_log;

-- ============================================================
-- Test spock.get_subscription_stats() against a disabled subscription
-- whose apply worker has never run (PG18 stats hooks guard, read side).
-- The pgstat entry is created at CREATE SUBSCRIPTION time regardless of
-- "enabled", so this must return a well-defined all-zero row, not crash.
-- ============================================================

BEGIN;
SELECT 1 FROM spock.sub_create(
subscription_name := 'test_subscription_disabled',
provider_dsn := (SELECT provider_dsn FROM spock_regress_variables()) || ' user=super',
replication_sets := '{}',
synchronize_structure := false,
synchronize_data := false,
forward_origins := '{}',
enabled := false);
COMMIT;

SELECT sub_id AS disabled_sub_id FROM spock.subscription
WHERE sub_name = 'test_subscription_disabled' \gset

SELECT confl_update_missing,
confl_insert_exists,confl_update_origin_differs,confl_update_exists,
confl_delete_origin_differs,confl_delete_missing,confl_delete_exists,
stats_reset
FROM spock.get_subscription_stats(:disabled_sub_id);

SELECT spock.sub_drop('test_subscription_disabled');

-- Cleanup
\c :provider_dsn
SELECT spock.replicate_ddl($$ DROP TABLE public.conflict_ue_test CASCADE; $$);
Expand Down
11 changes: 11 additions & 0 deletions tests/tap/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ test: 046_apply_worker_exception_misclassification
test: 048_insert_conflict_race
test: 049_wait_for_sync_dropped
test: 052_change_log_attmap
test: 070_bidir_plumbing
test: 073_bidir_join_multipeer_lag
test: 074_bidir_join_big_txn_liveness
test: 075_bidir_join_unbounded_peer_slot_wal
test: 077_bidir_join_lww_conflict
test: 078_bidir_join_concurrent_load
test: 081_bidir_join_forwarded_discard_abort
test: 082_create_subscriber_basebackup
test: 083_create_subscriber_enable_order
test: 084_create_subscriber_exception_modes
test: 085_create_subscriber_rmgr_replay
# Upgrade schema match test (builds from source, slow):
#test: 018_upgrade_schema_match
#
Expand Down
18 changes: 18 additions & 0 deletions tests/tap/schedule-nightly
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,21 @@ test: 103_manager_worker_dboid_race
test: 110_resync_node_info_warning
test: 120_standby_holdback_quorum
test: 121_exception_slot_exhausted

# --bidirectional join failure paths, kept off the per-PR schedule to stay
# inside the 30 minute TAP step limit in spockbench.yml. 076 and 080 are
# matrices in which every case is a full join (~110s apiece); 072, 079 and 086
# (~43s each) cover the utility being killed mid-catchup, the stall watchdog
# aborting, and the source slot creation being cancelled.
test: 072_bidir_join_crash_midcatchup
test: 076_bidir_join_precondition_negatives
test: 079_bidir_join_stall_abort
test: 080_bidir_join_failure_matrix
test: 086_create_subscriber_slot_cancel

# --bidirectional join under sustained OLTP write load (pgedge-loadgen).
# Not yet enabled here: needs its real-world runtime at
# SPOCK_BIDIR_LOAD_LEVEL=medium/heavy characterized on CI hardware first,
# and CI needs a pgedge-loadgen checkout (PGEDGE_LOADGEN_BIN) available --
# it skip_alls cleanly without one. ~161s locally at the light default.
#test: 071_bidir_join_under_load
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@

# Restart the apply worker repeatedly while the writer is running, via
# sub_alter_options() toggling apply_delay -- the same mechanism that
# uncovered this bug in 049_bidir_join_under_load.pl's lag-injection
# uncovered this bug in 071_bidir_join_under_load.pl's lag-injection
# scenario.
for my $i (1 .. 40) {
system_or_bail("$pg_bin/psql", '-X', '-p', $p2, '-d', $dbname, '-c',
Expand Down
Loading
Loading