Skip to content

Commit 5d5727f

Browse files
authored
Revert "Revert "Fix for fast/cold-boot: call db_migrator only after old config is loaded (#14933)" (#15464)" (#15684) (#16223)
1 parent 32a52a1 commit 5d5727f

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)