Skip to content

Commit 908933b

Browse files
authored
[202012] Fix CONFIG_DB_INITIALIZED flag check logic and set/reset flag for warmboot (#16225)
Cherry pick of #15685 MSFT ADO: 24274591 #### Why I did it Two changes: ### 1 Fix a day1 issue, where check to wait until `CONFIG_DB_INITIALIZED` is incorrect. There are multiple places where same incorrect logic is used. Current logic (`until [[ $($SONIC_DB_CLI CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]];`) will always result in pass, irrespective of the result of GET operation. ``` root@str2-7060cx-32s-29:~# sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED" 1 root@str2-7060cx-32s-29:~# until [[ $(sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; do echo "entered here"; done root@str2-7060cx-32s-29:~# root@str2-7060cx-32s-29:~# root@str2-7060cx-32s-29:~# sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED" 0 root@str2-7060cx-32s-29:~# until [[ $(sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; do echo "entered here"; done root@str2-7060cx-32s-29:~# ``` Fix this logic by checking for value of flag to be "1". ``` root@str2-7060cx-32s-29:~# until [[ $(sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") -eq 1 ]]; do echo "entered here"; done entered here entered here entered here ``` This gap in logic was highlighted when another fix was merged: #14933 The issue being fixed here caused warmboot-finalizer to not wait until config-db is initialized. ### 2 Set and unset CONFIG_DB_INITIALIZED for warm-reboot case Currently, during warm shutdown `CONFIG_DB_INITIALIZED`'s value is stored in redis db backup. This is restored back when the dump is loaded during warm-recovery. So the value of `CONFIG_DB_INITIALIZED` does not depend on config db's state, however it remain what it was before reboot. Fix this by setting `CONFIG_DB_INITIALIZED` to 0 as when the DB is loaded, and set it to 1 after db_migrator is done.
1 parent 7fc5436 commit 908933b

File tree

5 files changed

+14
-22
lines changed

5 files changed

+14
-22
lines changed

files/build_templates/docker_image_ctl.j2

+8-18
Original file line numberDiff line numberDiff line change
@@ -126,28 +126,18 @@ function postStartAction()
126126
$SONIC_CFGGEN -j /etc/sonic/config_db$DEV.json --write-to-db
127127
fi
128128
fi
129-
130-
if [[ "$BOOT_TYPE" == "fast" ]]; then
131-
# set the key to expire in 3 minutes
132-
$SONIC_DB_CLI STATE_DB SET "FAST_REBOOT|system" "1" "EX" "180"
133-
fi
134-
135-
$SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
136129
fi
137130

138-
if [ -e /tmp/pending_config_migration ]; then
131+
if [ -e /tmp/pending_config_migration ] || [ -e /tmp/pending_config_initialization ]; then
139132
# 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"
133+
# for warmboot case, DB is loaded but migration is still pending
134+
# For firstbboot/fast/cold reboot case, DB contains nothing at this point
135+
# unset CONFIG_DB_INITIALIZED to indicate pending config load and migration
136+
# This flag will be set to "1" after DB migration/initialization is completed as part of config-setup
137+
$SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "0"
143138
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
150-
fi
139+
# set CONFIG_DB_INITIALIZED to indicate end of config load and migration
140+
$SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
151141
fi
152142
# Add redis UDS to the redis group and give read/write access to the group
153143
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
@@ -251,6 +251,7 @@ do_config_initialization()
251251
fi
252252

253253
rm -f /tmp/pending_config_initialization
254+
sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
254255
}
255256

256257
# Restore config-setup post migration hooks from a backup copy
@@ -299,13 +300,14 @@ check_all_config_db_present()
299300
}
300301

301302
# DB schema is subject to change between two images
302-
# Perform DB schema migration after loading backup config from previous image
303+
# Perform DB schema migration after loading backup config/minigraph from previous image
303304
do_db_migration()
304305
{
305306
if [[ -x /usr/local/bin/db_migrator.py ]]; then
306307
# Migrate the DB to the latest schema version if needed
307308
/usr/local/bin/db_migrator.py -o migrate
308309
fi
310+
sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
309311
}
310312

311313
# Perform configuration migration from backup copy.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function wait_for_database_service()
5656
done
5757

5858
# Wait for configDB initialization
59-
until [[ $(sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]];
59+
until [[ $(sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") -eq 1 ]];
6060
do sleep 1;
6161
done
6262

files/scripts/swss.sh

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

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

files/scripts/syncd_common.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function wait_for_database_service()
6363
done
6464

6565
# Wait for configDB initialization
66-
until [[ $($SONIC_DB_CLI CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]];
66+
until [[ $($SONIC_DB_CLI CONFIG_DB GET "CONFIG_DB_INITIALIZED") -eq 1 ]];
6767
do sleep 1;
6868
done
6969
}

0 commit comments

Comments
 (0)