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

Make export-dir, source and target databases dynamic to enable parallel runs #2019

Merged
merged 26 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f4da0f4
Initial changes to enable parallel tests
shubham-yb Dec 1, 2024
ad054cb
Fixed Sakila and Chinook
shubham-yb Dec 1, 2024
1918713
Test fixes
shubham-yb Dec 1, 2024
335247a
Test fixes
shubham-yb Dec 1, 2024
1ea24a7
Added the usage of SKIP_DB_CREATION
shubham-yb Dec 1, 2024
23942d0
Added the limit to the schema names for Oracle
shubham-yb Dec 2, 2024
7835cd3
Added extra logs for debugging
shubham-yb Dec 3, 2024
41e0b18
Fix log name
shubham-yb Dec 3, 2024
4962c24
Added the NOCACHE clause to the sequences tables
shubham-yb Dec 4, 2024
f903d09
Merge branch 'main' into shubham/unique-export-dir
shubham-yb Dec 8, 2024
eecd0e9
Added uniqueness to ssl tests
shubham-yb Dec 8, 2024
f70ea8b
Merge branch 'main' into shubham/unique-export-dir
shubham-yb Dec 17, 2024
901d774
Fix for missing operand basename error
shubham-yb Dec 18, 2024
d478e31
Added verbose to ora2pg output
shubham-yb Dec 18, 2024
ccece7e
Changed the source db name for PG Partitions with Index test
shubham-yb Dec 19, 2024
fa67610
Use debug with ora2pg commands
shubham-yb Dec 20, 2024
bf31156
Use debug with ora2pg commands
shubham-yb Dec 20, 2024
c6c16bc
Merge branch 'main' into shubham/unique-export-dir
shubham-yb Dec 31, 2024
ff7373a
Cleanup
shubham-yb Dec 31, 2024
be69d26
Merge branch 'main' into shubham/unique-export-dir
shubham-yb Jan 7, 2025
c49b3d1
Review comments
shubham-yb Jan 7, 2025
a9035b7
Merge branch 'main' into shubham/unique-export-dir
shubham-yb Jan 7, 2025
a582746
Cleanup
shubham-yb Jan 7, 2025
0c88b8a
Addressed review comment
shubham-yb Jan 9, 2025
c6fa662
Revert "Addressed review comment"
shubham-yb Jan 9, 2025
dcdc035
Added comments
shubham-yb Jan 9, 2025
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
1 change: 1 addition & 0 deletions .github/workflows/mysql-migtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ jobs:

# Placeholder for now so that a basic test can run
- name: Create the live migration user
if: always()
run: |
mysql -uroot -proot -e 'GRANT SELECT, RELOAD, SHOW DATABASES, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'ybvoyager'@'127.0.0.1';'

Expand Down
3 changes: 2 additions & 1 deletion migtests/lib/yb.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def new_source_db():

def verify_colocation(tgt, source_db_type):
print("Verifying the colocation of the tables")
json_file = "export-dir/assessment/reports/migration_assessment_report.json"
export_dir = os.getenv("EXPORT_DIR", "export-dir")
json_file = f"{export_dir}/assessment/reports/migration_assessment_report.json"

sharded_tables, colocated_tables = fetch_sharded_and_colocated_tables(json_file)

Expand Down
2 changes: 1 addition & 1 deletion migtests/scripts/add-pk-from-alter-to-create
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import os
import re
import shutil

table_file_path = os.getenv('TEST_DIR')+'/export-dir/schema/tables/table.sql'
table_file_path = os.getenv('EXPORT_DIR')+'/schema/tables/table.sql'

#copy the table_file_path to table_file_path+'.old'
src = table_file_path
Expand Down
54 changes: 41 additions & 13 deletions migtests/scripts/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ grant_user_permission_oracle(){
*/
GRANT FLASHBACK ANY TABLE TO ybvoyager;
EOF
run_sqlplus_as_sys ${db_name} "oracle-inputs.sql"
run_sqlplus_as_sys ${db_name} "oracle-inputs.sql"
rm oracle-inputs.sql

}

Expand All @@ -149,6 +150,8 @@ EOF
run_sqlplus_as_sys ${pdb_name} "create-pdb-tablespace.sql"
cp ${SCRIPTS}/oracle/live-grants.sql oracle-inputs.sql
run_sqlplus_as_sys ${cdb_name} "oracle-inputs.sql"
rm create-pdb-tablespace.sql
rm oracle-inputs.sql
}

grant_permissions_for_live_migration_pg() {
Expand Down Expand Up @@ -191,7 +194,7 @@ run_sqlplus_as_sys() {
run_sqlplus_as_schema_owner() {
db_name=$1
sql=$2
conn_string="${SOURCE_DB_USER_SCHEMA_OWNER}/${SOURCE_DB_USER_SCHEMA_OWNER_PASSWORD}@${SOURCE_DB_HOST}:${SOURCE_DB_PORT}/${db_name}"
conn_string="${SOURCE_DB_SCHEMA}/${SOURCE_DB_PASSWORD}@${SOURCE_DB_HOST}:${SOURCE_DB_PORT}/${db_name}"
echo exit | sqlplus -f "${conn_string}" @"${sql}"
}

Expand Down Expand Up @@ -623,16 +626,6 @@ get_value_from_msr(){
echo $val
}

create_ff_schema(){
db_name=$1

cat > create-ff-schema.sql << EOF
CREATE USER FF_SCHEMA IDENTIFIED BY "password";
GRANT all privileges to FF_SCHEMA;
EOF
run_sqlplus_as_sys ${db_name} "create-ff-schema.sql"
}

set_replica_identity(){
db_schema=$1
cat > alter_replica_identity.sql <<EOF
Expand All @@ -647,6 +640,7 @@ set_replica_identity(){
END \$CUSTOM\$;
EOF
run_psql ${SOURCE_DB_NAME} "$(cat alter_replica_identity.sql)"
rm alter_replica_identity.sql
}

grant_permissions_for_live_migration() {
Expand All @@ -673,7 +667,15 @@ grant_permissions_for_live_migration() {
setup_fallback_environment() {
if [ "${SOURCE_DB_TYPE}" = "oracle" ]; then
run_sqlplus_as_sys ${SOURCE_DB_NAME} ${SCRIPTS}/oracle/create_metadata_tables.sql
run_sqlplus_as_sys ${SOURCE_DB_NAME} ${SCRIPTS}/oracle/fall_back_prep.sql

TEMP_SCRIPT="/tmp/fall_back_prep.sql"

sed "s/TEST_SCHEMA/${SOURCE_DB_SCHEMA}/g" ${SCRIPTS}/oracle/fall_back_prep.sql > $TEMP_SCRIPT

run_sqlplus_as_sys ${SOURCE_DB_NAME} $TEMP_SCRIPT

# Clean up the temporary file after execution
rm -f $TEMP_SCRIPT
elif [ "${SOURCE_DB_TYPE}" = "postgresql" ]; then
conn_string="postgresql://${SOURCE_DB_ADMIN_USER}:${SOURCE_DB_ADMIN_PASSWORD}@${SOURCE_DB_HOST}:${SOURCE_DB_PORT}/${SOURCE_DB_NAME}"
psql "${conn_string}" -v voyager_user="${SOURCE_DB_USER}" -v schema_list="${SOURCE_DB_SCHEMA}" -v replication_group='replication_group' -v is_live_migration=1 -v is_live_migration_fall_back=1 -f /opt/yb-voyager/guardrails-scripts/yb-voyager-pg-grant-migration-permissions.sql
Expand Down Expand Up @@ -1044,3 +1046,29 @@ cutover_to_target() {

yb-voyager initiate cutover to target ${args} $*
}

create_source_db() {
source_db=$1
case ${SOURCE_DB_TYPE} in
postgresql)
run_psql postgres "DROP DATABASE IF EXISTS ${source_db};"
run_psql postgres "CREATE DATABASE ${source_db};"
;;
mysql)
run_mysql mysql "DROP DATABASE IF EXISTS ${source_db};"
run_mysql mysql "CREATE DATABASE ${source_db};"
;;
oracle)
cat > create-oracle-schema.sql << EOF
CREATE USER ${source_db} IDENTIFIED BY "password";
GRANT all privileges to ${source_db};
EOF
run_sqlplus_as_sys ${SOURCE_DB_NAME} "create-oracle-schema.sql"
rm create-oracle-schema.sql
;;
*)
echo "ERROR: Source DB not created for ${SOURCE_DB_TYPE}"
exit 1
;;
esac
}
28 changes: 25 additions & 3 deletions migtests/scripts/live-migration-fallb-run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export REPO_ROOT="${PWD}"
export SCRIPTS="${REPO_ROOT}/migtests/scripts"
export TESTS_DIR="${REPO_ROOT}/migtests/tests"
export TEST_DIR="${TESTS_DIR}/${TEST_NAME}"
export EXPORT_DIR=${EXPORT_DIR:-"${TEST_DIR}/export-dir"}
export NORMALIZED_TEST_NAME="$(echo "$TEST_NAME" | tr '/-' '_')"
export QUEUE_SEGMENT_MAX_BYTES=400

export PYTHONPATH="${REPO_ROOT}/migtests/lib"
Expand All @@ -30,13 +30,27 @@ else
source "${TEST_DIR}/env.sh"
fi

export EXPORT_DIR=${EXPORT_DIR:-"${TEST_DIR}/${NORMALIZED_TEST_NAME}_fallb_export-dir"}
if [ -n "${SOURCE_DB_SSL_MODE}" ]; then
EXPORT_DIR="${EXPORT_DIR}_ssl"
fi

if [ "${SOURCE_DB_TYPE}" = "oracle" ]
then
source ${SCRIPTS}/${SOURCE_DB_TYPE}/live_env.sh
else
source ${SCRIPTS}/${SOURCE_DB_TYPE}/env.sh
fi

if [[ "${SOURCE_DB_TYPE}" == "postgresql" || "${SOURCE_DB_TYPE}" == "mysql" ]]; then
export SOURCE_DB_NAME=${SOURCE_DB_NAME:-"${NORMALIZED_TEST_NAME}_fallb"}
elif [[ "${SOURCE_DB_TYPE}" == "oracle" ]]; then
export SOURCE_DB_SCHEMA=${SOURCE_DB_SCHEMA:-"${NORMALIZED_TEST_NAME:0:10}_fallb"} && export SOURCE_DB_SCHEMA=${SOURCE_DB_SCHEMA^^}
Copy link
Collaborator

Choose a reason for hiding this comment

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

why :0:10 ? pls add a comment.
what is ^^?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using ^^ to make the schema uppercase

else
echo "ERROR: Unsupported SOURCE_DB_TYPE: ${SOURCE_DB_TYPE}"
exit 1
fi

source ${SCRIPTS}/yugabytedb/env.sh

source ${SCRIPTS}/functions.sh
Expand All @@ -56,6 +70,10 @@ main() {
pushd ${TEST_DIR}

step "Initialise source database."
if [ "${SOURCE_DB_TYPE}" = "oracle" ]
then
create_source_db ${SOURCE_DB_SCHEMA}
fi
./init-db

step "Grant source database user permissions for live migration"
Expand Down Expand Up @@ -169,7 +187,11 @@ main() {
import_schema --post-snapshot-import true --refresh-mviews=true

step "Run snapshot validations."
"${TEST_DIR}/validate" --live_migration 'true' --ff_enabled 'false' --fb_enabled 'true'
"${TEST_DIR}/validate" --live_migration 'true' --ff_enabled 'false' --fb_enabled 'true' || {
tail_log_file "yb-voyager-import-data.log"
tail_log_file "yb-voyager-export-data-from-source.log"
exit 1
}

step "Inserting new events"
run_sql_file source_delta.sql
Expand Down Expand Up @@ -264,7 +286,7 @@ main() {

step "Clean up"
./cleanup-db
rm -rf "${EXPORT_DIR}/*"
rm -rf "${EXPORT_DIR}"
run_ysql yugabyte "DROP DATABASE IF EXISTS ${TARGET_DB_NAME};"
}

Expand Down
28 changes: 24 additions & 4 deletions migtests/scripts/live-migration-fallf-run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export REPO_ROOT="${PWD}"
export SCRIPTS="${REPO_ROOT}/migtests/scripts"
export TESTS_DIR="${REPO_ROOT}/migtests/tests"
export TEST_DIR="${TESTS_DIR}/${TEST_NAME}"
export EXPORT_DIR=${EXPORT_DIR:-"${TEST_DIR}/export-dir"}
export NORMALIZED_TEST_NAME="$(echo "$TEST_NAME" | tr '/-' '_')"
Copy link
Collaborator

Choose a reason for hiding this comment

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

where do we get TEST_NAME from to begin with?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TEST_NAME is passed during the test invocation.
The general pattern is TEST_SCRIPT TEST_NAME
example: run_test.sh pg/datatypes


export PYTHONPATH="${REPO_ROOT}/migtests/lib"
export PATH="${PATH}:/usr/lib/oracle/21/client64/bin"
Expand All @@ -31,13 +31,27 @@ else
source "${TEST_DIR}/env.sh"
fi

export EXPORT_DIR=${EXPORT_DIR:-"${TEST_DIR}/${NORMALIZED_TEST_NAME}_fallf_export-dir"}
if [ -n "${SOURCE_DB_SSL_MODE}" ]; then
EXPORT_DIR="${EXPORT_DIR}_ssl"
fi

if [ "${SOURCE_DB_TYPE}" = "oracle" ]
then
source ${SCRIPTS}/${SOURCE_DB_TYPE}/live_env.sh
else
source ${SCRIPTS}/${SOURCE_DB_TYPE}/env.sh
fi

if [[ "${SOURCE_DB_TYPE}" == "postgresql" || "${SOURCE_DB_TYPE}" == "mysql" ]]; then
export SOURCE_DB_NAME=${SOURCE_DB_NAME:-"${NORMALIZED_TEST_NAME}_fallf"}
elif [[ "${SOURCE_DB_TYPE}" == "oracle" ]]; then
export SOURCE_DB_SCHEMA=${SOURCE_DB_SCHEMA:-"${NORMALIZED_TEST_NAME:0:10}_fallf"} && export SOURCE_DB_SCHEMA=${SOURCE_DB_SCHEMA^^}
else
echo "ERROR: Unsupported SOURCE_DB_TYPE: ${SOURCE_DB_TYPE}"
exit 1
fi

source ${SCRIPTS}/${SOURCE_DB_TYPE}/ff_env.sh

source ${SCRIPTS}/yugabytedb/env.sh
Expand All @@ -62,7 +76,8 @@ main() {

if [ "${SOURCE_DB_TYPE}" = "oracle" ]
then
create_ff_schema ${SOURCE_REPLICA_DB_NAME}
create_source_db ${SOURCE_DB_SCHEMA}
create_source_db ${SOURCE_REPLICA_DB_SCHEMA}
run_sqlplus_as_sys ${SOURCE_REPLICA_DB_NAME} ${SCRIPTS}/oracle/create_metadata_tables.sql
fi
./init-db
Expand Down Expand Up @@ -206,7 +221,12 @@ main() {
import_schema --post-snapshot-import true --refresh-mviews true

step "Run snapshot validations."
"${TEST_DIR}/validate" --live_migration 'true' --ff_enabled 'true' --fb_enabled 'false'
"${TEST_DIR}/validate" --live_migration 'true' --ff_enabled 'true' --fb_enabled 'false' || {
tail_log_file "yb-voyager-import-data.log"
tail_log_file "yb-voyager-export-data-from-source.log"
tail_log_file "yb-voyager-import-data-to-source-replica.log"
exit 1
}

step "Inserting new events to source"
run_sql_file source_delta.sql
Expand Down Expand Up @@ -286,7 +306,7 @@ main() {

step "Clean up"
./cleanup-db
rm -rf "${EXPORT_DIR}/*"
rm -rf "${EXPORT_DIR}"
run_ysql yugabyte "DROP DATABASE IF EXISTS ${TARGET_DB_NAME};"
}

Expand Down
22 changes: 20 additions & 2 deletions migtests/scripts/live-migration-run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export REPO_ROOT="${PWD}"
export SCRIPTS="${REPO_ROOT}/migtests/scripts"
export TESTS_DIR="${REPO_ROOT}/migtests/tests"
export TEST_DIR="${TESTS_DIR}/${TEST_NAME}"
export EXPORT_DIR=${EXPORT_DIR:-"${TEST_DIR}/export-dir"}
export NORMALIZED_TEST_NAME="$(echo "$TEST_NAME" | tr '/-' '_')"
export QUEUE_SEGMENT_MAX_BYTES=400

export PYTHONPATH="${REPO_ROOT}/migtests/lib"
Expand All @@ -37,6 +37,20 @@ else
source ${SCRIPTS}/${SOURCE_DB_TYPE}/env.sh
fi

export EXPORT_DIR=${EXPORT_DIR:-"${TEST_DIR}/${NORMALIZED_TEST_NAME}_live_export-dir"}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like this code is the same for all tests?
if so, can we write this logic in functions.sh? (for determining exportDir, setting SOURCE_DB_NAME, etc.

if [ -n "${SOURCE_DB_SSL_MODE}" ]; then
EXPORT_DIR="${EXPORT_DIR}_ssl"
fi

if [[ "${SOURCE_DB_TYPE}" == "postgresql" || "${SOURCE_DB_TYPE}" == "mysql" ]]; then
export SOURCE_DB_NAME=${SOURCE_DB_NAME:-"${NORMALIZED_TEST_NAME}_live"}
elif [[ "${SOURCE_DB_TYPE}" == "oracle" ]]; then
export SOURCE_DB_SCHEMA=${SOURCE_DB_SCHEMA:-"${NORMALIZED_TEST_NAME:0:10}_live"} && export SOURCE_DB_SCHEMA=${SOURCE_DB_SCHEMA^^}
else
echo "ERROR: Unsupported SOURCE_DB_TYPE: ${SOURCE_DB_TYPE}"
exit 1
fi

source ${SCRIPTS}/yugabytedb/env.sh

source ${SCRIPTS}/functions.sh
Expand All @@ -56,6 +70,10 @@ main() {
pushd ${TEST_DIR}

step "Initialise source database."
if [ "${SOURCE_DB_TYPE}" = "oracle" ]
then
create_source_db ${SOURCE_DB_SCHEMA}
fi
./init-db

step "Grant source database user permissions for live migration"
Expand Down Expand Up @@ -218,7 +236,7 @@ main() {

step "Clean up"
./cleanup-db
rm -rf "${EXPORT_DIR}/*"
rm -rf "${EXPORT_DIR}"
run_ysql yugabyte "DROP DATABASE IF EXISTS ${TARGET_DB_NAME};"
}

Expand Down
2 changes: 1 addition & 1 deletion migtests/scripts/run-schema-migration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ main() {

step "Clean up"
./cleanup-db
rm -rf "${EXPORT_DIR}/*"
rm -rf "${EXPORT_DIR}"
run_ysql yugabyte "DROP DATABASE IF EXISTS ${TARGET_DB_NAME};"
}

Expand Down
2 changes: 1 addition & 1 deletion migtests/scripts/run-test-export-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ main() {

step "Clean up"
./cleanup-db
rm -rf "${EXPORT_DIR}/*"
rm -rf "${EXPORT_DIR}"
run_ysql yugabyte "DROP DATABASE IF EXISTS ${TARGET_DB_NAME};"
}

Expand Down
33 changes: 30 additions & 3 deletions migtests/scripts/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export REPO_ROOT="${PWD}"
export SCRIPTS="${REPO_ROOT}/migtests/scripts"
export TESTS_DIR="${REPO_ROOT}/migtests/tests"
export TEST_DIR="${TESTS_DIR}/${TEST_NAME}"
export EXPORT_DIR=${EXPORT_DIR:-"${TEST_DIR}/export-dir"}
export NORMALIZED_TEST_NAME="$(echo "$TEST_NAME" | tr '/-' '_')"

export PYTHONPATH="${REPO_ROOT}/migtests/lib"

Expand All @@ -33,9 +33,24 @@ then
else
source ${TEST_DIR}/env.sh
fi

source ${SCRIPTS}/${SOURCE_DB_TYPE}/env.sh
source ${SCRIPTS}/yugabytedb/env.sh

export EXPORT_DIR=${EXPORT_DIR:-"${TEST_DIR}/${NORMALIZED_TEST_NAME}_offline_export-dir"}
if [ -n "${SOURCE_DB_SSL_MODE}" ]; then
EXPORT_DIR="${EXPORT_DIR}_ssl"
fi

if [[ "${SOURCE_DB_TYPE}" == "postgresql" || "${SOURCE_DB_TYPE}" == "mysql" ]]; then
export SOURCE_DB_NAME=${SOURCE_DB_NAME:-"${NORMALIZED_TEST_NAME}_offline"}
elif [[ "${SOURCE_DB_TYPE}" == "oracle" ]]; then
export SOURCE_DB_SCHEMA=${SOURCE_DB_SCHEMA:-"${NORMALIZED_TEST_NAME:0:10}_offline"} && export SOURCE_DB_SCHEMA=${SOURCE_DB_SCHEMA^^}
else
echo "ERROR: Unsupported SOURCE_DB_TYPE: ${SOURCE_DB_TYPE}"
exit 1
fi

source ${SCRIPTS}/yugabytedb/env.sh
source ${SCRIPTS}/functions.sh

main() {
Expand All @@ -52,6 +67,18 @@ main() {
pushd ${TEST_DIR}

step "Initialise source database."
if [[ "${SKIP_DB_CREATION}" != "true" ]]; then
if [[ "${SOURCE_DB_TYPE}" == "postgresql" || "${SOURCE_DB_TYPE}" == "mysql" ]]; then
create_source_db "${SOURCE_DB_NAME}"
elif [[ "${SOURCE_DB_TYPE}" == "oracle" ]]; then
create_source_db "${SOURCE_DB_SCHEMA}"
else
echo "ERROR: Unsupported SOURCE_DB_TYPE: ${SOURCE_DB_TYPE}"
exit 1
fi
else
echo "Skipping database creation as SKIP_DB_CREATION is set to true."
fi
./init-db

step "Grant source database user permissions"
Expand Down Expand Up @@ -190,7 +217,7 @@ main() {

step "Clean up"
./cleanup-db
rm -rf "${EXPORT_DIR}/*"
rm -rf "${EXPORT_DIR}"
run_ysql yugabyte "DROP DATABASE IF EXISTS ${TARGET_DB_NAME};"
}

Expand Down
Loading