Skip to content

Instantly share code, notes, and snippets.

@ideepika
Created March 16, 2022 15:50
Show Gist options
  • Save ideepika/4bf7972cc7fcf0e2af70dda9a58019f6 to your computer and use it in GitHub Desktop.
Save ideepika/4bf7972cc7fcf0e2af70dda9a58019f6 to your computer and use it in GitHub Desktop.
rbd_mirror_ops.sh
```
#!/bin/bash
set -x
rbdpool=data
rbdimage=a1
east=primary
west=secondary
rbdimagefeatures="--image-feature layering --image-feature exclusive-lock --image-feature object-map --image-feature fast-diff"
setup()
{
echo "=== Creating image $1 ==="
../src/mrun $1 rbd create $rbdpool/$rbdimage --size 10G $rbdimagefeatures
echo
echo "=== Enabling mirror $1 ==="
../src/mrun $1 rbd mirror image enable $rbdpool/$rbdimage snapshot
echo
echo "=== Enabling snapshot schedule 1m $1 ==="
../src/mrun $1 rbd mirror snapshot schedule add --pool $rbdpool --image $rbdimage 1m
}
display()
{
echo `date`
echo "=== Mirror image status $east ==="
../src/mrun $east rbd mirror image status $rbdpool/$rbdimage
echo
echo "=== Mirror image status $west ==="
../src/mrun $west rbd mirror image status $rbdpool/$rbdimage
echo
echo "=== Mirror snapshot list $east ==="
../src/mrun $east rbd -p $rbdpool snap ls $rbdimage --all
echo
echo "=== Mirror snapshot list $west ==="
../src/mrun $west rbd -p $rbdpool snap ls $rbdimage --all
echo
}
#Force promote cluster1 to have 2 primaries
forcePromote()
{
echo
echo "=== Force promote image on $1 ==="
../src/mrun $1 rbd mirror image promote $rbdpool/$rbdimage --force
echo
}
#Demote hub
demote()
{
echo "=== Demoting $1 ==="
../src/mrun $1 rbd mirror image demote $rbdpool/$rbdimage
echo
echo "=== Sleep for catch up ==="
sleep 4
}
resync()
{
echo "=== Resync $1 ==="
../src/mrun $1 rbd mirror image resync $rbdpool/$rbdimage
echo
echo "=== Sleeping for 10 seconds for resync catch up ==="
sleep 10
}
performIO()
{
echo "=== Perform IO on $1 ==="
(../src/mrun $1 rbd bench --io-type write --io-size 4K --io-threads 2 --io-total 10G --io-pattern rand $rbdpool/$rbdimage) &
echo
# echo "=== Sleep for catch up ==="
# sleep 10
}
promote()
{
echo "=== Promote on $1 ==="
../src/mrun $1 rbd mirror image promote $rbdpool/$rbdimage
echo
echo "=== Sleep for catch up ==="
sleep 4
}
cleanup()
{
echo "=== remove rbd mirror logs ==="
> /home/ideepika/sdc/ceph3/ceph/build2/resync_logs/rbd_mirror_secondary.log
> /home/ideepika/sdc/ceph3/ceph/build2/resync_logs/rbd_mirror_primary.log
echo "=== remove logs ===="
rm -rf run/$east/out/client* run/$east/out/rbd*; rm -rf run/$west/out/client* run/$west/out/rbd*
echo "=== Delete image on $1 ==="
../src/mrun $1 rbd mirror image disable $rbdpool/$rbdimage --force
../src/mrun $1 rbd rm $rbdpool/$rbdimage
echo "=== Force promote $2 ==="
../src/mrun $2 rbd mirror image promote $rbdpool/$rbdimage --force
../src/mrun secondary rbd mirror image disable data/a1 --force
../src/mrun primary rbd mirror image disable data/a1 --force
echo "=== Delete image on $2 ==="
../src/mrun $1 rbd mirror image disable $rbdpool/$rbdimage --force
../src/mrun $2 rbd rm $rbdpool/$rbdimage
}
# create
cleanup $west $east
setup $west
sleep 15
display
# Use - 1
# perform in the background
#performIO $west
## wait for rbd mirror to start picking up the changes
#echo " waiting so mirroring can be in progress..."
#sleep 15
## while ios happening force promote
#forcePromote $east
#display
# Use - 1
# perform in the background
# # relocate - 1
# demote $west
# display
# demote $east
# display
# resync $west
# display
# # relocate - 2
# demote $east
# display
# promote $west
# display
# performIO $west
# display
# #relocate - 3
# demote $west
# display
# promote $east
# display
# performIO $east
# display
# # relocate - 4
# demote $east
# display
# promote $west
# display
# performIO $west
# display
# cleanup $west $east
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment