From 3504fdca51cf0333cd0ae316f95dca4dfa8fe8df Mon Sep 17 00:00:00 2001 From: jumao Date: Tue, 5 Sep 2023 17:19:56 -0400 Subject: [PATCH] =?UTF-8?q?=20=20=20=20*=20[saidump]=20=20=20=20=20?= =?UTF-8?q?=E2=80=A2=20=20=20=20=20=20=20Saidump=20for=20DNX-SAI=20https:/?= =?UTF-8?q?/github.com/sonic-net/sonic-buildimage/issues/13561?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Solution and modification: To use the redis-db SAVE option to save the snapshot of DB each time and recover later, instead of looping through each entry in the table and saving it. (1) Updated sonic-buildimage/build_debian.sh, to install Python library rdbtools into the host. (2) Updated sonic-buildimage/src/sonic-sairedis/saidump/saidump.cpp, add a new option -r, which updates the rdbtools's output-JSON files' format. (3) Add a new script file: files/scripts/saidump.sh, to do the below steps For each ASIC0, such as ASIC0, 1. Save the Redis data. sudo sonic-db-cli -n asic$1 SAVE > /dev/null 2. Move dump files to /var/run/redisX/ docker exec database$1 sh -c "mv /var/lib/redis/dump.rdb /var/run/redis$1/" 3. Run rdb command to convert the dump files into JSON files sudo python /usr/local/bin/rdb --command json /var/run/redis$1/dump.rdb | sudo tee /var/run/redis$1/dump.json > /dev/null 4. Run saidump -r to update the JSON files' format as same as the saidump before. Then we can get the saidump result in standard output. docker exec syncd$1 sh -c "saidump -r /var/run/redis$1/dump.json" 5. clear sudo rm -f /var/run/redis$1/dump.rdb sudo rm -f /var/run/redis$1/dump.json (4) Update sonic-buildimage/src/sonic-utilities/scripts/generate_dump, replace saidump with saidump.sh --- scripts/generate_dump | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/generate_dump b/scripts/generate_dump index 1e4c6a0dd4..0c98749bb8 100755 --- a/scripts/generate_dump +++ b/scripts/generate_dump @@ -872,6 +872,27 @@ save_redis() { # None ############################################################################### save_saidump() { + trap 'handle_error $? $LINENO' ERR + if [[ ( "$NUM_ASICS" == 1 ) ]] ; then + save_cmd "docker exec syncd saidump" "saidump" + else + for (( i=0; i<$NUM_ASICS; i++ )) + do + save_cmd "docker exec syncd$i saidump" "saidump$i" + done + fi +} + +############################################################################### +# SAI DUMP from syncd by Redis Save command +# Globals: +# NUM_ASICS +# Arguments: +# None +# Returns: +# None +############################################################################### +save_saidump_by_save_cmd() { trap 'handle_error $? $LINENO' ERR if [[ ( "$NUM_ASICS" == 1 ) ]] ; then save_cmd "saidump.sh" "saidump" @@ -1791,6 +1812,8 @@ main() { if [[ "$device_type" != "SpineRouter" ]]; then save_saidump + else + save_saidump_by_save_cmd fi if [ "$asic" = "barefoot" ]; then