]> git.proxmox.com Git - ceph.git/blame - ceph/qa/workunits/mon/pg_autoscaler.sh
bump version to 16.2.6-pve2
[ceph.git] / ceph / qa / workunits / mon / pg_autoscaler.sh
CommitLineData
11fdf7f2
TL
1#!/bin/bash -ex
2
3NUM_OSDS=$(ceph osd ls | wc -l)
4if [ $NUM_OSDS -lt 6 ]; then
5 echo "test requires at least 6 OSDs"
6 exit 1
7fi
8
9NUM_POOLS=$(ceph osd pool ls | wc -l)
10if [ $NUM_POOLS -gt 0 ]; then
11 echo "test requires no preexisting pools"
12 exit 1
13fi
14
15function wait_for() {
16 local sec=$1
17 local cmd=$2
18
19 while true ; do
20 if bash -c "$cmd" ; then
21 break
22 fi
23 sec=$(( $sec - 1 ))
24 if [ $sec -eq 0 ]; then
25 echo failed
26 return 1
27 fi
28 sleep 1
29 done
30 return 0
31}
32
522d829b
TL
33function power2() { echo "x=l($1)/l(2); scale=0; 2^((x+0.5)/1)" | bc -l;}
34
11fdf7f2
TL
35# enable
36ceph config set mgr mgr/pg_autoscaler/sleep_interval 5
37ceph mgr module enable pg_autoscaler
38
39# pg_num_min
40ceph osd pool create a 16 --pg-num-min 4
41ceph osd pool create b 16 --pg-num-min 2
42ceph osd pool set a pg_autoscale_mode on
43ceph osd pool set b pg_autoscale_mode on
44
522d829b
TL
45# get num pools again since we created more pools
46NUM_POOLS=$(ceph osd pool ls | wc -l)
47
48# get pool size
49POOL_SIZE_A=$(ceph osd pool get a size| grep -Eo '[0-9]{1,4}')
50POOL_SIZE_B=$(ceph osd pool get b size| grep -Eo '[0-9]{1,4}')
51
52# calculate target pg of each pools
53TARGET_PG_A=$(power2 $((($NUM_OSDS * 100)/($NUM_POOLS)/($POOL_SIZE_A))))
54TARGET_PG_B=$(power2 $((($NUM_OSDS * 100)/($NUM_POOLS)/($POOL_SIZE_B))))
55
56# evaluate target_pg against pg num of each pools
57wait_for 120 "ceph osd pool get a pg_num | grep $TARGET_PG_A"
58wait_for 120 "ceph osd pool get b pg_num | grep $TARGET_PG_B"
11fdf7f2
TL
59
60# target ratio
9f95a23c
TL
61ceph osd pool set a target_size_ratio 5
62ceph osd pool set b target_size_ratio 1
63sleep 10
64APGS=$(ceph osd dump -f json-pretty | jq '.pools[0].pg_num_target')
65BPGS=$(ceph osd dump -f json-pretty | jq '.pools[1].pg_num_target')
11fdf7f2
TL
66test $APGS -gt 100
67test $BPGS -gt 10
68
69# small ratio change does not change pg_num
9f95a23c
TL
70ceph osd pool set a target_size_ratio 7
71ceph osd pool set b target_size_ratio 2
11fdf7f2 72sleep 10
9f95a23c
TL
73APGS2=$(ceph osd dump -f json-pretty | jq '.pools[0].pg_num_target')
74BPGS2=$(ceph osd dump -f json-pretty | jq '.pools[1].pg_num_target')
75test $APGS -eq $APGS2
76test $BPGS -eq $BPGS2
11fdf7f2
TL
77
78# target_size
79ceph osd pool set a target_size_bytes 1000000000000000
80ceph osd pool set b target_size_bytes 1000000000000000
9f95a23c 81ceph osd pool set a target_size_ratio 0
11fdf7f2 82ceph osd pool set b target_size_ratio 0
9f95a23c
TL
83wait_for 60 "ceph health detail | grep POOL_TARGET_SIZE_BYTES_OVERCOMMITTED"
84
85ceph osd pool set a target_size_bytes 1000
86ceph osd pool set b target_size_bytes 1000
87ceph osd pool set a target_size_ratio 1
88wait_for 60 "ceph health detail | grep POOL_HAS_TARGET_SIZE_BYTES_AND_RATIO"
11fdf7f2
TL
89
90ceph osd pool rm a a --yes-i-really-really-mean-it
91ceph osd pool rm b b --yes-i-really-really-mean-it
92
93echo OK