From 723a21e091a22397ece008866bd3bf4458d3fe13 Mon Sep 17 00:00:00 2001 From: Bhuvnesh Chaudhary Date: Tue, 18 Feb 2020 16:21:59 -0800 Subject: [PATCH] Add test --- contrib/pg_upgrade/greenplum/check_gp.c | 8 ++- .../integration/configuration/gpdb5-env.sh | 3 +- .../test/integration/gpdb5_schedule | 1 + .../integration/input/preferred_roles.source | 40 +++++++++++ .../integration/output/preferred_roles.source | 66 +++++++++++++++++++ contrib/pg_upgrade/test/integration/test.sh | 5 +- 6 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 contrib/pg_upgrade/test/integration/input/preferred_roles.source create mode 100644 contrib/pg_upgrade/test/integration/output/preferred_roles.source diff --git a/contrib/pg_upgrade/greenplum/check_gp.c b/contrib/pg_upgrade/greenplum/check_gp.c index 91519db053..f104ecc4bd 100644 --- a/contrib/pg_upgrade/greenplum/check_gp.c +++ b/contrib/pg_upgrade/greenplum/check_gp.c @@ -919,6 +919,12 @@ check_preferred_roles(void) int content; PGconn *conn; + /* + * We only need to check the segment roles on master + */ + if (!is_greenplum_dispatcher_mode()) + return; + prep_status("Checking for segments not in preferred role"); snprintf(output_path, sizeof(output_path), "segment_roles_switched.txt"); @@ -968,4 +974,4 @@ check_preferred_roles(void) else check_ok(); -} \ No newline at end of file +} diff --git a/contrib/pg_upgrade/test/integration/configuration/gpdb5-env.sh b/contrib/pg_upgrade/test/integration/configuration/gpdb5-env.sh index 5a24ca87e0..c047832eb8 100644 --- a/contrib/pg_upgrade/test/integration/configuration/gpdb5-env.sh +++ b/contrib/pg_upgrade/test/integration/configuration/gpdb5-env.sh @@ -2,4 +2,5 @@ export MASTER_PORT=50000 export STANDBY_PORT=50001 export PORT_BASE=50002 export DATADIRS="$PWD/gpdb5-data" -export PGPORT=50000 \ No newline at end of file +export PGPORT=50000 +export MASTER_DATA_DIRECTORY="$DATADIRS/qddir/demoDataDir-1" diff --git a/contrib/pg_upgrade/test/integration/gpdb5_schedule b/contrib/pg_upgrade/test/integration/gpdb5_schedule index d97eac218b..0dd4e0cf14 100644 --- a/contrib/pg_upgrade/test/integration/gpdb5_schedule +++ b/contrib/pg_upgrade/test/integration/gpdb5_schedule @@ -9,3 +9,4 @@ test: unsupported_tsquery_col test: gphdfs test: mismatched_aopartition_indexes test: different_name_index_backed_constraint +test: preferred_roles diff --git a/contrib/pg_upgrade/test/integration/input/preferred_roles.source b/contrib/pg_upgrade/test/integration/input/preferred_roles.source new file mode 100644 index 0000000000..9ad756a527 --- /dev/null +++ b/contrib/pg_upgrade/test/integration/input/preferred_roles.source @@ -0,0 +1,40 @@ +-- start_ignore +create language plpythonu; +-- end_ignore + + +-- stop a primary in order to trigger a mirror promotion +create or replace function stop_segment(datadir text) +returns text as $$ + import subprocess + cmd = 'pg_ctl -l postmaster.log -D %s -w -m immediate stop' % datadir + return subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).replace('.', '') +$$ language plpythonu; + + +-- function to wait for a segment to take a role +create or replace function wait_for_content0(target_mode char) /*in func*/ returns void as $$ /*in func*/ declare /*in func*/ iterations int := 0; /*in func*/ begin /*in func*/ while iterations < 120 loop /*in func*/ perform pg_sleep(1); /*in func*/ if exists (select * from gp_segment_configuration where content = 0 and mode = target_mode) then /*in func*/ return; /*in func*/ end if; /*in func*/ iterations := iterations + 1; /*in func*/ end loop; /*in func*/ end $$ /*in func*/ language plpgsql; + + +checkpoint; +-- the check should not return any failure +! ./gpdb6/bin/pg_upgrade --mode=dispatcher --old-gp-dbid=1 --new-gp-dbid=1 --check --old-bindir=@upgrade_test_path@/gpdb5/bin --new-bindir=@upgrade_test_path@/gpdb6/bin --old-datadir=@upgrade_test_path@/gpdb5-data/qddir/demoDataDir-1 --new-datadir=@upgrade_test_path@/gpdb6-data/qddir/demoDataDir-1 --old-port=@old_port@; + +-- Stop content 0 primary and let the mirror take over +select stop_segment(fselocation) from pg_filespace_entry fe, gp_segment_configuration c, pg_filespace f +where fe.fsedbid = c.dbid and c.content=0 and c.role='p' and f.oid = fe.fsefsoid and f.fsname = 'pg_system'; + +select wait_for_content0('c'); + +-- one of the segment has switched role, the check should catch it +! ./gpdb6/bin/pg_upgrade --mode=dispatcher --old-gp-dbid=1 --new-gp-dbid=1 --check --old-bindir=@upgrade_test_path@/gpdb5/bin --new-bindir=@upgrade_test_path@/gpdb6/bin --old-datadir=@upgrade_test_path@/gpdb5-data/qddir/demoDataDir-1 --new-datadir=@upgrade_test_path@/gpdb6-data/qddir/demoDataDir-1 --old-port=@old_port@; + +-- start_ignore +! ./gpdb5/bin/gprecoverseg -a -d @upgrade_test_path@/gpdb5-data/qddir/demoDataDir-1; + +select wait_for_content0('s'); + +! ./gpdb5/bin/gprecoverseg -a -r -d @upgrade_test_path@/gpdb5-data/qddir/demoDataDir-1; + +select wait_for_content0('s'); +-- end_ignore diff --git a/contrib/pg_upgrade/test/integration/output/preferred_roles.source b/contrib/pg_upgrade/test/integration/output/preferred_roles.source new file mode 100644 index 0000000000..532a5d5683 --- /dev/null +++ b/contrib/pg_upgrade/test/integration/output/preferred_roles.source @@ -0,0 +1,66 @@ +-- start_ignore +create language plpythonu; +-- end_ignore + + +-- stop a primary in order to trigger a mirror promotion +create or replace function stop_segment(datadir text) returns text as $$ import subprocess cmd = 'pg_ctl -l postmaster.log -D %s -w -m immediate stop' % datadir return subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).replace('.', '') $$ language plpythonu; +CREATE + + +-- function to wait for a segment to take a role +create or replace function wait_for_content0(target_mode char) /*in func*/ returns void as $$ /*in func*/ declare /*in func*/ iterations int := 0; /*in func*/ begin /*in func*/ while iterations < 120 loop /*in func*/ perform pg_sleep(1); /*in func*/ if exists (select * from gp_segment_configuration where content = 0 and mode = target_mode) then /*in func*/ return; /*in func*/ end if; /*in func*/ iterations := iterations + 1; /*in func*/ end loop; /*in func*/ end $$ /*in func*/ language plpgsql; +CREATE + + +checkpoint; +CHECKPOINT +-- the check should not return any failure +! ./gpdb6/bin/pg_upgrade --mode=dispatcher --old-gp-dbid=1 --new-gp-dbid=1 --check --old-bindir=@upgrade_test_path@/gpdb5/bin --new-bindir=@upgrade_test_path@/gpdb6/bin --old-datadir=@upgrade_test_path@/gpdb5-data/qddir/demoDataDir-1 --new-datadir=@upgrade_test_path@/gpdb6-data/qddir/demoDataDir-1 --old-port=@old_port@; +Performing Consistency Checks on Old Live Server +------------------------------------------------ +Creating a dump of all tablespace metadata. ok + +*Clusters are compatible* + + +-- Stop content 0 primary and let the mirror take over +select stop_segment(fselocation) from pg_filespace_entry fe, gp_segment_configuration c, pg_filespace f where fe.fsedbid = c.dbid and c.content=0 and c.role='p' and f.oid = fe.fsefsoid and f.fsname = 'pg_system'; + stop_segment +------------------------------------------------------ + waiting for server to shut down done +server stopped + +(1 row) + +select wait_for_content0('c'); + wait_for_content0 +------------------- + +(1 row) + +-- one of the segment has switched role, the check should catch it +! ./gpdb6/bin/pg_upgrade --mode=dispatcher --old-gp-dbid=1 --new-gp-dbid=1 --check --old-bindir=@upgrade_test_path@/gpdb5/bin --new-bindir=@upgrade_test_path@/gpdb6/bin --old-datadir=@upgrade_test_path@/gpdb5-data/qddir/demoDataDir-1 --new-datadir=@upgrade_test_path@/gpdb6-data/qddir/demoDataDir-1 --old-port=@old_port@; +Performing Consistency Checks on Old Live Server +------------------------------------------------ +Creating a dump of all tablespace metadata. ok +Checking for segments not in preferred roles fatal + +| The segments should be in their preferred roles for upgrade. +| Segments not operating in the preferred roles must be recovered +| and/or rebalanced using gprecoverseg. The list of such segments +| is in the file: + segment_roles_switched.txt + +Failure, exiting + + +-- start_ignore +! ./gpdb5/bin/gprecoverseg -a -d @upgrade_test_path@/gpdb5-data/qddir/demoDataDir-1; + +select wait_for_content0('s'); + +! ./gpdb5/bin/gprecoverseg -a -r -d @upgrade_test_path@/gpdb5-data/qddir/demoDataDir-1; + +select wait_for_content0('s'); +-- end_ignore diff --git a/contrib/pg_upgrade/test/integration/test.sh b/contrib/pg_upgrade/test/integration/test.sh index 8bda7e4884..ba53e25705 100755 --- a/contrib/pg_upgrade/test/integration/test.sh +++ b/contrib/pg_upgrade/test/integration/test.sh @@ -13,7 +13,7 @@ main() { local new_port=60000 # need python for sql isolation test modules. - source gpdb6/greenplum_path.sh + source gpdb5/greenplum_path.sh if [ $# -eq 0 ] then @@ -34,6 +34,9 @@ main() { --old-port=$old_port \ $gpdb5_input ./scripts/gpdb5-cluster stop + # need python for sql isolation test modules. + source gpdb6/greenplum_path.sh + ./scripts/upgrade-cluster ./scripts/gpdb6-cluster start ./pg_upgrade_regress --use-existing \ -- GitLab