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

Add a test for master restart after being killed #133

Merged
merged 3 commits into from
Sep 6, 2016

Conversation

pkubatrh
Copy link
Member

@pkubatrh pkubatrh commented Aug 31, 2016

This PR adds a simple test to check if a master can be properly restarted after being killed in a replication scenario.
First commit makes some necessary changes to existing test code while the second commit adds the actual test.

@openshift-bot
Copy link
Collaborator

Can one of the admins verify this patch?

@pkubatrh
Copy link
Member Author

[test]

1 similar comment
@bparees
Copy link
Collaborator

bparees commented Aug 31, 2016

[test]

@praiskup
Copy link
Contributor

Thanks. I wouldn't use a word "failover" as that usually means different usecase in PostgreSQL context. I'll do a better review tomorrow.

for cidfile in $CIDFILE_DIR/* ; do
CONTAINER=$(cat $cidfile)

cleanup_container
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move this into the second patch, otherwise this "function split" looks like
unnecessary (when somebody looks at the patch separately).

@praiskup
Copy link
Contributor

praiskup commented Sep 1, 2016

Ah, reading the patch carefully, there really is failover scenario tested (that is, however, probably not usable in OpenShift at least ATM).

@praiskup
Copy link
Contributor

praiskup commented Sep 1, 2016

IOW: promoting slave container to master container is hard task enough to rather start new
master...

@pkubatrh pkubatrh force-pushed the master branch 6 times, most recently from ac593e5 to e300684 Compare September 1, 2016 09:02
@pkubatrh pkubatrh changed the title Add a test for failover scenario Add a test for master restart after being killed Sep 1, 2016
@pkubatrh
Copy link
Member Author

pkubatrh commented Sep 1, 2016

Updated the PR with a new test case (master restart instead of failover).

local value
value=24
# Do some real work to test replication in practice
postgresql_cmd -c "CREATE TABLE t1 (a integer); INSERT INTO t1 VALUES ($value);"
local table_name="t1"
Copy link
Contributor

Choose a reason for hiding this comment

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

This overwrites previous variable assignment.

@pkubatrh
Copy link
Member Author

pkubatrh commented Sep 1, 2016

New push, fixed issues pointed out by @praiskup (overwritten variable + added a comment to global variable)

for f in `find ${CIDFILE_DIR} -type f -name "slave-*"`; do
cidfile=$(basename $f)
slave_ip=$(get_container_ip $cidfile)
CONTAINER_IP=$slave_ip
for i in $(seq $max_attempts); do
result="$(postgresql_cmd -At -c "select * from t1")"
result="$(postgresql_cmd -At -c "select * from $table_name")"
if [[ ! -z "${result}" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably OK, but I would rather fix it sooner than later ... checking psql output
for (non)empty-ness is not perfect, because error messages comes to standard output ->
thus empty string comes from invalid query. We are fine because 'set -e' is activated ..
but that could change in future... I would vote for explicit string to compare $result with.

@pkubatrh pkubatrh force-pushed the master branch 2 times, most recently from ba55e85 to b4ab64c Compare September 1, 2016 11:41
@pkubatrh
Copy link
Member Author

pkubatrh commented Sep 1, 2016

Rewrote non-emptyness check into an expected value check, max_attempts variable no longer global.

docker stop $(cat $cidfile)
local rm_cmd='/bin/rm -rf /var/lib/pgsql/data/*'
docker run $master_args --rm $IMAGE_NAME /bin/sh -c "$rm_cmd"
rmdir ${volume_dir}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, can we do this at one place (looks like code duplication).

@@ -265,7 +265,8 @@ function run_slave() {

function run_master() {
local suffix="$1"; shift
docker run $cluster_args -p 5432 \
master_args=${master_args-}
docker run $cluster_args $master_args -p 5432 \
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still not sure whether we need to '-p 5432'.

@pkubatrh
Copy link
Member Author

pkubatrh commented Sep 5, 2016

Incorporated @praiskup's suggestions - new functions for the creation and removal of volumes, got rid of some redundant local variables, changed loops to use container IDs instead of calling 'find' on .cid files.

@praiskup
Copy link
Contributor

praiskup commented Sep 5, 2016

Weird. On my Fedora 24 box, running 'make test VERSION=9.4' fails very early with:

  • timeout -s 9 --preserve-status 60s docker run --rm -e POSTGRESQL_USER=user -e POSTGRESQL_PASSWORD=pass centos/postgresql-94-centos7-candidate
    /bin/bash: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: Permission denied

Actually, the docker build created unusable image, the source 'centos:centos7' works fine.

@praiskup
Copy link
Contributor

praiskup commented Sep 5, 2016

[test]

@praiskup
Copy link
Contributor

praiskup commented Sep 6, 2016

My mistake, more info in #136, I'll continue with the review.

@@ -309,7 +328,7 @@ function test_value_replication() {
CONTAINER_IP=$slave_ip
for i in $(seq $max_attempts); do
result="$(postgresql_cmd -At -c "select * from $table_name")"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure the loop here has some effect. When the value is not there yet, it is
very likely the $table_name table does not exist yet too. Then, postgresql_cmd fails
and this would fail the whole command, so no other attempt would me made.

Probably || : is missing.

Copy link
Contributor

Choose a reason for hiding this comment

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

s/fail the whole command/exit the whole script/

@pkubatrh
Copy link
Member Author

pkubatrh commented Sep 6, 2016

Pushed new changes - ignore psql errors when checking for value replication, master_args variable now local

@praiskup
Copy link
Contributor

praiskup commented Sep 6, 2016

LGTM.

@praiskup
Copy link
Contributor

praiskup commented Sep 6, 2016

@pkubatrh looks like this is pretty atomic change, would it be fine to squash the commits?

@bparees bparees merged commit 4a70862 into sclorg:master Sep 6, 2016
@bparees
Copy link
Collaborator

bparees commented Sep 6, 2016

squash merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants