Skip to content

Instantly share code, notes, and snippets.

@drakonstein
Created February 13, 2019 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drakonstein/4391c0b268a35b64d4f26a12e5058ba9 to your computer and use it in GitHub Desktop.
Save drakonstein/4391c0b268a35b64d4f26a12e5058ba9 to your computer and use it in GitHub Desktop.
Compacting omaps on OSDs
#!/bin/bash
# Name: osd_omap_compaction.sh
#
# This will compact the omap dbs on OSDs
# Wait until the cluster is Healthy
HEALTH_OK=${1:-"HEALTH_OK"}
while [[ "$(ceph health)" != "$HEALTH_OK" ]]; do
sleep 10
done
osds=$(ceph osd crush ls $(hostname -s) | cut -d. -f2)
ceph osd set noout
# For each OSD, we want to run it's commands in the background so all OSDs will run at the same time
for osd in $osds; do
osd_type=$(ceph osd metadata $osd | grep 'osd_objectstore')
if echo $osd_type | grep -q filestore; then
db=$(sudo grep -aEo [[:alpha:]]+db /var/lib/ceph/osd/ceph-${osd}/superblock)
elif echo $osd_type | grep -q bluestore; then
db=bluestore-kv
else
echo $osd has an invalid type
exit 1
fi
(
echo "================================================================================"
sudo systemctl stop ceph-osd@$osd
omap=/var/lib/ceph/osd/ceph-${osd}/current/omap
sudo -u ceph ceph-kvstore-tool $db $omap compact
sudo systemctl start ceph-osd@$osd
) &
done
wait
# Wait until all OSDs are back up and in and then increase osd_max_backfills to speed up recovery between nodes
while true; do
stat=$(ceph osd stat)
up=$(echo "$stat" | grep -Eo '[[:digit:]]+\s+up' | awk '{print $1}')
in=$(echo "$stat" | grep -Eo '[[:digit:]]+\s+in' | awk '{print $1}')
if (( up == in )); then
ceph tell osd.\* injectargs --osd_max_backfills=2
ceph osd unset noout
break
else
sleep 10
fi
done
for osd in $osds; do
sudo du -sh /var/lib/ceph/osd/ceph-${osd}/current/omap
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment