Skip to content

Commit ab61edb

Browse files
committed
Use warm-boot infrastructure for fast-boot
1 parent 5bf684c commit ab61edb

File tree

1 file changed

+39
-55
lines changed

1 file changed

+39
-55
lines changed

scripts/fast-reboot

+39-55
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ EXIT_FILE_SYSTEM_FULL=3
4040
EXIT_NEXT_IMAGE_NOT_EXISTS=4
4141
EXIT_ORCHAGENT_SHUTDOWN=10
4242
EXIT_SYNCD_SHUTDOWN=11
43-
EXIT_FAST_REBOOT_DUMP_FAILURE=12
44-
EXIT_FILTER_FDB_ENTRIES_FAILURE=13
4543
EXIT_COUNTERPOLL_DELAY_FAILURE=14
4644
EXIT_DB_INTEGRITY_FAILURE=15
4745
EXIT_NO_CONTROL_PLANE_ASSISTANT=20
@@ -125,41 +123,36 @@ function parseOptions()
125123
done
126124
}
127125

128-
function common_clear()
126+
function clear_boot()
129127
{
128+
# common_clear
130129
debug "${REBOOT_TYPE} failure ($?) cleanup ..."
131130

132131
/sbin/kexec -u || /bin/true
133132

134133
teardown_control_plane_assistant
135-
}
136-
137-
function clear_fast_boot()
138-
{
139-
common_clear
140-
141-
sonic-db-cli STATE_DB DEL "FAST_REBOOT|system" &>/dev/null || /bin/true
142-
}
143-
144-
function clear_warm_boot()
145-
{
146-
common_clear
147134

135+
#clear_warm_boot
148136
result=$(timeout 10s config warm_restart disable; res=$?; if [[ $res == 124 ]]; then echo timeout; else echo "code ($res)"; fi) || /bin/true
149137
debug "Cancel warm-reboot: ${result}"
150138
151139
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
152140
if [[ -f ${WARM_DIR}/${REDIS_FILE} ]]; then
153141
mv -f ${WARM_DIR}/${REDIS_FILE} ${WARM_DIR}/${REDIS_FILE}.${TIMESTAMP} || /bin/true
154142
fi
143+
144+
#clear_fast_boot
145+
if [[ "$REBOOT_TYPE" = "fast-reboot" ]]; then
146+
sonic-db-cli STATE_DB DEL "FAST_REBOOT|system" &>/dev/null || /bin/true
147+
fi
155148
}
156149
157150
function init_warm_reboot_states()
158151
{
159152
# If the current running instance was booted up with warm reboot. Then
160153
# the current DB contents will likely mark warm reboot is done.
161154
# Clear these states so that the next boot up image won't get confused.
162-
if [[ "$REBOOT_TYPE" = "warm-reboot" || "$REBOOT_TYPE" = "fastfast-reboot" ]]; then
155+
if [[ "$REBOOT_TYPE" = "warm-reboot" || "$REBOOT_TYPE" = "fastfast-reboot" || "$REBOOT_TYPE" = "fast-reboot" ]]; then
163156
sonic-db-cli STATE_DB eval "
164157
for _, key in ipairs(redis.call('keys', 'WARM_RESTART_TABLE|*')) do
165158
redis.call('hdel', key, 'state')
@@ -266,7 +259,8 @@ function backup_database()
266259
and not string.match(k, 'FG_ROUTE_TABLE|') \
267260
and not string.match(k, 'WARM_RESTART_ENABLE_TABLE|') \
268261
and not string.match(k, 'VXLAN_TUNNEL_TABLE|') \
269-
and not string.match(k, 'BUFFER_MAX_PARAM_TABLE|') then
262+
and not string.match(k, 'BUFFER_MAX_PARAM_TABLE|') \
263+
and not string.match(k, 'FAST_REBOOT|') then
270264
redis.call('del', k)
271265
end
272266
end
@@ -371,7 +365,7 @@ function check_docker_exec()
371365
372366
function check_db_integrity()
373367
{
374-
if [[ "$REBOOT_TYPE" = "warm-reboot" || "$REBOOT_TYPE" = "fastfast-reboot" ]]; then
368+
if [[ "$REBOOT_TYPE" = "warm-reboot" || "$REBOOT_TYPE" = "fastfast-reboot" || "$REBOOT_TYPE" = "fast-reboot" ]]; then
375369
CHECK_DB_INTEGRITY=0
376370
/usr/local/bin/check_db_integrity.py || CHECK_DB_INTEGRITY=$?
377371
if [[ CHECK_DB_INTEGRITY -ne 0 ]]; then
@@ -454,7 +448,6 @@ function unload_kernel()
454448
function save_counters_folder() {
455449
if [[ "$REBOOT_TYPE" = "warm-reboot" ]]; then
456450
debug "Saving counters folder before warmboot..."
457-
458451
counters_folder="/host/counters"
459452
if [[ ! -d $counters_folder ]]; then
460453
mkdir $counters_folder
@@ -523,9 +516,11 @@ sonic_asic_type=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
523516
BOOT_TYPE_ARG="cold"
524517
case "$REBOOT_TYPE" in
525518
"fast-reboot")
519+
check_warm_restart_in_progress
526520
BOOT_TYPE_ARG=$REBOOT_TYPE
527-
trap clear_fast_boot EXIT HUP INT QUIT TERM KILL ABRT ALRM
521+
trap clear_boot EXIT HUP INT QUIT TERM KILL ABRT ALRM
528522
sonic-db-cli STATE_DB SET "FAST_REBOOT|system" "1" "EX" "180" &>/dev/null
523+
config warm_restart enable system
529524
;;
530525
"warm-reboot")
531526
check_warm_restart_in_progress
@@ -538,7 +533,7 @@ case "$REBOOT_TYPE" in
538533
else
539534
BOOT_TYPE_ARG="warm"
540535
fi
541-
trap clear_warm_boot EXIT HUP INT QUIT TERM KILL ABRT ALRM
536+
trap clear_boot EXIT HUP INT QUIT TERM KILL ABRT ALRM
542537
config warm_restart enable system
543538
;;
544539
*)
@@ -596,34 +591,11 @@ else
596591
load_kernel
597592
fi
598593
599-
if [[ "$REBOOT_TYPE" = "fast-reboot" ]]; then
600-
# Dump the ARP and FDB tables to files also as default routes for both IPv4 and IPv6
601-
# into /host/fast-reboot
602-
DUMP_DIR=/host/fast-reboot
603-
mkdir -p $DUMP_DIR
604-
FAST_REBOOT_DUMP_RC=0
605-
/usr/local/bin/fast-reboot-dump.py -t $DUMP_DIR || FAST_REBOOT_DUMP_RC=$?
606-
if [[ FAST_REBOOT_DUMP_RC -ne 0 ]]; then
607-
error "Failed to run fast-reboot-dump.py. Exit code: $FAST_REBOOT_DUMP_RC"
608-
unload_kernel
609-
exit "${EXIT_FAST_REBOOT_DUMP_FAILURE}"
610-
fi
611-
612-
FILTER_FDB_ENTRIES_RC=0
613-
# Filter FDB entries using MAC addresses from ARP table
614-
/usr/local/bin/filter_fdb_entries -f $DUMP_DIR/fdb.json -a $DUMP_DIR/arp.json -c $CONFIG_DB_FILE || FILTER_FDB_ENTRIES_RC=$?
615-
if [[ FILTER_FDB_ENTRIES_RC -ne 0 ]]; then
616-
error "Failed to filter FDb entries. Exit code: $FILTER_FDB_ENTRIES_RC"
617-
unload_kernel
618-
exit "${EXIT_FILTER_FDB_ENTRIES_FAILURE}"
619-
fi
620-
fi
621-
622594
init_warm_reboot_states
623595
624596
setup_control_plane_assistant
625597
626-
if [[ "$REBOOT_TYPE" = "warm-reboot" || "$REBOOT_TYPE" = "fastfast-reboot" ]]; then
598+
if [[ "$REBOOT_TYPE" = "warm-reboot" || "$REBOOT_TYPE" = "fastfast-reboot" || "$REBOOT_TYPE" = "fast-reboot" ]]; then
627599
# Freeze orchagent for warm restart
628600
# Ask orchagent_restart_check to try freeze 5 times with interval of 2 seconds,
629601
# it is possible that the orchagent is in transient state and no opportunity to freeze
@@ -655,6 +627,17 @@ fi
655627
# service will go down and we cannot recover from it.
656628
set +e
657629
630+
if [[ "$REBOOT_TYPE" = "fast-reboot" ]]; then
631+
# Clear all routes except of default routes for faster reconciliation time.
632+
sonic-db-cli APPL_DB eval "
633+
for _, k in ipairs(redis.call('keys', '*')) do
634+
if string.match(k, 'ROUTE_TABLE:') and not string.match(k, 'ROUTE_TABLE:0.0.0.0/0') and not string.match(k, 'ROUTE_TABLE:::/0') then \
635+
redis.call('del', k)
636+
end
637+
end
638+
" 0 > /dev/null
639+
fi
640+
658641
# disable trap-handlers which were set before
659642
trap '' EXIT HUP INT QUIT TERM KILL ABRT ALRM
660643
@@ -716,18 +699,19 @@ for service in ${SERVICES_TO_STOP}; do
716699
if [[ "x$sonic_asic_type" == x"mellanox" ]]; then
717700
check_issu_bank_file
718701
fi
702+
fi
719703
720-
# Warm reboot: dump state to host disk
721-
if [[ "$REBOOT_TYPE" = "fastfast-reboot" ]]; then
722-
sonic-db-cli ASIC_DB FLUSHDB > /dev/null
723-
sonic-db-cli COUNTERS_DB FLUSHDB > /dev/null
724-
sonic-db-cli FLEX_COUNTER_DB FLUSHDB > /dev/null
725-
fi
726-
727-
# TODO: backup_database preserves FDB_TABLE
728-
# need to cleanup as well for fastfast boot case
729-
backup_database
704+
if [[ "$REBOOT_TYPE" = "fastfast-reboot" || "$REBOOT_TYPE" = "fast-reboot" ]]; then
705+
# Advanced reboot: dump state to host disk
706+
sonic-db-cli ASIC_DB FLUSHDB > /dev/null
707+
sonic-db-cli COUNTERS_DB FLUSHDB > /dev/null
708+
sonic-db-cli FLEX_COUNTER_DB FLUSHDB > /dev/null
730709
fi
710+
711+
# TODO: backup_database preserves FDB_TABLE
712+
# need to cleanup as well for fastfast boot case
713+
backup_database
714+
731715
fi
732716
done
733717

0 commit comments

Comments
 (0)