Skip to content

Commit 6e705dd

Browse files
vaibhavhdqiluo-msft
authored andcommitted
Fix for fast/cold-boot: call db_migrator only after old config is loaded (#14933)
Why I did it Fix the issue where db_migrator is called before DB is loaded w/ config. This leads to db_migrator: Not finding anything, and resumes to incorrectly migrate every missing config This is not expected. migration should happen after the old config is loaded and only new schema changes need migration. Since DB does not have anything when migrator is called, db_migrator fails when some APIs return None. The reason for incorrect call is that: database service starts db_migrator as part of startup sequence. config-setup service loads data from old-config/minigraph. However, since it has Requires=database.service. Hence, config-setup starts only when database service is started. And database service is started when db_migrator is completed. Fixed by: Check if this is first time boot by checking pending_config_migration flag. If pending_config_migration is enabled, then do not call db_migrator as part of database service startup. Let database service start which triggers config-setup service to start. Now call db_migrator after when config-setup service loads old-config/minigraph
1 parent 0b6ee2d commit 6e705dd

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

files/build_templates/docker_image_ctl.j2

+12-4
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,18 @@ function postStartAction()
135135
$SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
136136
fi
137137

138-
if [[ -x /usr/local/bin/db_migrator.py ]]; then
139-
# Migrate the DB to the latest schema version if needed
140-
if [ -z "$DEV" ]; then
141-
/usr/local/bin/db_migrator.py -o migrate
138+
if [ -e /tmp/pending_config_migration ]; then
139+
# this is first boot to a new image, config-setup execution is pending.
140+
# For fast/cold reboot case, DB contains nothing at this point
141+
# Call db_migrator after config-setup loads the config (from old config or minigraph)
142+
echo "Delaying db_migrator until config migration is over"
143+
else
144+
# this is not a first time boot to a new image. Datbase container starts w/ old pre-existing config
145+
if [[ -x /usr/local/bin/db_migrator.py ]]; then
146+
# Migrate the DB to the latest schema version if needed
147+
if [ -z "$DEV" ]; then
148+
/usr/local/bin/db_migrator.py -o migrate
149+
fi
142150
fi
143151
fi
144152
# Add redis UDS to the redis group and give read/write access to the group

files/image_config/config-setup/config-setup

+13
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,16 @@ check_all_config_db_present()
298298
return 0
299299
}
300300

301+
# DB schema is subject to change between two images
302+
# Perform DB schema migration after loading backup config from previous image
303+
do_db_migration()
304+
{
305+
if [[ -x /usr/local/bin/db_migrator.py ]]; then
306+
# Migrate the DB to the latest schema version if needed
307+
/usr/local/bin/db_migrator.py -o migrate
308+
fi
309+
}
310+
301311
# Perform configuration migration from backup copy.
302312
# - This step is performed when a new image is installed and SONiC switch boots into it
303313
do_config_migration()
@@ -320,16 +330,19 @@ do_config_migration()
320330
if [ x"${WARM_BOOT}" == x"true" ]; then
321331
echo "Warm reboot detected..."
322332
disable_updategraph
333+
do_db_migration
323334
rm -f /tmp/pending_config_migration
324335
exit 0
325336
elif check_all_config_db_present; then
326337
echo "Use config_db.json from old system..."
327338
reload_configdb
339+
do_db_migration
328340
# Disable updategraph
329341
disable_updategraph
330342
elif [ -r ${MINGRAPH_FILE} ]; then
331343
echo "Use minigraph.xml from old system..."
332344
reload_minigraph
345+
do_db_migration
333346
# Disable updategraph
334347
disable_updategraph
335348
else

0 commit comments

Comments
 (0)