summaryrefslogtreecommitdiffstats
path: root/src/test/crush/crush_weights.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/crush/crush_weights.sh')
-rwxr-xr-xsrc/test/crush/crush_weights.sh60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/test/crush/crush_weights.sh b/src/test/crush/crush_weights.sh
new file mode 100755
index 000000000..64f854541
--- /dev/null
+++ b/src/test/crush/crush_weights.sh
@@ -0,0 +1,60 @@
+#!/usr/bin/env bash
+
+source $(dirname $0)/../detect-build-env-vars.sh
+
+if [ `uname` = FreeBSD ]; then
+ SED=gsed
+else
+ SED=sed
+fi
+
+read -r -d '' cm <<'EOF'
+# devices
+device 0 device0
+device 1 device1
+device 2 device2
+device 3 device3
+device 4 device4
+# types
+type 0 osd
+type 1 domain
+type 2 pool
+# buckets
+domain root {
+ id -1 # do not change unnecessarily
+ # weight 5.00000
+ alg straw2
+ hash 0 # rjenkins1
+ item device0 weight 10.00000
+ item device1 weight 10.00000
+ item device2 weight 10.00000
+ item device3 weight 10.00000
+ item device4 weight 1.00000
+}
+# rules
+rule data {
+ id 0
+ type replicated
+ step take root
+ step choose firstn 0 type osd
+ step emit
+}
+EOF
+
+three=($(echo "$cm" | crushtool -c /dev/fd/0 --test --show-utilization \
+ --min-x 1 --max-x 1000000 --num-rep 3 | \
+ grep "device \(0\|4\)" | $SED -e 's/^.*stored : \([0-9]\+\).*$/\1/'))
+
+if test $(echo "scale=5; (10 - ${three[0]}/${three[1]}) < .75" | bc) = 1; then
+ echo 3 replicas weights better distributed than they should be. 1>&2
+ exit 1
+fi
+
+one=($(echo "$cm" | crushtool -c /dev/fd/0 --test --show-utilization \
+ --min-x 1 --max-x 1000000 --num-rep 1 | \
+ grep "device \(0\|4\)" | $SED -e 's/^.*stored : \([0-9]\+\).*$/\1/'))
+
+if test $(echo "scale=5; (10 - ${one[0]}/${one[1]}) > .1 || (10 - ${one[0]}/${one[1]}) < -.1" | bc) = 1; then
+ echo 1 replica not distributed as they should be. 1>&2
+ exit 1
+fi