Skip to content

Commit 15652b2

Browse files
vaibhavhdpull[bot]
authored andcommitted
Fix CONFIG_DB_INITIALIZED flag check logic and set/reset flag for warmboot (#15685)
* Fix CONFIG_DB_INITIALIZED flag check logic and set/reset flag for warm-reboot * Fix db-cli usage * Handle same image warm-reboot and generalize handling of INIT flag * Cover boot from ONIE case: set config init flag when minigraph, config_db are missing * Handle case: first boot of SONiC * Check for config init flag * Simplify logic, and do not call db_migrator for same image reboot
1 parent 0014ec4 commit 15652b2

File tree

5 files changed

+15
-22
lines changed

5 files changed

+15
-22
lines changed

files/build_templates/docker_image_ctl.j2

+9-18
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ function postStartAction()
235235
($(docker exec -i database$DEV sonic-db-cli PING | grep -c PONG) -gt 0) ]]; do
236236
sleep 1;
237237
done
238+
238239
if [[ ("$BOOT_TYPE" == "warm" || "$BOOT_TYPE" == "fastfast" || "$BOOT_TYPE" == "fast") && -f $WARM_DIR/dump.rdb ]]; then
239240
# retain the dump file from last boot for debugging purposes
240241
mv $WARM_DIR/dump.rdb $WARM_DIR/dump.rdb.old
@@ -248,28 +249,18 @@ function postStartAction()
248249
$SONIC_CFGGEN -j /etc/sonic/config_db$DEV.json --write-to-db
249250
fi
250251
fi
251-
252-
if [[ "$BOOT_TYPE" == "fast" ]]; then
253-
# set the key to expire in 3 minutes
254-
$SONIC_DB_CLI STATE_DB SET "FAST_REBOOT|system" "1" "EX" "180"
255-
fi
256-
257-
$SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
258252
fi
259253

260-
if [ -e /tmp/pending_config_migration ]; then
254+
if [ -e /tmp/pending_config_migration ] || [ -e /tmp/pending_config_initialization ]; then
261255
# 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"
256+
# for warmboot case, DB is loaded but migration is still pending
257+
# For firstbboot/fast/cold reboot case, DB contains nothing at this point
258+
# unset CONFIG_DB_INITIALIZED to indicate pending config load and migration
259+
# This flag will be set to "1" after DB migration/initialization is completed as part of config-setup
260+
$SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "0"
265261
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
272-
fi
262+
# set CONFIG_DB_INITIALIZED to indicate end of config load and migration
263+
$SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
273264
fi
274265
# Add redis UDS to the redis group and give read/write access to the group
275266
REDIS_SOCK="/var/run/redis${DEV}/redis.sock"

files/image_config/config-setup/config-setup

+3-1
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ do_config_initialization()
295295
fi
296296

297297
rm -f /tmp/pending_config_initialization
298+
sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
298299
}
299300

300301
# Restore config-setup post migration hooks from a backup copy
@@ -344,13 +345,14 @@ check_all_config_db_present()
344345
}
345346

346347
# DB schema is subject to change between two images
347-
# Perform DB schema migration after loading backup config from previous image
348+
# Perform DB schema migration after loading backup config/minigraph from previous image
348349
do_db_migration()
349350
{
350351
if [[ -x /usr/local/bin/db_migrator.py ]]; then
351352
# Migrate the DB to the latest schema version if needed
352353
/usr/local/bin/db_migrator.py -o migrate
353354
fi
355+
sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
354356
}
355357

356358
# Perform configuration migration from backup copy.

files/image_config/warmboot-finalizer/finalize-warmboot.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function wait_for_database_service()
7474
done
7575

7676
# Wait for configDB initialization
77-
until [[ $(sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]];
77+
until [[ $(sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") -eq 1 ]];
7878
do sleep 1;
7979
done
8080

files/scripts/swss.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function wait_for_database_service()
8787
done
8888

8989
# Wait for configDB initialization
90-
until [[ $($SONIC_DB_CLI CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]];
90+
until [[ $($SONIC_DB_CLI CONFIG_DB GET "CONFIG_DB_INITIALIZED") -eq 1 ]];
9191
do sleep 1;
9292
done
9393
}

files/scripts/syncd_common.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function wait_for_database_service()
6666
done
6767

6868
# Wait for configDB initialization
69-
until [[ $($SONIC_DB_CLI CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]];
69+
until [[ $($SONIC_DB_CLI CONFIG_DB GET "CONFIG_DB_INITIALIZED") -eq 1 ]];
7070
do sleep 1;
7171
done
7272
}

0 commit comments

Comments
 (0)