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 for fast/cold-boot: call db_migrator only after old config is loaded #14933

Merged
merged 1 commit into from
May 30, 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
16 changes: 12 additions & 4 deletions files/build_templates/docker_image_ctl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,18 @@ function postStartAction()
$SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
fi

if [[ -x /usr/local/bin/db_migrator.py ]]; then
# Migrate the DB to the latest schema version if needed
if [ -z "$DEV" ]; then
/usr/local/bin/db_migrator.py -o migrate
if [ -e /tmp/pending_config_migration ]; then
# this is first boot to a new image, config-setup execution is pending.
# For fast/cold reboot case, DB contains nothing at this point
# Call db_migrator after config-setup loads the config (from old config or minigraph)
echo "Delaying db_migrator until config migration is over"
else
# this is not a first time boot to a new image. Datbase container starts w/ old pre-existing config
if [[ -x /usr/local/bin/db_migrator.py ]]; then
# Migrate the DB to the latest schema version if needed
if [ -z "$DEV" ]; then
/usr/local/bin/db_migrator.py -o migrate
fi
fi
fi
# Add redis UDS to the redis group and give read/write access to the group
Expand Down
13 changes: 13 additions & 0 deletions files/image_config/config-setup/config-setup
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,16 @@ check_all_config_db_present()
return 0
}

# DB schema is subject to change between two images
# Perform DB schema migration after loading backup config from previous image
do_db_migration()
{
if [[ -x /usr/local/bin/db_migrator.py ]]; then
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@judyjoseph can you please review this part of change from multi DB namespace point of view.

With this change db_migrator will get called always. Earlier you ignored migration as part of #4477

Why would db_migrator be skipped for multi db?

Copy link
Contributor

Choose a reason for hiding this comment

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

@vaibhavhd the db_migrator should run fine for multi-asic config _db's too. I see the VERSIONS table with DATABASE version in multi-asic config _db's, hence it should work as it works for single asic config_db.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, Judy! @yxieca we should be good to go ahead with this change. Can you please re-review.

# Migrate the DB to the latest schema version if needed
/usr/local/bin/db_migrator.py -o migrate
fi
}

# Perform configuration migration from backup copy.
# - This step is performed when a new image is installed and SONiC switch boots into it
do_config_migration()
Expand All @@ -322,16 +332,19 @@ do_config_migration()
if [ x"${WARM_BOOT}" == x"true" ]; then
echo "Warm reboot detected..."
disable_updategraph
do_db_migration
rm -f /tmp/pending_config_migration
exit 0
elif check_all_config_db_present; then
echo "Use config_db.json from old system..."
reload_configdb
do_db_migration
# Disable updategraph
disable_updategraph
elif [ -r ${MINGRAPH_FILE} ]; then
echo "Use minigraph.xml from old system..."
reload_minigraph
do_db_migration
# Disable updategraph
disable_updategraph
else
Expand Down