Skip to content

Commit e52c2c2

Browse files
vaibhavhdmssonicbld
authored andcommitted
Revert "Revert "Fix for fast/cold-boot: call db_migrator only after old config is loaded (sonic-net#14933)" (sonic-net#15464)" (sonic-net#15684)
This reverts commit 9649a44.
1 parent 4672d07 commit e52c2c2

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
@@ -255,10 +255,18 @@ function postStartAction()
255255
$SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
256256
fi
257257

258-
if [[ -x /usr/local/bin/db_migrator.py ]]; then
259-
# Migrate the DB to the latest schema version if needed
260-
if [ -z "$DEV" ]; then
261-
/usr/local/bin/db_migrator.py -o migrate
258+
if [ -e /tmp/pending_config_migration ]; then
259+
# this is first boot to a new image, config-setup execution is pending.
260+
# For fast/cold reboot case, DB contains nothing at this point
261+
# Call db_migrator after config-setup loads the config (from old config or minigraph)
262+
echo "Delaying db_migrator until config migration is over"
263+
else
264+
# this is not a first time boot to a new image. Datbase container starts w/ old pre-existing config
265+
if [[ -x /usr/local/bin/db_migrator.py ]]; then
266+
# Migrate the DB to the latest schema version if needed
267+
if [ -z "$DEV" ]; then
268+
/usr/local/bin/db_migrator.py -o migrate
269+
fi
262270
fi
263271
fi
264272
# 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
@@ -300,6 +300,16 @@ check_all_config_db_present()
300300
return 0
301301
}
302302

303+
# DB schema is subject to change between two images
304+
# Perform DB schema migration after loading backup config from previous image
305+
do_db_migration()
306+
{
307+
if [[ -x /usr/local/bin/db_migrator.py ]]; then
308+
# Migrate the DB to the latest schema version if needed
309+
/usr/local/bin/db_migrator.py -o migrate
310+
fi
311+
}
312+
303313
# Perform configuration migration from backup copy.
304314
# - This step is performed when a new image is installed and SONiC switch boots into it
305315
do_config_migration()
@@ -322,16 +332,19 @@ do_config_migration()
322332
if [ x"${WARM_BOOT}" == x"true" ]; then
323333
echo "Warm reboot detected..."
324334
disable_updategraph
335+
do_db_migration
325336
rm -f /tmp/pending_config_migration
326337
exit 0
327338
elif check_all_config_db_present; then
328339
echo "Use config_db.json from old system..."
329340
reload_configdb
341+
do_db_migration
330342
# Disable updategraph
331343
disable_updategraph
332344
elif [ -r ${MINGRAPH_FILE} ]; then
333345
echo "Use minigraph.xml from old system..."
334346
reload_minigraph
347+
do_db_migration
335348
# Disable updategraph
336349
disable_updategraph
337350
else

0 commit comments

Comments
 (0)