2013-12-20 19:39:21 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2014-02-02 09:40:37 +00:00
|
|
|
# Copyright (C) 2013,2014 Cloudwatt <libre.licensing@cloudwatt.com>
|
2013-12-20 19:39:21 +00:00
|
|
|
#
|
|
|
|
# Author: Loic Dachary <loic@dachary.org>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Library Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
# any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Library Public License for more details.
|
|
|
|
#
|
|
|
|
set -xe
|
|
|
|
PS4='$LINENO: '
|
|
|
|
|
|
|
|
DIR=osd-pool-create
|
|
|
|
rm -fr $DIR
|
2014-02-02 09:31:48 +00:00
|
|
|
trap "test \$? = 0 || cat $DIR/log ; set +x ; kill_mon || true && rm -fr $DIR" EXIT
|
2013-12-20 19:39:21 +00:00
|
|
|
mkdir $DIR
|
|
|
|
export CEPH_ARGS="--conf /dev/null --auth-supported=none --mon-host=127.0.0.1"
|
|
|
|
|
|
|
|
function run_mon() {
|
|
|
|
./ceph-mon --id a \
|
2014-01-03 23:34:45 +00:00
|
|
|
--public-addr=127.0.0.1 --mkfs \
|
2013-12-20 19:39:21 +00:00
|
|
|
--fsid=$(uuidgen) --mon-data=$DIR --run-dir=$DIR
|
|
|
|
|
|
|
|
./ceph-mon --id a \
|
|
|
|
--chdir= \
|
2014-02-02 09:33:20 +00:00
|
|
|
--paxos-propose-interval=0.1 \
|
|
|
|
--osd-pool-default-erasure-code-directory=.libs \
|
2013-12-20 19:39:21 +00:00
|
|
|
--mon-data=$DIR \
|
|
|
|
--log-file=$DIR/log \
|
|
|
|
--mon-cluster-log-file=$DIR/log \
|
|
|
|
--run-dir=$DIR \
|
|
|
|
--pid-file=$DIR/pidfile \
|
|
|
|
"$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
function kill_mon() {
|
2013-12-25 20:36:13 +00:00
|
|
|
for try in 0 1 1 1 2 3 ; do
|
|
|
|
if [ ! -e $DIR/pidfile ] ||
|
2014-02-02 09:34:43 +00:00
|
|
|
! kill -9 $(cat $DIR/pidfile) ; then
|
2013-12-25 20:36:13 +00:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
sleep $try
|
|
|
|
done
|
|
|
|
|
2013-12-29 12:41:45 +00:00
|
|
|
rm -fr $DIR/*
|
2013-12-20 19:39:21 +00:00
|
|
|
}
|
|
|
|
|
2013-12-26 11:03:57 +00:00
|
|
|
# explicitly set the default crush rule
|
|
|
|
expected=66
|
|
|
|
run_mon --osd_pool_default_crush_replicated_ruleset $expected
|
|
|
|
./ceph --format json osd dump | grep '"crush_ruleset":'$expected
|
2014-02-02 09:37:18 +00:00
|
|
|
! grep "osd_pool_default_crush_rule is deprecated " $DIR/log || exit 1
|
2013-12-26 11:03:57 +00:00
|
|
|
kill_mon
|
|
|
|
|
|
|
|
# explicitly set the default crush rule using deprecated option
|
|
|
|
expected=55
|
|
|
|
run_mon --osd_pool_default_crush_rule $expected
|
|
|
|
./ceph --format json osd dump | grep '"crush_ruleset":'$expected
|
|
|
|
grep "osd_pool_default_crush_rule is deprecated " $DIR/log
|
|
|
|
kill_mon
|
|
|
|
|
|
|
|
expected=77
|
|
|
|
unexpected=33
|
|
|
|
run_mon \
|
|
|
|
--osd_pool_default_crush_rule $expected \
|
|
|
|
--osd_pool_default_crush_replicated_ruleset $unexpected
|
|
|
|
./ceph --format json osd dump | grep '"crush_ruleset":'$expected
|
2014-02-02 09:37:18 +00:00
|
|
|
! ./ceph --format json osd dump | grep '"crush_ruleset":'$unexpected || exit 1
|
2013-12-26 11:03:57 +00:00
|
|
|
grep "osd_pool_default_crush_rule is deprecated " $DIR/log
|
|
|
|
kill_mon
|
|
|
|
|
2013-12-20 19:39:21 +00:00
|
|
|
# osd_pool_default_erasure_code_properties is
|
|
|
|
# valid JSON but not of the expected type
|
|
|
|
run_mon --osd_pool_default_erasure_code_properties 1
|
|
|
|
./ceph osd pool create poolA 12 12 erasure 2>&1 | grep 'must be a JSON object'
|
|
|
|
kill_mon
|
|
|
|
|
2014-02-02 09:40:37 +00:00
|
|
|
# set the erasure crush rule
|
|
|
|
run_mon
|
|
|
|
crush_ruleset=erasure_ruleset
|
|
|
|
./ceph osd crush rule create-erasure $crush_ruleset
|
|
|
|
./ceph osd crush rule ls | grep $crush_ruleset
|
|
|
|
./ceph osd pool create pool_erasure 12 12 erasure 2>&1 |
|
|
|
|
grep 'crush_ruleset is missing'
|
|
|
|
! ./ceph osd pool create pool_erasure 12 12 erasure crush_ruleset=WRONG > $DIR/out 2>&1
|
|
|
|
grep 'WRONG does not exist' $DIR/out
|
|
|
|
grep 'EINVAL' $DIR/out
|
|
|
|
! ./ceph --format json osd dump | grep '"crush_ruleset":1' || exit 1
|
|
|
|
./ceph osd pool create pool_erasure 12 12 erasure crush_ruleset=$crush_ruleset
|
|
|
|
./ceph --format json osd dump | grep '"crush_ruleset":1'
|
2013-12-26 08:59:18 +00:00
|
|
|
kill_mon
|
|
|
|
|
2014-02-03 21:59:30 +00:00
|
|
|
# try again if the ruleset creation is pending
|
2014-02-12 15:58:23 +00:00
|
|
|
run_mon --mon-advanced-debug-mode --debug-mon=20 --debug-paxos=20
|
2014-02-03 21:59:30 +00:00
|
|
|
crush_ruleset=erasure_ruleset
|
2014-02-12 15:58:23 +00:00
|
|
|
# add to the pending OSD map without triggering a paxos proposal
|
|
|
|
result=$(echo '{"prefix":"osdmonitor_prepare_command","prepare":"osd crush rule create-erasure","name":"'$crush_ruleset'"}' | nc -U $DIR/ceph-mon.a.asok | cut --bytes=5-)
|
|
|
|
test $result = true || exit 1
|
|
|
|
./ceph osd pool create pool_erasure 12 12 erasure crush_ruleset=$crush_ruleset
|
2014-02-03 21:59:30 +00:00
|
|
|
grep "$crush_ruleset try again" $DIR/log
|
|
|
|
kill_mon
|
|
|
|
|
2013-12-20 19:39:21 +00:00
|
|
|
# osd_pool_default_erasure_code_properties is JSON
|
2014-02-02 10:35:13 +00:00
|
|
|
expected='"erasure-code-plugin":"example"'
|
2013-12-20 19:39:21 +00:00
|
|
|
run_mon --osd_pool_default_erasure_code_properties "{$expected}"
|
2014-02-02 10:35:13 +00:00
|
|
|
! ./ceph --format json osd dump | grep "$expected" || exit 1
|
|
|
|
crush_ruleset=erasure_ruleset
|
|
|
|
./ceph osd crush rule create-erasure $crush_ruleset
|
|
|
|
./ceph osd pool create pool_erasure 12 12 erasure crush_ruleset=$crush_ruleset
|
2013-12-20 19:39:21 +00:00
|
|
|
./ceph --format json osd dump | grep "$expected"
|
|
|
|
kill_mon
|
|
|
|
|
|
|
|
# osd_pool_default_erasure_code_properties is plain text
|
2014-02-02 10:35:13 +00:00
|
|
|
expected='"erasure-code-plugin":"example"'
|
|
|
|
run_mon --osd_pool_default_erasure_code_properties "erasure-code-plugin=example"
|
|
|
|
! ./ceph --format json osd dump | grep "$expected" || exit 1
|
|
|
|
crush_ruleset=erasure_ruleset
|
|
|
|
./ceph osd crush rule create-erasure $crush_ruleset
|
|
|
|
./ceph osd pool create pool_erasure 12 12 erasure crush_ruleset=$crush_ruleset
|
2013-12-20 19:39:21 +00:00
|
|
|
./ceph --format json osd dump | grep "$expected"
|
|
|
|
kill_mon
|
|
|
|
|
2014-02-05 19:44:32 +00:00
|
|
|
# the default stripe width is used to initialize the pool
|
2013-12-20 19:39:21 +00:00
|
|
|
run_mon
|
2014-02-05 19:44:32 +00:00
|
|
|
stripe_width=$(./ceph-conf --show-config-value osd_pool_erasure_code_stripe_width)
|
|
|
|
crush_ruleset=erasure_ruleset
|
|
|
|
./ceph osd crush rule create-erasure $crush_ruleset
|
|
|
|
./ceph osd pool create pool_erasure 12 12 erasure crush_ruleset=$crush_ruleset
|
|
|
|
./ceph --format json osd dump | tee $DIR/osd.json
|
|
|
|
grep '"stripe_width":'$stripe_width $DIR/osd.json > /dev/null
|
|
|
|
kill_mon
|
2013-12-20 19:39:21 +00:00
|
|
|
|
2014-02-05 19:44:32 +00:00
|
|
|
# setting osd_pool_erasure_code_stripe_width modifies the stripe_width
|
|
|
|
# and it is padded as required by the default plugin
|
|
|
|
properties+=" erasure-code-plugin=jerasure"
|
|
|
|
properties+=" erasure-code-technique=reed_sol_van"
|
|
|
|
k=4
|
|
|
|
properties+=" erasure-code-k=$k"
|
|
|
|
properties+=" erasure-code-m=2"
|
|
|
|
expected_chunk_size=2048
|
|
|
|
actual_stripe_width=$(($expected_chunk_size * $k))
|
|
|
|
desired_stripe_width=$(($actual_stripe_width - 1))
|
|
|
|
run_mon \
|
|
|
|
--osd_pool_erasure_code_stripe_width $desired_stripe_width \
|
|
|
|
--osd_pool_default_erasure_code_properties "$properties"
|
|
|
|
crush_ruleset=erasure_ruleset
|
|
|
|
./ceph osd crush rule create-erasure $crush_ruleset
|
|
|
|
./ceph osd pool create pool_erasure 12 12 erasure crush_ruleset=$crush_ruleset
|
|
|
|
./ceph osd dump | tee $DIR/osd.json
|
|
|
|
grep "stripe_width $actual_stripe_width" $DIR/osd.json > /dev/null
|
|
|
|
kill_mon
|
|
|
|
|
|
|
|
run_mon
|
2014-02-02 09:37:18 +00:00
|
|
|
# creating an erasure code pool sets defaults properties
|
2013-12-20 19:39:21 +00:00
|
|
|
./ceph --format json osd dump > $DIR/osd.json
|
2014-02-02 09:37:18 +00:00
|
|
|
! grep "erasure-code-plugin" $DIR/osd.json || exit 1
|
2014-02-02 10:35:13 +00:00
|
|
|
./ceph osd crush rule create-erasure erasure_ruleset
|
|
|
|
./ceph osd pool create erasurecodes 12 12 erasure crush_ruleset=erasure_ruleset
|
2013-12-20 19:39:21 +00:00
|
|
|
./ceph --format json osd dump | tee $DIR/osd.json
|
|
|
|
grep "erasure-code-plugin" $DIR/osd.json > /dev/null
|
|
|
|
grep "erasure-code-directory" $DIR/osd.json > /dev/null
|
|
|
|
|
|
|
|
./ceph osd pool create erasurecodes 12 12 erasure 2>&1 |
|
|
|
|
grep 'already exists'
|
|
|
|
./ceph osd pool create erasurecodes 12 12 2>&1 |
|
|
|
|
grep 'cannot change to type replicated'
|
|
|
|
./ceph osd pool create replicated 12 12 replicated
|
|
|
|
./ceph osd pool create replicated 12 12 replicated 2>&1 |
|
|
|
|
grep 'already exists'
|
|
|
|
./ceph osd pool create replicated 12 12 # default is replicated
|
|
|
|
./ceph osd pool create replicated 12 # default is replicated, pgp_num = pg_num
|
|
|
|
./ceph osd pool create replicated 12 12 erasure 2>&1 |
|
|
|
|
grep 'cannot change to type erasure'
|
|
|
|
|
|
|
|
kill_mon
|
|
|
|
|
|
|
|
# Local Variables:
|
2014-02-12 15:58:23 +00:00
|
|
|
# compile-command: "cd ../.. ; make -j4 && test/mon/osd-pool-create.sh"
|
2013-12-20 19:39:21 +00:00
|
|
|
# End:
|