-
Notifications
You must be signed in to change notification settings - Fork 12
Make export-dir, source and target databases dynamic to enable parallel runs #2019
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
Changes from all commits
f4da0f4
ad054cb
1918713
335247a
1ea24a7
23942d0
7835cd3
41e0b18
4962c24
f903d09
eecd0e9
f70ea8b
901d774
d478e31
ccece7e
fa67610
bf31156
c6c16bc
ff7373a
be69d26
c49b3d1
a9035b7
a582746
0c88b8a
c6fa662
dcdc035
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
} | ||
|
||
|
@@ -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() { | ||
|
@@ -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}" | ||
} | ||
|
||
|
@@ -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 | ||
|
@@ -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() { | ||
|
@@ -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 | ||
|
@@ -1044,3 +1046,60 @@ 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 | ||
} | ||
|
||
normalize_and_export_vars() { | ||
local test_suffix=$1 | ||
|
||
# Normalize TEST_NAME | ||
# Keeping the full name for PG and MySQL to test out large schema/export dir names | ||
export NORMALIZED_TEST_NAME="$(echo "$TEST_NAME" | tr '/-' '_')" | ||
|
||
# Set EXPORT_DIR | ||
export EXPORT_DIR=${EXPORT_DIR:-"${TEST_DIR}/${NORMALIZED_TEST_NAME}_${test_suffix}_export-dir"} | ||
if [ -n "${SOURCE_DB_SSL_MODE}" ]; then | ||
EXPORT_DIR="${EXPORT_DIR}_ssl" | ||
fi | ||
|
||
# Set database-specific variables | ||
case "${SOURCE_DB_TYPE}" in | ||
postgresql|mysql) | ||
export SOURCE_DB_NAME=${SOURCE_DB_NAME:-"${NORMALIZED_TEST_NAME}_${test_suffix}"} | ||
;; | ||
oracle) | ||
# Limit schema name to 10 characters for Oracle/Debezium due to 30 character limit | ||
# Since test_suffix is the unique identifying factor, we need to add it post all the normalization | ||
export SOURCE_DB_SCHEMA=${SOURCE_DB_SCHEMA:-"${NORMALIZED_TEST_NAME:0:10}_${test_suffix}"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: you can do the truncate 0:10 also above when generating NORMALIZED_TEST_NAME. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keeping it specific to Oracle for now. The longer export-dir name brought out some issues. It'll be good to have that test case. |
||
export SOURCE_DB_SCHEMA=${SOURCE_DB_SCHEMA^^} | ||
;; | ||
*) | ||
echo "ERROR: Unsupported SOURCE_DB_TYPE: ${SOURCE_DB_TYPE}" | ||
exit 1 | ||
;; | ||
esac | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,7 +94,7 @@ main() { | |
|
||
step "Clean up" | ||
./cleanup-db | ||
rm -rf "${EXPORT_DIR}/*" | ||
rm -rf "${EXPORT_DIR}" | ||
} | ||
|
||
main |
Uh oh!
There was an error while loading. Please reload this page.