| 1 | #!/bin/bash |
| 2 | #set -x |
| 3 | source /usr/share/ceph-tools/_ct-common |
| 4 | |
| 5 | |
| 6 | help_msg () { |
| 7 | printf """ |
| 8 | usage: $0 [-h] [-s|--step Step] $CT_HELP_DESCR POOL NEW_PG_NUM |
| 9 | |
| 10 | Description Gradually increase the number of PG_NUM without overloading the cluster |
| 11 | |
| 12 | Optional |
| 13 | $CT_HELP_MSG |
| 14 | -s STEP, --step STEP |
| 15 | Increasing PG_NUM by 'Step', minimum and default: 64, if possible power of 2 |
| 16 | |
| 17 | Positional |
| 18 | POOL Pool to apply |
| 19 | NEW_PG_NUM New PG_NUM for pool 'POOL', minimum: 64 and Power of 2 |
| 20 | |
| 21 | Example |
| 22 | $0 $CT_HELP_EXAMPLE -s 64 Cinder 8192 |
| 23 | """ |
| 24 | } |
| 25 | |
| 26 | REBALANCING_STEP=64 |
| 27 | |
| 28 | ct_help_min $# 2 |
| 29 | ct_help $@ |
| 30 | shift $? |
| 31 | while [ $# -ge 2 ]; do |
| 32 | key="$1" |
| 33 | case $key in |
| 34 | -s|--step) |
| 35 | if [ $2 -lt 64 ]; then |
| 36 | echo "Step minimum 64 !" |
| 37 | ct_on_exit 1 |
| 38 | else |
| 39 | REBALANCING_STEP=$2 |
| 40 | fi |
| 41 | shift 2 |
| 42 | ;; |
| 43 | *) |
| 44 | POOL=$1 |
| 45 | if [[ ! $(($2 & ($2-1))) == 0 ]]; then |
| 46 | echo "NEW_PG_NUM must be a power of 2" |
| 47 | ct_on_exit 1 |
| 48 | else |
| 49 | NEW_PG_NUM=$2 |
| 50 | fi |
| 51 | break |
| 52 | ;; |
| 53 | esac |
| 54 | done |
| 55 | |
| 56 | get_current_pg_num() { |
| 57 | # Get Current PG_NUM |
| 58 | pg=$(ceph osd pool get $POOL pg_num|awk '{print $2}') |
| 59 | echo $pg |
| 60 | } |
| 61 | |
| 62 | |
| 63 | CURRENT_PG_NUM=$(get_current_pg_num) |
| 64 | |
| 65 | if [ $CURRENT_PG_NUM -ge $NEW_PG_NUM ]; then |
| 66 | # If CURRENT_PG_NUM >= NEW_PG_NUM |
| 67 | echo No change |
| 68 | ct_on_exit 0 |
| 69 | fi |
| 70 | |
| 71 | for count in $(seq $((CURRENT_PG_NUM + REBALANCING_STEP)) $REBALANCING_STEP $NEW_PG_NUM); do |
| 72 | # Increase by REBALANCING_STEP |
| 73 | ct_healthy_wait $REBALANCING_STEP |
| 74 | ceph osd pool set $POOL pg_num $count |
| 75 | ceph osd pool set $POOL pgp_num $count |
| 76 | sleep 30 |
| 77 | done |
| 78 | |
| 79 | if [ $CURRENT_PG_NUM -lt $NEW_PG_NUM ]; then |
| 80 | # CURRENT_PG_NUM < NEW_PG_NUM |
| 81 | ceph osd pool set $POOL pg_num $NEW_PG_NUM |
| 82 | ceph osd pool set $POOL pgp_num $NEW_PG_NUM |
| 83 | sleep 30 |
| 84 | fi |
| 85 | |
| 86 | ct_healthy_wait 0 |
| 87 | echo PG_NUM for pool ${POOL} is set to ${NEW_PG_NUM} |
| 88 | |
| 89 | ct_on_exit 0 |