From 19ba9940f5c01e324f981bbb3de1033c39886bc9 Mon Sep 17 00:00:00 2001 From: JunhongMao <134556118+JunhongMao@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:36:32 -0400 Subject: [PATCH] [VOQ][saidump] To move saidump.sh from the sonic-buildimage repo to the sairedis repo (#1298) To fix the issue: sonic-net/sonic-buildimage#13561 The existing saidump use https://github.com/sonic-net/sonic-swss-common/blob/master/common/table_dump.lua script which loops the ASIC_DB more than 5 seconds and blocks other processes access. This solution uses the Redis SAVE command to save the snapshot of DB each time and recover later, instead of looping through each entry in the table. --- syncd/scripts/saidump.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 syncd/scripts/saidump.sh diff --git a/syncd/scripts/saidump.sh b/syncd/scripts/saidump.sh new file mode 100755 index 000000000..034322ff3 --- /dev/null +++ b/syncd/scripts/saidump.sh @@ -0,0 +1,39 @@ +#!/bin/bash +set -e + +save_saidump_by_rdb() +{ + local filepath="/var/run/redis/sonic-db/database_config.json" + + # Get hostname, port, redis directory + local redis_config=$(python3 -c " +import json +with open('$filepath') as json_file: + data = json.load(json_file) + print(data['INSTANCES']['redis']['hostname'], data['INSTANCES']['redis']['port'], data['INSTANCES']['redis']['unix_socket_path'])") + + # split + redis_config=(${redis_config// / }) + local hostname=${redis_config[0]} + local port=${redis_config[1]} + local redis_dir=`dirname ${redis_config[2]}` + logger "saidump.sh: hostname:$hostname, port:$port, redis_dir:$redis_dir" + + logger "saidump.sh: [1] Config Redis consistency directory." + redis-cli -h $hostname -p $port CONFIG SET dir $redis_dir > /dev/null + + logger "saidump.sh: [2] SAVE." + redis-cli -h $hostname -p $port SAVE > /dev/null + + logger "saidump.sh: [3] Run rdb command to convert the dump files into JSON files." + rdb --command json $redis_dir/dump.rdb | tee $redis_dir/dump.json > /dev/null + + logger "saidump.sh: [4] Run saidump -r to update the JSON files' format as same as the saidump before. Then we can get the saidump's result in standard output." + saidump -r $redis_dir/dump.json -m 100 + + logger "saidump.sh: [5] Clear the temporary files." + rm -f $redis_dir/dump.rdb + rm -f $redis_dir/dump.json +} + +save_saidump_by_rdb \ No newline at end of file