Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions docs/spock_release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,9 @@ These shipped in 5.0.6 – 5.0.8 and are included in 6.0.0:

### Upgrading

The upgrade from 5.0.8 to 6.0.0 is a single `ALTER EXTENSION spock UPDATE`
once the binaries are swapped. The upgrade:
The upgrade from any 5.0.8 or later release to 6.0.0 is a single
`ALTER EXTENSION spock UPDATE` once the binaries are swapped (the command
walks the 5.0.8 -> 5.0.9 -> 5.0.10 -> 6.0.0 chain automatically). The upgrade:

* drops the legacy `spock.progress` table and recreates it as a view,
* replaces the `spock.lag_tracker` view definition,
Expand Down
32 changes: 32 additions & 0 deletions patches/15/pg15-000-spock-patchset-version.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Spock core-patchset: export patchset version via miscadmin.h and globals.c.

Adds SPOCK_CORE_PATCHSET_VERSION (compile-time constant) and
SpockCorePatchsetVersion (runtime global) to the standard places
PostgreSQL already uses for server-wide state. No new files.

--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -498,4 +498,11 @@
/* in executor/nodeHash.c */
extern size_t get_hash_memory_limit(void);

+/*
+ * Spock core-patchset identity. Bump the version when the patchset
+ * changes in a way visible to the extension binary.
+ */
+#define SPOCK_CORE_PATCHSET_VERSION 1
+extern PGDLLIMPORT int SpockCorePatchsetVersion;
+
#endif /* MISCADMIN_H */
--- a/src/backend/utils/init/globals.c
+++ b/src/backend/utils/init/globals.c
@@ -114,6 +114,9 @@
bool IsBinaryUpgrade = false;
bool IsBackgroundWorker = false;

+/* Spock core-patchset identity. */
+int SpockCorePatchsetVersion = SPOCK_CORE_PATCHSET_VERSION;
+
bool ExitOnAnyError = false;

int DateStyle = USE_ISO_DATES;
32 changes: 32 additions & 0 deletions patches/16/pg16-000-spock-patchset-version.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Spock core-patchset: export patchset version via miscadmin.h and globals.c.

Adds SPOCK_CORE_PATCHSET_VERSION (compile-time constant) and
SpockCorePatchsetVersion (runtime global) to the standard places
PostgreSQL already uses for server-wide state. No new files.

--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -510,4 +510,11 @@
/* in executor/nodeHash.c */
extern size_t get_hash_memory_limit(void);

+/*
+ * Spock core-patchset identity. Bump the version when the patchset
+ * changes in a way visible to the extension binary.
+ */
+#define SPOCK_CORE_PATCHSET_VERSION 1

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 think it is smart idea in general. It does replace one patch with another though (but smaller). I am thinking one day we could have a spock-lite with reduced functionality that would work with plain Postgres. I will think about this some more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mason-sharp ,
It is trivial to guard our patches and the corresponding Spock machinery. That enables Spock to be used with upstream Postgres. But for production use, at least one patch (logical clock) is a requirement. So, for the safety and predictability, we should have a mechanism to detect patched postgres.

+extern PGDLLIMPORT int SpockCorePatchsetVersion;
+
#endif /* MISCADMIN_H */
--- a/src/backend/utils/init/globals.c
+++ b/src/backend/utils/init/globals.c
@@ -114,6 +114,9 @@
bool IsBinaryUpgrade = false;
bool IsBackgroundWorker = false;

+/* Spock core-patchset identity. */
+int SpockCorePatchsetVersion = SPOCK_CORE_PATCHSET_VERSION;
+
bool ExitOnAnyError = false;

int DateStyle = USE_ISO_DATES;
32 changes: 32 additions & 0 deletions patches/17/pg17-000-spock-patchset-version.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Spock core-patchset: export patchset version via miscadmin.h and globals.c.

Adds SPOCK_CORE_PATCHSET_VERSION (compile-time constant) and
SpockCorePatchsetVersion (runtime global) to the standard places
PostgreSQL already uses for server-wide state. No new files.

--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -525,4 +525,11 @@
/* in executor/nodeHash.c */
extern size_t get_hash_memory_limit(void);

+/*
+ * Spock core-patchset identity. Bump the version when the patchset
+ * changes in a way visible to the extension binary.
+ */
+#define SPOCK_CORE_PATCHSET_VERSION 1
+extern PGDLLIMPORT int SpockCorePatchsetVersion;
+
#endif /* MISCADMIN_H */
--- a/src/backend/utils/init/globals.c
+++ b/src/backend/utils/init/globals.c
@@ -117,6 +117,9 @@
bool IsUnderPostmaster = false;
bool IsBinaryUpgrade = false;

+/* Spock core-patchset identity. */
+int SpockCorePatchsetVersion = SPOCK_CORE_PATCHSET_VERSION;
+
bool ExitOnAnyError = false;

int DateStyle = USE_ISO_DATES;
32 changes: 32 additions & 0 deletions patches/18/pg18-000-spock-patchset-version.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Spock core-patchset: export patchset version via miscadmin.h and globals.c.

Adds SPOCK_CORE_PATCHSET_VERSION (compile-time constant) and
SpockCorePatchsetVersion (runtime global) to the standard places
PostgreSQL already uses for server-wide state. No new files.

--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -540,4 +540,11 @@
/* in executor/nodeHash.c */
extern size_t get_hash_memory_limit(void);

+/*
+ * Spock core-patchset identity. Bump the version when the patchset
+ * changes in a way visible to the extension binary.
+ */
+#define SPOCK_CORE_PATCHSET_VERSION 1
+extern PGDLLIMPORT int SpockCorePatchsetVersion;
+
#endif /* MISCADMIN_H */
--- a/src/backend/utils/init/globals.c
+++ b/src/backend/utils/init/globals.c
@@ -120,6 +120,9 @@
bool IsUnderPostmaster = false;
bool IsBinaryUpgrade = false;

+/* Spock core-patchset identity. */
+int SpockCorePatchsetVersion = SPOCK_CORE_PATCHSET_VERSION;
+
bool ExitOnAnyError = false;

int DateStyle = USE_ISO_DATES;
6 changes: 5 additions & 1 deletion sql/spock--5.0.8--6.0.0.sql → sql/spock--5.0.10--6.0.0.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* spock--5.0.8--6.0.0.sql */
/* spock--5.0.10--6.0.0.sql */

-- No schema changes occurred between 5.0.8 and 5.0.10 (spock--5.0.8--5.0.9.sql
-- and spock--5.0.9--5.0.10.sql are empty no-ops), so this final step of the
-- update chain carries the full 5.x -> 6.0.0 migration.

-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION spock UPDATE TO '6.0.0'" to load this file. \quit
Expand Down
6 changes: 6 additions & 0 deletions sql/spock--5.0.8--5.0.9.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* spock--5.0.8--5.0.9.sql */

-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION spock UPDATE TO '5.0.9'" to load this file. \quit

-- No schema changes in 5.0.9.
6 changes: 6 additions & 0 deletions sql/spock--5.0.9--5.0.10.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* spock--5.0.9--5.0.10.sql */

-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION spock UPDATE TO '5.0.10'" to load this file. \quit

-- No schema changes in 5.0.10.
14 changes: 14 additions & 0 deletions src/spock.c
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,20 @@ _PG_init(void)
if (!process_shared_preload_libraries_in_progress)
elog(ERROR, "spock is not in shared_preload_libraries");

/*
* Runtime patchset check: if the server binary was built from a
* different patchset generation than this extension, refuse to
* start. An unpatched server never reaches here -- the dynamic
* linker fails on the missing SpockCorePatchsetVersion symbol.
*/
if (SpockCorePatchsetVersion != SPOCK_CORE_PATCHSET_VERSION)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("spock core patchset version mismatch: "
"server has v%d, extension expects v%d",
SpockCorePatchsetVersion,
SPOCK_CORE_PATCHSET_VERSION)));

DefineCustomEnumVariable("spock.conflict_resolution",
gettext_noop("Sets method used for conflict resolution for resolvable conflicts."),
NULL,
Expand Down
1 change: 1 addition & 0 deletions tests/tap/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ test: 025_tiebreaker_equal_warning
# Regression tests

test: 103_manager_worker_dboid_race
test: 030_pg_upgrade_5x_to_6x
5 changes: 4 additions & 1 deletion tests/tap/t/002_create_subscriber.pl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@

# Test 13: Insert more data and verify replication
system_or_bail "$pg_bin/psql", '-p', $node_ports->[0], '-d', $dbname, '-c', "INSERT INTO test_subscription_data (name, value) VALUES ('test3', 300)";
system_or_bail "$pg_bin/psql", '-q', '-p', $node_ports->[1], '-d', $dbname, '-c', "SELECT spock.sub_wait_for_sync('test_subscription')";
my $sync_lsn = `$pg_bin/psql -p $node_ports->[0] -d $dbname -t -A -c "SELECT spock.sync_event()"`;
chomp($sync_lsn);
$sync_lsn =~ s/\s+//g;
system_or_bail "$pg_bin/psql", '-q', '-p', $node_ports->[1], '-d', $dbname, '-c', "CALL spock.wait_for_sync_event(NULL, 'n1', '$sync_lsn'::pg_lsn, 60)";

my $count_subscriber_updated = `$pg_bin/psql -p $node_ports->[1] -d $dbname -t -c "SELECT COUNT(*) FROM test_subscription_data"`;
chomp($count_subscriber_updated);
Expand Down
20 changes: 10 additions & 10 deletions tests/tap/t/018_upgrade_schema_match.pl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# =============================================================================
# Test: 018_upgrade_schema_match.pl
#
# Verify that upgrading Spock from 5.0.8 -> 6.0.0 produces a schema that is
# Verify that upgrading Spock from 5.0.10 -> 6.0.0 produces a schema that is
# identical to a fresh 6.0.0 installation.
#
# Each Spock version requires PostgreSQL built with that branch's patches:
Expand All @@ -28,7 +28,7 @@
# for caching across runs (only datadirs and source trees are cleaned up).
#
# Environment variables:
# V5_PG_INSTALL pre-built PG+Spock 5.0.8 dir (default: $TEMP_BASE/pg_v5)
# V5_PG_INSTALL pre-built PG+Spock 5.0.10 dir (default: $TEMP_BASE/pg_v5)
# V60_PG_INSTALL pre-built PG+Spock 6.0.0 dir (default: $TEMP_BASE/pg_v60)
# PG_TAG git tag for PG source (default: REL_18_2)
# PG_REPO git URL for PG source (default: github postgres mirror)
Expand Down Expand Up @@ -75,7 +75,7 @@
my $V60_BIN = "$V60_PG_INSTALL/bin";
my $PG_BIN = $V60_BIN; # client tools (psql, pg_ctl) use v60 binary

my $DATADIR_UPG = "$TEMP_BASE/datadir_upgraded"; # starts at 5.0.8, upgraded
my $DATADIR_UPG = "$TEMP_BASE/datadir_upgraded"; # starts at 5.0.10, upgraded
my $DATADIR_NEW = "$TEMP_BASE/datadir_fresh"; # fresh 6.0.0 install
my $PORT_UPG = 5441;
my $PORT_NEW = 5442;
Expand Down Expand Up @@ -352,11 +352,11 @@ sub compare_category {
}

# ─────────────────────────────────────────────────────────────────────────────
# PHASE 1 – Ensure v5_STABLE environment (PG + Spock 5.0.8)
# PHASE 1 – Ensure v5_STABLE environment (PG + Spock 5.0.10)
# ─────────────────────────────────────────────────────────────────────────────
diag("PHASE 1: Ensuring Spock 5.0.8 environment ($V5_BRANCH)");
diag("PHASE 1: Ensuring Spock 5.0.10 environment ($V5_BRANCH)");
ok(ensure_version_ready($V5_BRANCH, $V5_PG_INSTALL, 'v5'),
"Spock 5.0.8 environment ready");
"Spock 5.0.10 environment ready");

# ─────────────────────────────────────────────────────────────────────────────
# PHASE 2 – Ensure current environment (PG + Spock 6.0.0)
Expand All @@ -366,11 +366,11 @@ sub compare_category {
"Spock 6.0.0 environment ready");

# ─────────────────────────────────────────────────────────────────────────────
# PHASE 3 – Start upgrade node (Spock 5.0.8)
# PHASE 3 – Start upgrade node (Spock 5.0.10)
# ─────────────────────────────────────────────────────────────────────────────
diag("PHASE 3: Initialising upgrade node (Spock 5.0.8)...");
diag("PHASE 3: Initialising upgrade node (Spock 5.0.10)...");
ok(init_and_start_node($DATADIR_UPG, $PORT_UPG, $V5_PG_INSTALL),
'Upgrade node started (5.0.8)');
'Upgrade node started (5.0.10)');

# ─────────────────────────────────────────────────────────────────────────────
# PHASE 4 – Start fresh node (Spock 6.0.0)
Expand All @@ -394,7 +394,7 @@ sub compare_category {
my $ver_upg = scalar_query($NODE_UPG,
"SELECT extversion FROM pg_extension WHERE extname = 'spock'");
diag("Upgrade node extension version after CREATE: $ver_upg");
like($ver_upg, qr/^5\.0\.8/, 'Upgrade node starts at 5.0.8');
like($ver_upg, qr/^5\.0\.10/, 'Upgrade node starts at 5.0.10');

psql_or_bail($NODE_NEW, 'CREATE EXTENSION spock');
my $ver_new = scalar_query($NODE_NEW,
Expand Down
Loading
Loading