Skip to content

Commit 19ba994

Browse files
JunhongMaoStormLiangMS
authored andcommitted
[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.
1 parent 01f17ba commit 19ba994

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

syncd/scripts/saidump.sh

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
set -e
3+
4+
save_saidump_by_rdb()
5+
{
6+
local filepath="/var/run/redis/sonic-db/database_config.json"
7+
8+
# Get hostname, port, redis directory
9+
local redis_config=$(python3 -c "
10+
import json
11+
with open('$filepath') as json_file:
12+
data = json.load(json_file)
13+
print(data['INSTANCES']['redis']['hostname'], data['INSTANCES']['redis']['port'], data['INSTANCES']['redis']['unix_socket_path'])")
14+
15+
# split
16+
redis_config=(${redis_config// / })
17+
local hostname=${redis_config[0]}
18+
local port=${redis_config[1]}
19+
local redis_dir=`dirname ${redis_config[2]}`
20+
logger "saidump.sh: hostname:$hostname, port:$port, redis_dir:$redis_dir"
21+
22+
logger "saidump.sh: [1] Config Redis consistency directory."
23+
redis-cli -h $hostname -p $port CONFIG SET dir $redis_dir > /dev/null
24+
25+
logger "saidump.sh: [2] SAVE."
26+
redis-cli -h $hostname -p $port SAVE > /dev/null
27+
28+
logger "saidump.sh: [3] Run rdb command to convert the dump files into JSON files."
29+
rdb --command json $redis_dir/dump.rdb | tee $redis_dir/dump.json > /dev/null
30+
31+
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."
32+
saidump -r $redis_dir/dump.json -m 100
33+
34+
logger "saidump.sh: [5] Clear the temporary files."
35+
rm -f $redis_dir/dump.rdb
36+
rm -f $redis_dir/dump.json
37+
}
38+
39+
save_saidump_by_rdb

0 commit comments

Comments
 (0)