Skip to content

Commit

Permalink
PG16: Enable update/downgrade tests on CI
Browse files Browse the repository at this point in the history
Note that multinode support was removed from PG16 so starting now
update/downgrade tests will be executed only on singlenode setup.
  • Loading branch information
fabriziomello authored and jnidzwetzki committed Jan 4, 2024
1 parent 382ba66 commit 24c1697
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 44 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/update-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ jobs:
strategy:
matrix:
pg: ${{ fromJson(needs.config.outputs.pg_latest) }}
# Should be removed after the first version for PG 16 is released
exclude:
- pg: "16.1"
fail-fast: false
env:
PG_VERSION: ${{ matrix.pg }}
Expand Down Expand Up @@ -59,9 +56,6 @@ jobs:
strategy:
matrix:
pg: ${{ fromJson(needs.config.outputs.pg_latest) }}
# Should be removed after the first version for PG 16 is released
exclude:
- pg: "16.1"
fail-fast: false
env:
PG_VERSION: ${{ matrix.pg }}
Expand Down
38 changes: 26 additions & 12 deletions scripts/test_downgrade_from_tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ TEST_TMPDIR=${TEST_TMPDIR:-$(mktemp -d 2>/dev/null || mktemp -d -t 'timescaledb_
UPDATE_PG_PORT=${UPDATE_PG_PORT:-6432}
CLEAN_PG_PORT=${CLEAN_PG_PORT:-6433}
PG_VERSION=${PG_VERSION:-14.3}
PG_VERSION_MAJOR=$(echo "${PG_VERSION}" | awk '{split($0,v,"."); print v[1]}')
GIT_ID=$(git -C ${BASE_DIR} describe --dirty --always | sed -e "s|/|_|g")
UPDATE_FROM_IMAGE=${UPDATE_FROM_IMAGE:-timescale/timescaledb}
UPDATE_FROM_TAG=${UPDATE_FROM_TAG:-0.1.0}
Expand All @@ -32,8 +33,6 @@ CONTAINER_CLEAN_RESTORE=timescaledb-clean-restore-${PID}
CONTAINER_UPDATED=timescaledb-updated-${PID}
CONTAINER_CLEAN_RERUN=timescaledb-clean-rerun-${PID}

export PG_VERSION

if [[ "$DO_CLEANUP" = "false" ]]; then
echo "!!Debug mode: Containers and temporary directory will be left on disk"
else
Expand Down Expand Up @@ -214,7 +213,10 @@ docker_pgcmd ${CONTAINER_UPDATED} "SELECT user_view_schema, user_view_name FROM

echo "Executing ALTER EXTENSION timescaledb UPDATE for update ($UPDATE_FROM_TAG -> $UPDATE_TO_TAG)"
docker_pgcmd ${CONTAINER_UPDATED} "ALTER EXTENSION timescaledb UPDATE" "single"
docker_pgcmd ${CONTAINER_UPDATED} "ALTER EXTENSION timescaledb UPDATE" "dn1"
# PG16 does not support MN
if [ "${PG_VERSION_MAJOR}" -lt 16 ]; then
docker_pgcmd ${CONTAINER_UPDATED} "ALTER EXTENSION timescaledb UPDATE" "dn1"
fi
# Need to update also postgres DB since add_data_node may connect to
# it and it will be borked if we don't upgrade to an extension binary
# which is available in the image.
Expand All @@ -227,7 +229,10 @@ docker_pgcmd ${CONTAINER_UPDATED} "SELECT user_view_schema, user_view_name FROM
# downgrade the just upgraded version.
echo "Executing ALTER EXTENSION timescaledb UPDATE for downgrade ($UPDATE_TO_TAG -> $UPDATE_FROM_TAG)"
docker_pgcmd ${CONTAINER_UPDATED} "ALTER EXTENSION timescaledb UPDATE TO '$VERSION'" "postgres"
docker_pgcmd ${CONTAINER_UPDATED} "ALTER EXTENSION timescaledb UPDATE TO '$VERSION'" "dn1"
# PG16 does not support MN
if [ "${PG_VERSION_MAJOR}" -lt 16 ]; then
docker_pgcmd ${CONTAINER_UPDATED} "ALTER EXTENSION timescaledb UPDATE TO '$VERSION'" "dn1"
fi
docker_pgcmd ${CONTAINER_UPDATED} "ALTER EXTENSION timescaledb UPDATE TO '$VERSION'" "single"

# Check that there is nothing wrong before taking a backup
Expand All @@ -244,25 +249,34 @@ docker_pgscript ${CONTAINER_CLEAN_RERUN} /src/test/sql/updates/setup.${TEST_VERS
docker_pgscript ${CONTAINER_CLEAN_RERUN} /src/test/sql/updates/setup.post-downgrade.sql

docker_exec ${CONTAINER_UPDATED} "pg_dump -h localhost -U postgres -Fc single > /tmp/single.dump"
docker_exec ${CONTAINER_UPDATED} "pg_dump -h localhost -U postgres -Fc dn1 > /tmp/dn1.dump"
docker cp ${CONTAINER_UPDATED}:/tmp/single.dump ${TEST_TMPDIR}/single.dump
docker cp ${CONTAINER_UPDATED}:/tmp/dn1.dump ${TEST_TMPDIR}/dn1.dump
# PG16 does not support MN
if [ "${PG_VERSION_MAJOR}" -lt 16 ]; then
docker_exec ${CONTAINER_UPDATED} "pg_dump -h localhost -U postgres -Fc dn1 > /tmp/dn1.dump"
docker cp ${CONTAINER_UPDATED}:/tmp/dn1.dump ${TEST_TMPDIR}/dn1.dump
fi

echo "Restoring database on clean version"
docker cp ${TEST_TMPDIR}/single.dump ${CONTAINER_CLEAN_RESTORE}:/tmp/single.dump
docker cp ${TEST_TMPDIR}/dn1.dump ${CONTAINER_CLEAN_RESTORE}:/tmp/dn1.dump
# PG16 does not support MN
if [ "${PG_VERSION_MAJOR}" -lt 16 ]; then
docker cp ${TEST_TMPDIR}/dn1.dump ${CONTAINER_CLEAN_RESTORE}:/tmp/dn1.dump
fi

# Restore single
docker_exec ${CONTAINER_CLEAN_RESTORE} "createdb -h localhost -U postgres single"
docker_pgcmd ${CONTAINER_CLEAN_RESTORE} "ALTER DATABASE single SET timescaledb.restoring='on'"
docker_exec ${CONTAINER_CLEAN_RESTORE} "pg_restore -h localhost -U postgres -d single /tmp/single.dump"
docker_pgcmd ${CONTAINER_CLEAN_RESTORE} "ALTER DATABASE single RESET timescaledb.restoring"

# Restore dn1
docker_exec ${CONTAINER_CLEAN_RESTORE} "createdb -h localhost -U postgres dn1"
docker_pgcmd ${CONTAINER_CLEAN_RESTORE} "ALTER DATABASE dn1 SET timescaledb.restoring='on'"
docker_exec ${CONTAINER_CLEAN_RESTORE} "pg_restore -h localhost -U postgres -d dn1 /tmp/dn1.dump"
docker_pgcmd ${CONTAINER_CLEAN_RESTORE} "ALTER DATABASE dn1 RESET timescaledb.restoring"
# PG16 does not support MN
if [ "${PG_VERSION_MAJOR}" -lt 16 ]; then
# Restore dn1
docker_exec ${CONTAINER_CLEAN_RESTORE} "createdb -h localhost -U postgres dn1"
docker_pgcmd ${CONTAINER_CLEAN_RESTORE} "ALTER DATABASE dn1 SET timescaledb.restoring='on'"
docker_exec ${CONTAINER_CLEAN_RESTORE} "pg_restore -h localhost -U postgres -d dn1 /tmp/dn1.dump"
docker_pgcmd ${CONTAINER_CLEAN_RESTORE} "ALTER DATABASE dn1 RESET timescaledb.restoring"
fi

echo "Comparing downgraded ($UPDATE_TO_TAG -> $UPDATE_FROM_TAG) with clean install ($UPDATE_TO_TAG)"
docker_pgdiff_all /src/test/sql/updates/post.${TEST_VERSION}.sql "single"
31 changes: 22 additions & 9 deletions scripts/test_update_from_tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ TEST_TMPDIR=${TEST_TMPDIR:-$(mktemp -d 2>/dev/null || mktemp -d -t 'timescaledb_
UPDATE_PG_PORT=${UPDATE_PG_PORT:-6432}
CLEAN_PG_PORT=${CLEAN_PG_PORT:-6433}
PG_VERSION=${PG_VERSION:-14.3}
PG_VERSION_MAJOR=$(echo "${PG_VERSION}" | awk '{split($0,v,"."); print v[1]}')
GIT_ID=$(git -C ${BASE_DIR} describe --dirty --always | sed -e "s|/|_|g")
UPDATE_FROM_IMAGE=${UPDATE_FROM_IMAGE:-timescale/timescaledb}
UPDATE_FROM_TAG=${UPDATE_FROM_TAG:-0.1.0}
Expand Down Expand Up @@ -198,7 +199,10 @@ docker_run_vol ${CONTAINER_UPDATED} ${UPDATE_VOLUME}:/var/lib/postgresql/data ${

echo "Executing ALTER EXTENSION timescaledb UPDATE ($UPDATE_FROM_TAG -> $UPDATE_TO_TAG)"
docker_pgcmd ${CONTAINER_UPDATED} "ALTER EXTENSION timescaledb UPDATE" "single"
docker_pgcmd ${CONTAINER_UPDATED} "ALTER EXTENSION timescaledb UPDATE" "dn1"
# PG16 does not support MN
if [ "${PG_VERSION_MAJOR}" -lt 16 ]; then
docker_pgcmd ${CONTAINER_UPDATED} "ALTER EXTENSION timescaledb UPDATE" "dn1"
fi
# Need to update also postgres DB since add_data_node may connect to
# it and it will be borked if we don't upgrade to an extension binary
# which is available in the image.
Expand All @@ -214,25 +218,34 @@ docker_pgscript ${CONTAINER_CLEAN_RERUN} /src/test/sql/updates/pre.testing.sql
docker_pgscript ${CONTAINER_CLEAN_RERUN} /src/test/sql/updates/setup.${TEST_VERSION}.sql

docker_exec ${CONTAINER_UPDATED} "pg_dump -h localhost -U postgres -Fc single > /tmp/single.dump"
docker_exec ${CONTAINER_UPDATED} "pg_dump -h localhost -U postgres -Fc dn1 > /tmp/dn1.dump"
docker cp ${CONTAINER_UPDATED}:/tmp/single.dump ${TEST_TMPDIR}/single.dump
docker cp ${CONTAINER_UPDATED}:/tmp/dn1.dump ${TEST_TMPDIR}/dn1.dump
# PG16 does not support MN
if [ "${PG_VERSION_MAJOR}" -lt 16 ]; then
docker_exec ${CONTAINER_UPDATED} "pg_dump -h localhost -U postgres -Fc dn1 > /tmp/dn1.dump"
docker cp ${CONTAINER_UPDATED}:/tmp/dn1.dump ${TEST_TMPDIR}/dn1.dump
fi

echo "Restoring database on clean version"
docker cp ${TEST_TMPDIR}/single.dump ${CONTAINER_CLEAN_RESTORE}:/tmp/single.dump
docker cp ${TEST_TMPDIR}/dn1.dump ${CONTAINER_CLEAN_RESTORE}:/tmp/dn1.dump
# PG16 does not support MN
if [ "${PG_VERSION_MAJOR}" -lt 16 ]; then
docker cp ${TEST_TMPDIR}/dn1.dump ${CONTAINER_CLEAN_RESTORE}:/tmp/dn1.dump
fi

# Restore single
docker_exec ${CONTAINER_CLEAN_RESTORE} "createdb -h localhost -U postgres single"
docker_pgcmd ${CONTAINER_CLEAN_RESTORE} "ALTER DATABASE single SET timescaledb.restoring='on'"
docker_exec ${CONTAINER_CLEAN_RESTORE} "pg_restore -h localhost -U postgres -d single /tmp/single.dump"
docker_pgcmd ${CONTAINER_CLEAN_RESTORE} "ALTER DATABASE single RESET timescaledb.restoring"

# Restore dn1
docker_exec ${CONTAINER_CLEAN_RESTORE} "createdb -h localhost -U postgres dn1"
docker_pgcmd ${CONTAINER_CLEAN_RESTORE} "ALTER DATABASE dn1 SET timescaledb.restoring='on'"
docker_exec ${CONTAINER_CLEAN_RESTORE} "pg_restore -h localhost -U postgres -d dn1 /tmp/dn1.dump"
docker_pgcmd ${CONTAINER_CLEAN_RESTORE} "ALTER DATABASE dn1 RESET timescaledb.restoring"
# PG16 does not support MN
if [ "${PG_VERSION_MAJOR}" -lt 16 ]; then
# Restore dn1
docker_exec ${CONTAINER_CLEAN_RESTORE} "createdb -h localhost -U postgres dn1"
docker_pgcmd ${CONTAINER_CLEAN_RESTORE} "ALTER DATABASE dn1 SET timescaledb.restoring='on'"
docker_exec ${CONTAINER_CLEAN_RESTORE} "pg_restore -h localhost -U postgres -d dn1 /tmp/dn1.dump"
docker_pgcmd ${CONTAINER_CLEAN_RESTORE} "ALTER DATABASE dn1 RESET timescaledb.restoring"
fi

echo "Comparing upgraded ($UPDATE_FROM_TAG -> $UPDATE_TO_TAG) with clean install ($UPDATE_TO_TAG)"
docker_pgdiff_all /src/test/sql/updates/post.${TEST_VERSION}.sql "single"
13 changes: 13 additions & 0 deletions scripts/test_updates_pg16.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -e

SCRIPT_DIR=$(dirname $0)

# shellcheck source=scripts/test_functions.inc
source ${SCRIPT_DIR}/test_functions.inc

# Also run repair tests for >=2.10.x versions due to PR #5441
run_tests "$@" -r -v8 \
2.13.0-pg16

11 changes: 8 additions & 3 deletions test/sql/updates/cleanup.multinode.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.

DROP TABLE disthyper;
SELECT delete_data_node('dn1');
drop database if exists dn1 with (force);
SELECT current_setting('server_version_num')::int < 160000 AS has_multinode_support
\gset

\if :has_multinode_support
DROP TABLE disthyper;
SELECT delete_data_node('dn1');
drop database if exists dn1 with (force);
\endif
8 changes: 7 additions & 1 deletion test/sql/updates/cleanup.v7.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.

SELECT current_setting('server_version_num')::int < 160000 AS has_multinode_support
\gset

\ir cleanup.v6.sql
\ir cleanup.multinode.sql

\if :has_multinode_support
\ir cleanup.multinode.sql
\endif
30 changes: 18 additions & 12 deletions test/sql/updates/setup.databases.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.

SELECT current_setting('server_version_num')::int < 160000 AS has_multinode_support
\gset

CREATE DATABASE single;
-- Always pre-create the data node database 'dn1' so that we can dump
-- and restore it even on TimescaleDB versions that don't support
-- multinode. Otherwise, we'd have to create version-dependent scripts
-- to specifically handle multinode tests. We use template0, or
-- otherwise dn1 will have the same UUID as 'single' since template1
-- has the extension pre-installed.
CREATE DATABASE dn1 TEMPLATE template0;
\c dn1
-- Make sure the extension is installed so that extension versions
-- that don't support multinode will still be able to update the
-- extension with ALTER EXTENSION ... UPDATE.
CREATE EXTENSION IF NOT EXISTS timescaledb;

\if :has_multinode_support
-- Always pre-create the data node database 'dn1' so that we can dump
-- and restore it even on TimescaleDB versions that don't support
-- multinode. Otherwise, we'd have to create version-dependent scripts
-- to specifically handle multinode tests. We use template0, or
-- otherwise dn1 will have the same UUID as 'single' since template1
-- has the extension pre-installed.
CREATE DATABASE dn1 TEMPLATE template0;
\c dn1
-- Make sure the extension is installed so that extension versions
-- that don't support multinode will still be able to update the
-- extension with ALTER EXTENSION ... UPDATE.
CREATE EXTENSION IF NOT EXISTS timescaledb;
\endif

\c single
CREATE EXTENSION IF NOT EXISTS timescaledb;
Expand Down
8 changes: 7 additions & 1 deletion test/sql/updates/setup.v7.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.

SELECT current_setting('server_version_num')::int < 160000 AS has_multinode_support
\gset

\ir setup.v6.sql
\ir setup.multinode.sql

\if :has_multinode_support
\ir setup.multinode.sql
\endif

0 comments on commit 24c1697

Please sign in to comment.