@@ -1563,6 +1563,20 @@ function test_is_clean() {
15631563
15641564# ######################################################################
15651565
1566+ # #
1567+ # Predicate checking if the named PG is in state "active+clean"
1568+ #
1569+ # @return 0 if the PG is active & clean, 1 otherwise
1570+ #
1571+ function is_pg_clean() {
1572+ local pgid=$1
1573+ local pg_state
1574+ pg_state=$( ceph pg $pgid query 2> /dev/null | jq -r " .state " )
1575+ [[ " $pg_state " == " active+clean" * ]]
1576+ }
1577+
1578+ # ######################################################################
1579+
15661580calc () { $AWK " BEGIN{print $* }" ; }
15671581
15681582# #
@@ -1678,6 +1692,33 @@ function test_wait_for_clean() {
16781692 teardown $dir || return 1
16791693}
16801694
1695+ # #
1696+ # Wait until the named PG becomes clean or until a timeout of
1697+ # $WAIT_FOR_CLEAN_TIMEOUT seconds.
1698+ #
1699+ # @return 0 if the PG is clean, 1 otherwise
1700+ #
1701+ function wait_for_pg_clean() {
1702+ local pg_id=$1
1703+ local -a delays=($( get_timeout_delays $WAIT_FOR_CLEAN_TIMEOUT 1 3) )
1704+ local -i loop=0
1705+
1706+ flush_pg_stats || return 1
1707+
1708+ while true ; do
1709+ echo " #---------- $pgid loop $loop "
1710+ is_pg_clean $pg_id && break
1711+ if (( $loop >= ${# delays[*]} )) ; then
1712+ ceph report
1713+ echo " PG $pg_id is not clean after $loop iterations"
1714+ return 1
1715+ fi
1716+ sleep ${delays[$loop]}
1717+ loop+=1
1718+ done
1719+ return 0
1720+ }
1721+
16811722# #
16821723# Wait until the cluster becomes peered or if it does not make progress
16831724# for $WAIT_FOR_CLEAN_TIMEOUT seconds.
@@ -1881,13 +1922,17 @@ function test_repair() {
18811922#
18821923function pg_scrub() {
18831924 local pgid=$1
1925+ # do not issue the scrub command unless the PG is clean
1926+ wait_for_pg_clean $pgid || return 1
18841927 local last_scrub=$( get_last_scrub_stamp $pgid )
18851928 ceph pg scrub $pgid
18861929 wait_for_scrub $pgid " $last_scrub "
18871930}
18881931
18891932function pg_deep_scrub() {
18901933 local pgid=$1
1934+ # do not issue the scrub command unless the PG is clean
1935+ wait_for_pg_clean $pgid || return 1
18911936 local last_scrub=$( get_last_scrub_stamp $pgid last_deep_scrub_stamp)
18921937 ceph pg deep-scrub $pgid
18931938 wait_for_scrub $pgid " $last_scrub " last_deep_scrub_stamp
@@ -1923,15 +1968,19 @@ function test_pg_scrub() {
19231968#
19241969function pg_schedule_scrub() {
19251970 local pgid=$1
1971+ # do not issue the scrub command unless the PG is clean
1972+ wait_for_pg_clean $pgid || return 1
19261973 local last_scrub=$( get_last_scrub_stamp $pgid )
1927- ceph pg scrub $pgid
1974+ ceph tell $pgid schedule-scrub
19281975 wait_for_scrub $pgid " $last_scrub "
19291976}
19301977
19311978function pg_schedule_deep_scrub() {
19321979 local pgid=$1
1980+ # do not issue the scrub command unless the PG is clean
1981+ wait_for_pg_clean $pgid || return 1
19331982 local last_scrub=$( get_last_scrub_stamp $pgid last_deep_scrub_stamp)
1934- ceph pg deep-scrub $pgid
1983+ ceph tell $pgid schedule- deep-scrub
19351984 wait_for_scrub $pgid " $last_scrub " last_deep_scrub_stamp
19361985}
19371986
@@ -1940,13 +1989,11 @@ function test_pg_schedule_scrub() {
19401989
19411990 setup $dir || return 1
19421991 run_mon $dir a --osd_pool_default_size=1 --mon_allow_pool_size_one=true || return 1
1943- run_mgr $dir x || return 1
1992+ run_mgr $dir x --mgr_stats_period=1 || return 1
19441993 run_osd $dir 0 || return 1
19451994 create_rbd_pool || return 1
19461995 wait_for_clean || return 1
19471996 pg_schedule_scrub 1.0 || return 1
1948- kill_daemons $dir KILL osd || return 1
1949- ! TIMEOUT=1 pg_scrub 1.0 || return 1
19501997 teardown $dir || return 1
19511998}
19521999
@@ -2333,7 +2380,7 @@ function run_tests() {
23332380 shopt -s -o xtrace
23342381 PS4=' ${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: '
23352382
2336- export .:$PATH # make sure program from sources are preferred
2383+ export PATH=./bin: .:$PATH # make sure program from sources are preferred
23372384
23382385 export CEPH_MON=" 127.0.0.1:7109" # git grep '\<7109\>' : there must be only one
23392386 export CEPH_ARGS
0 commit comments