Skip to content

Commit ddb3086

Browse files
authored
Revert "Revert "Fix for fast/cold-boot: call db_migrator only after old config is loaded (#14933)" (#15464)" (#15684)
This reverts commit 9649a44.
1 parent 6f6218a commit ddb3086

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

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

307+
# DB schema is subject to change between two images
308+
# Perform DB schema migration after loading backup config from previous image
309+
do_db_migration()
310+
{
311+
if [[ -x /usr/local/bin/db_migrator.py ]]; then
312+
# Migrate the DB to the latest schema version if needed
313+
/usr/local/bin/db_migrator.py -o migrate
314+
fi
315+
}
316+
307317
# Perform configuration migration from backup copy.
308318
# - This step is performed when a new image is installed and SONiC switch boots into it
309319
do_config_migration()
@@ -326,16 +336,19 @@ do_config_migration()
326336
if [ x"${WARM_BOOT}" == x"true" ]; then
327337
echo "Warm reboot detected..."
328338
disable_updategraph
339+
do_db_migration
329340
rm -f /tmp/pending_config_migration
330341
exit 0
331342
elif check_all_config_db_present; then
332343
echo "Use config_db.json from old system..."
333344
reload_configdb
345+
do_db_migration
334346
# Disable updategraph
335347
disable_updategraph
336348
elif [ -r ${MINGRAPH_FILE} ]; then
337349
echo "Use minigraph.xml from old system..."
338350
reload_minigraph
351+
do_db_migration
339352
# Disable updategraph
340353
disable_updategraph
341354
else

0 commit comments

Comments
 (0)