Project

General

Profile

Bug #38135 » delete_random_snapshot.sh

Bengen Tan, 02/01/2019 12:10 AM

 
#!/bin/bash
#
# testing-modify-delete-random-snapshots-pB
#
# Version: 20181129-00
DATE="$(date "+%Y%m%d-%H%M%S")"
RBD_POOL=test-rbd0
declare -i work_counter
[[ -d /mnt/rbd ]] || mkdir /mnt/rbd
get_rbd_name()
{
printf "vpayno-sparse-%050d" ${1}
} # get_rbd_name()
worker()
{
local -i id="${1}"
rbd_name=$(get_rbd_name ${id})
printf "\n(%07d) %s\n\n" ${id} "${rbd_name}"
printf "Checking to see if %s/%s exists...\n" "${RBD_POOL}" "${rbd_name}"
if ! grep -q "^${rbd_name}$" /root/rbd-list.txt; then
printf "RBD does not exist, skipping ...\n"
return
fi
printf "Creating RBD lock ...\n"
echo rbd lock add ${RBD_POOL}/${rbd_name} vpayno
time if ! rbd lock add ${RBD_POOL}/${rbd_name} vpayno; then
printf "Getting lock failed, skipping ...\n"
return
fi
# Grab the oldest snapshot name.
snap_name="$(rbd snap ls ${RBD_POOL}/${rbd_name} | awk '/^[0-9][0-9]/ { print $2 }' | head -n 1)"
printf "last snapshot: %s\n" "${snap_name}"
printf "Removing snapshot ...\n"
echo rbd snap remove ${RBD_POOL}/${rbd_name}@${snap_name}
time rbd snap remove ${RBD_POOL}/${rbd_name}@${snap_name}
printf "\n"
rbd lock list ${RBD_POOL}/${rbd_name}
printf "Removing RBD lock ...\n"
echo rbd lock remove ${RBD_POOL}/${rbd_name} $(rbd lock list ${RBD_POOL}/${rbd_name} | awk '/^client/ { print $2" "$1 }')
time rbd lock remove ${RBD_POOL}/${rbd_name} $(rbd lock list ${RBD_POOL}/${rbd_name} | awk '/^client/ { print $2" "$1 }')
rbd lock list ${RBD_POOL}/${rbd_name}
printf "\n"
} # worker()
time for i in {0..999999}; do
id="$(shuf -i 0-499999 -n 1)"
echo worker ${id}
worker ${id} &
let work_counter++
#break
sleep 0.5s
if [[ $(( ${i} % 6 )) -eq 0 ]]; then
jobs
time wait
printf "\n# of worker threads that have completed: %d\n\n" "${work_counter}"
echo sleeping...
sleep 15s
fi
[[ -f /tmp/stop-tests ]] && break
done
jobs
time wait
(3-3/4)