Skip to content

Commit

Permalink
#16466 fix based on review comments:
Browse files Browse the repository at this point in the history
Install rdbtools into syncd docker and add saidump.sh into host.

* [saidump]
• Saidump for DNX-SAI #13561

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 platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2, install Python library rdbtools into the syncd containter.
(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) Updated sonic-buildimage/build_debian.sh, to add a new script file: files/scripts/saidump.sh into the host. This shell file does 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
  docker exec syncd$1 sh -c "rdb --command json /var/run/redis$1/dump.rdb | 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 -m 100"

  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, to check the asic db size and if it is larger than xxx entries, then do with REDIS SAVE, otherwise, to do with old method: looping through each entry of Redis DB.
  • Loading branch information
JunhongMao committed Sep 21, 2023
1 parent c8f5996 commit 1a414d5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
14 changes: 1 addition & 13 deletions build_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -729,22 +729,10 @@ SONIC_VERSION_CACHE=${SONIC_VERSION_CACHE} \
DBGOPT="${DBGOPT}" \
scripts/collect_host_image_version_files.sh $CONFIGURED_ARCH $IMAGE_DISTRO $TARGET_PATH $FILESYSTEM_ROOT

# Install libc6-dev and python3-dev for compiling python-lzf
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install libc6-dev python3-dev

# Install python-lzf
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install 'python-lzf==0.2.4'

# Install rdbtools
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install 'rdbtools==0.1.15'

# Uninstall libc6-dev and python3-dev for compiling python-lzf
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y remove libc6-dev
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y remove python3-dev

## Copy saidump.sh
sudo cp ./files/scripts/saidump.sh $FILESYSTEM_ROOT/usr/local/bin/saidump.sh
sudo chmod +x $FILESYSTEM_ROOT/usr/local/bin/saidump.sh

# Remove GCC
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y remove gcc

Expand Down
27 changes: 17 additions & 10 deletions files/scripts/saidump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,34 @@ function debug()
}

save_saidump_by_rdb() {
debug "saidump.sh: [1] sonic-db-cli -n asic$1 SAVE."
sudo sonic-db-cli -n asic$1 SAVE > /dev/null
debug "saidump.sh: [2] Move dump.rdb to /var/run/redis$1/ in container database$1."
docker exec database$1 sh -c "mv /var/lib/redis/dump.rdb /var/run/redis$1/"
DEV=$1 # ASIC index to operate on

if [ "$DEV" ]; then
debug "saidump.sh: [1] sonic-db-cli -n asic$DEV SAVE."
sonic-db-cli -n asic$DEV SAVE > /dev/null
else
debug "saidump.sh: [1] sonic-db-cli SAVE."
sonic-db-cli SAVE > /dev/null
fi

debug "saidump.sh: [2] Move dump.rdb to /var/run/redis$DEV/ in container database$DEV."
docker exec database$DEV sh -c "mv /var/lib/redis/dump.rdb /var/run/redis$DEV/"
debug "saidump.sh: [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
docker exec syncd$DEV sh -c "rdb --command json /var/run/redis$DEV/dump.rdb | tee /var/run/redis$DEV/dump.json > /dev/null"
debug "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."
docker exec syncd$1 sh -c "saidump -r /var/run/redis$1/dump.json"
docker exec syncd$DEV sh -c "saidump -r /var/run/redis$DEV/dump.json -m 100"
debug "saidump.sh: [5] Clear temporary files."
sudo rm -f /var/run/redis$1/dump.rdb
sudo rm -f /var/run/redis$1/dump.json
sudo rm -f /var/run/redis$DEV/dump.rdb
sudo rm -f /var/run/redis$DEV/dump.json
}

NUM_ASICS=`python -c 'from sonic_py_common.multi_asic import get_num_asics; print(get_num_asics())'`


if (( $# == 0 && $NUM_ASICS == 1 )); then
save_saidump_by_rdb
#validate if the argument is an integer
elif [[ "$1" =~ [0-9]+ ]] && (( $# == 1 && $1 >= 0 && $1 < $NUM_ASICS )) ; then
save_saidump_by_rdb $1
save_saidump_by_rdb $1
else
echo "The number of ASICS is $NUM_ASICS."
echo "Usage:"
Expand Down
12 changes: 12 additions & 0 deletions platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ RUN apt-get install -yf kmod
## BRCM uses ethtool to set host interface speed
RUN apt-get install -y ethtool

## Install gcc, libc6-dev and python3-dev for compiling python-lzf
RUN apt-get -y install build-essential libc6-dev python3-dev

## Install python-lzf
RUN pip3 install 'python-lzf==0.2.4'

## Install rdbtools
RUN pip3 install 'rdbtools==0.1.15'

## Uninstall gcc, libc6-dev and python3-dev for compiling python-lzf
RUN apt-get -y remove build-essential libc6-dev python3-dev

COPY ["files/dsserve", "files/bcmcmd", "start.sh", "start_led.sh", "bcmsh", "/usr/bin/"]
RUN chmod +x /usr/bin/dsserve /usr/bin/bcmcmd

Expand Down

0 comments on commit 1a414d5

Please sign in to comment.