Skip to content

Instantly share code, notes, and snippets.

@drakonstein
Created February 13, 2019 18:32

Revisions

  1. drakonstein created this gist Feb 13, 2019.
    53 changes: 53 additions & 0 deletions osd_omap_compaction.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    #!/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