Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #439 #445

Merged
merged 2 commits into from
Sep 4, 2023
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ Slave settings:
- **DESTROY_DATABASE_ON_RESTART**: Default is `True`. Set to 'False' to prevent this behavior. A
replicant will always destroy its current database on restart, because it will try to sync again
from `master` and avoid inconsistencies.
- **PROMOTE_MASTER**: Default none. If set to any value then the current replicant
- **PROMOTE_MASTER**: Default false. If set to `true` then the current replicant
will be promoted to master. In some cases when the `master` container has failed, we might want
to use our `replicant` as `master` for a while. However, the promoted replicant will break
consistencies and is not able to revert to replicant anymore, unless it is destroyed and
Expand Down
39 changes: 0 additions & 39 deletions commit-and-deploy.sh

This file was deleted.

1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

8 changes: 1 addition & 7 deletions scenario_tests/collations/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

version: '2.1'
version: '3.9'

volumes:
pg-data-dir:
Expand All @@ -11,8 +11,6 @@ services:
pg:
image: 'kartoza/postgis:${TAG:-manual-build}'
restart: 'always'
# You can optionally mount to volume, to play with the persistence and
# observe how the node will behave after restarts.
volumes:
- pg-data-dir:/var/lib/postgresql
- ./tests:/tests
Expand All @@ -35,8 +33,6 @@ services:
pg-new:
image: 'kartoza/postgis:${TAG:-manual-build}'
restart: 'always'
# You can optionally mount to volume, to play with the persistence and
# observe how the node will behave after restarts.
volumes:
- new-pg-data-dir:/opt/data/postgis
- ./tests:/tests
Expand All @@ -62,8 +58,6 @@ services:
pg-gosu:
image: 'kartoza/postgis:${TAG:-manual-build}'
restart: 'always'
# You can optionally mount to volume, to play with the persistence and
# observe how the node will behave after restarts.
volumes:
- pg-data-dir-gs:/var/lib/postgresql
- ./tests:/tests
Expand Down
2 changes: 1 addition & 1 deletion scenario_tests/datadir_init/docker-compose-gs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2.1'
version: '3.9'
volumes:
default-pg-data-dir:
new-pg-data-dir:
Expand Down
2 changes: 1 addition & 1 deletion scenario_tests/datadir_init/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2.1'
version: '3.9'
volumes:
default-pg-data-dir:
new-pg-data-dir:
Expand Down
2 changes: 1 addition & 1 deletion scenario_tests/extensions/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

version: '2.1'
version: '3.9'

services:
pg:
Expand Down
2 changes: 1 addition & 1 deletion scenario_tests/init_scripts/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2.1'
version: '3.9'
volumes:
default-pg-data-dir-md5:
new-pg-data-dir:
Expand Down
2 changes: 1 addition & 1 deletion scenario_tests/logical_replication/docker-compose-gs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

version: '2.1'
version: '3.9'

volumes:
pg-publisher-data-dir:
Expand Down
2 changes: 1 addition & 1 deletion scenario_tests/logical_replication/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

version: '2.1'
version: '3.9'

volumes:
pg-publisher-data-dir:
Expand Down
2 changes: 1 addition & 1 deletion scenario_tests/multiple_databases/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

version: '2.1'
version: '3.9'

volumes:
pg-db-data-dir:
Expand Down
62 changes: 62 additions & 0 deletions scenario_tests/streaming_replication/docker-compose-gs-promote.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

version: '2.1'

volumes:
pg-master-data-dir:
pg-node-data-dir:

services:
pg-master:
image: 'kartoza/postgis:${TAG:-manual-build}'
restart: 'always'

volumes:
- pg-master-data-dir:/var/lib/postgresql
- ./tests:/tests
- ../utils:/lib/utils
- ./scripts/setup-master.sql:/docker-entrypoint-initdb.d/setup-master.sql
environment:

ALLOW_IP_RANGE: '0.0.0.0/0'

# We can specify optional credentials
POSTGRES_PASS: 'docker'
REPLICATION_USER: 'replicator'
REPLICATION_PASS: 'replicator'
REPLICATION: 'true'
RUN_AS_ROOT: false
healthcheck:
interval: 60s
timeout: 30s
retries: 3
test: "pg_isready"

pg-node:
image: 'kartoza/postgis:${TAG:-manual-build}'
restart: 'always'

volumes:
- pg-node-data-dir:/var/lib/postgresql
- ./tests:/tests
- ../utils:/lib/utils

environment:

ALLOW_IP_RANGE: '0.0.0.0/0'
POSTGRES_PASS: 'docker'
REPLICATE_FROM: 'pg-master'
REPLICATION: 'true'
RUN_AS_ROOT: false
PROMOTE_MASTER: false
DESTROY_DATABASE_ON_RESTART: 'True'
REPLICATION_USER: 'replicator'
REPLICATION_PASS: 'replicator'
depends_on:
pg-master:
condition: service_healthy

healthcheck:
interval: 60s
timeout: 30s
retries: 3
test: "pg_isready"
2 changes: 1 addition & 1 deletion scenario_tests/streaming_replication/docker-compose-gs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

version: '2.1'
version: '3.9'

volumes:
pg-master-data-dir:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

version: '2.1'

volumes:
pg-master-data-dir:
pg-node-data-dir:

services:
pg-master:
image: 'kartoza/postgis:${TAG:-manual-build}'
restart: 'always'
volumes:
- pg-master-data-dir:/var/lib/postgresql
- ./tests:/tests
- ../utils:/lib/utils
- ./scripts/setup-master.sql:/docker-entrypoint-initdb.d/setup-master.sql
environment:
ALLOW_IP_RANGE: '0.0.0.0/0'
# We can specify optional credentials
POSTGRES_PASS: 'docker'
REPLICATION_USER: 'replicator'
REPLICATION_PASS: 'replicator'
REPLICATION: 'true'
RUN_AS_ROOT: true
healthcheck:
interval: 60s
timeout: 30s
retries: 3
test: "pg_isready"

pg-node:
image: 'kartoza/postgis:${TAG:-manual-build}'
restart: 'always'
volumes:
- pg-node-data-dir:/var/lib/postgresql
- ./tests:/tests
- ../utils:/lib/utils
environment:
ALLOW_IP_RANGE: '0.0.0.0/0'
POSTGRES_PASS: 'docker'
REPLICATE_FROM: 'pg-master'
REPLICATION: 'true'
RUN_AS_ROOT: true
PROMOTE_MASTER: false
DESTROY_DATABASE_ON_RESTART: 'True'
REPLICATION_USER: 'replicator'
REPLICATION_PASS: 'replicator'
depends_on:
pg-master:
condition: service_healthy
healthcheck:
interval: 60s
timeout: 30s
retries: 3
test: "pg_isready"
2 changes: 1 addition & 1 deletion scenario_tests/streaming_replication/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

version: '2.1'
version: '3.9'

volumes:
pg-master-data-dir:
Expand Down
11 changes: 11 additions & 0 deletions scenario_tests/streaming_replication/scripts/setup-master.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Create a table
CREATE TABLE IF NOT EXISTS sweets
(
id SERIAL,
name TEXT,
price DECIMAL,
CONSTRAINT sweets_pkey PRIMARY KEY (id)
);

-- Inserts records into the table
INSERT INTO sweets (name, price) VALUES ('strawberry', 4.50), ('Coffee', 6.20), ('lollipop', 3.80);
67 changes: 65 additions & 2 deletions scenario_tests/streaming_replication/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ if [[ $(dpkg -l | grep "docker-compose") > /dev/null ]];then
VERSION='docker compose'
fi


####
# Run service as root user
####
${VERSION} up -d

if [[ -n "${PRINT_TEST_LOGS}" ]]; then
Expand All @@ -39,7 +40,9 @@ ${VERSION} exec -T pg-node /bin/bash /tests/test_node.sh

${VERSION} down -v

####
# Run service as none root
####
${VERSION} -f docker-compose-gs.yml up -d

if [[ -n "${PRINT_TEST_LOGS}" ]]; then
Expand All @@ -64,4 +67,64 @@ done;
# Execute tests
${VERSION} -f docker-compose-gs.yml exec -T pg-node /bin/bash /tests/test_node.sh

${VERSION} -f docker-compose-gs.yml down -v
${VERSION} -f docker-compose-gs.yml down -v


####
# Run service as root user for node promotion
####
${VERSION} -f docker-compose-root-promote.yml up -d

if [[ -n "${PRINT_TEST_LOGS}" ]]; then
${VERSION} -f docker-compose-root-promote.yml logs -f &
fi

sleep 30

# Update env variable
sed -i 's/\(PROMOTE_MASTER: \)false/\1true/' docker-compose-root-promote.yml

# Bring up node with option to promote node

${VERSION} -f docker-compose-root-promote.yml up -d pg-node

# Preparing node cluster
until ${VERSION} -f docker-compose-root-promote.yml exec -T pg-node pg_isready; do
sleep 30
done;

# Execute tests
${VERSION} -f docker-compose-root-promote.yml exec -T pg-node /bin/bash /tests/test_node_promotion.sh

${VERSION} -f docker-compose-root-promote.yml down -v
sed -i 's/\(PROMOTE_MASTER: \)true/\1false/' docker-compose-root-promote.yml

####
# Run service as none root user for node promotion
####
${VERSION} -f docker-compose-gs-promote.yml up -d

if [[ -n "${PRINT_TEST_LOGS}" ]]; then
${VERSION} -f docker-compose-gs-promote.yml logs -f &
fi

sleep 30

# Update env variable
sed -i 's/\(PROMOTE_MASTER: \)false/\1true/' docker-compose-gs-promote.yml

# Bring up node with option to promote node

${VERSION} -f docker-compose-gs-promote.yml up -d pg-node

# Preparing node cluster
until ${VERSION} -f docker-compose-gs-promote.yml exec -T pg-node pg_isready; do
sleep 30
done;

# Execute tests
${VERSION} -f docker-compose-gs-promote.yml exec -T pg-node /bin/bash /tests/test_node_promotion.sh

${VERSION} -f docker-compose-gs-promote.yml down -v
sed -i 's/\(PROMOTE_MASTER: \)true/\1false/' docker-compose-gs-promote.yml

13 changes: 13 additions & 0 deletions scenario_tests/streaming_replication/tests/test_node_promotion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -e

source /scripts/env-data.sh

# execute tests
pushd /tests

PGHOST=localhost \
PGDATABASE=gis \
PYTHONPATH=/lib \
python3 -m unittest -v test_replication.TestReplicationPromotion
Loading