]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/crush/crush_weights.sh
import quincy beta 17.1.0
[ceph.git] / ceph / src / test / crush / crush_weights.sh
1 #!/usr/bin/env bash
2
3 source $(dirname $0)/../detect-build-env-vars.sh
4
5 if [ `uname` = FreeBSD ]; then
6 SED=gsed
7 else
8 SED=sed
9 fi
10
11 read -r -d '' cm <<'EOF'
12 # devices
13 device 0 device0
14 device 1 device1
15 device 2 device2
16 device 3 device3
17 device 4 device4
18 # types
19 type 0 osd
20 type 1 domain
21 type 2 pool
22 # buckets
23 domain root {
24 id -1 # do not change unnecessarily
25 # weight 5.00000
26 alg straw2
27 hash 0 # rjenkins1
28 item device0 weight 10.00000
29 item device1 weight 10.00000
30 item device2 weight 10.00000
31 item device3 weight 10.00000
32 item device4 weight 1.00000
33 }
34 # rules
35 rule data {
36 id 0
37 type replicated
38 step take root
39 step choose firstn 0 type osd
40 step emit
41 }
42 EOF
43
44 three=($(echo "$cm" | crushtool -c /dev/fd/0 --test --show-utilization \
45 --min-x 1 --max-x 1000000 --num-rep 3 | \
46 grep "device \(0\|4\)" | $SED -e 's/^.*stored : \([0-9]\+\).*$/\1/'))
47
48 if test $(echo "scale=5; (10 - ${three[0]}/${three[1]}) < .75" | bc) = 1; then
49 echo 3 replicas weights better distributed than they should be. 1>&2
50 exit 1
51 fi
52
53 one=($(echo "$cm" | crushtool -c /dev/fd/0 --test --show-utilization \
54 --min-x 1 --max-x 1000000 --num-rep 1 | \
55 grep "device \(0\|4\)" | $SED -e 's/^.*stored : \([0-9]\+\).*$/\1/'))
56
57 if test $(echo "scale=5; (10 - ${one[0]}/${one[1]}) > .1 || (10 - ${one[0]}/${one[1]}) < -.1" | bc) = 1; then
58 echo 1 replica not distributed as they should be. 1>&2
59 exit 1
60 fi