summaryrefslogtreecommitdiffstats
path: root/qa/standalone/misc/test-snaptrim-stats.sh
blob: 98b3e4fdd9ce1c69ab174fb5f71210926de69fc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env bash
#
# Copyright (C) 2022 Red Hat <contact@redhat.com>
#
# Author: Sridhar Seshasayee <sseshasa@redhat.com>
#
# 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.
#

source $CEPH_ROOT/qa/standalone/ceph-helpers.sh

function run() {
    local dir=$1
    shift

    export CEPH_MON="127.0.0.1:7124" # git grep '\<7124\>' : there must be only one
    export CEPH_ARGS
    CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none "
    CEPH_ARGS+="--mon-host=$CEPH_MON "
    CEPH_ARGS+="--debug-bluestore 20 "

    local funcs=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
    for func in $funcs ; do
        setup $dir || return 1
        $func $dir || return 1
        teardown $dir || return 1
    done
}

function TEST_snaptrim_stats() {
    local dir=$1
    local poolname=test
    local OSDS=3
    local PGNUM=8
    local PGPNUM=8
    local objects=10
    local WAIT_FOR_UPDATE=10

    setup $dir || return 1
    run_mon $dir a --osd_pool_default_size=$OSDS || return 1
    run_mgr $dir x || return 1
    for osd in $(seq 0 $(expr $OSDS - 1))
    do
      run_osd $dir $osd --osd_pool_default_pg_autoscale_mode=off || return 1
    done

    # disable scrubs
    ceph osd set noscrub || return 1
    ceph osd set nodeep-scrub || return 1

    # Create a pool
    create_pool $poolname $PGNUM $PGPNUM
    wait_for_clean || return 1
    poolid=$(ceph osd dump | grep "^pool.*[']${poolname}[']" | awk '{ print $2 }')

    # write a few objects
    TESTDATA="testdata.1"
    dd if=/dev/urandom of=$TESTDATA bs=4096 count=1
    for i in `seq 1 $objects`
    do
        rados -p $poolname put obj${i} $TESTDATA
    done
    rm -f $TESTDATA

    # create a snapshot, clones
    SNAP=1
    rados -p $poolname mksnap snap${SNAP}
    TESTDATA="testdata.2"
    dd if=/dev/urandom of=$TESTDATA  bs=4096 count=1
    for i in `seq 1 $objects`
    do
        rados -p $poolname put obj${i} $TESTDATA
    done
    rm -f $TESTDATA

    # remove the snapshot, should trigger snaptrim
    rados -p $poolname rmsnap snap${SNAP}

    # check for snaptrim stats
    wait_for_clean || return 1
    sleep $WAIT_FOR_UPDATE
    local objects_trimmed=0
    local snaptrim_duration_total=0.0
    for i in $(seq 0 $(expr $PGNUM - 1))
    do
        local pgid="${poolid}.${i}"
        objects_trimmed=$(expr $objects_trimmed + $(ceph pg $pgid query | \
            jq '.info.stats.objects_trimmed'))
        snaptrim_duration_total=`echo $snaptrim_duration_total + $(ceph pg \
            $pgid query | jq '.info.stats.snaptrim_duration') | bc`
    done
    test $objects_trimmed -eq $objects || return 1
    echo "$snaptrim_duration_total > 0.0" | bc || return 1

    teardown $dir || return 1
}

function TEST_snaptrim_stats_multiple_snaps() {
    local dir=$1
    local poolname=test
    local OSDS=3
    local PGNUM=8
    local PGPNUM=8
    local objects=10
    local WAIT_FOR_UPDATE=10

    setup $dir || return 1
    run_mon $dir a --osd_pool_default_size=$OSDS || return 1
    run_mgr $dir x || return 1
    for osd in $(seq 0 $(expr $OSDS - 1))
    do
      run_osd $dir $osd --osd_pool_default_pg_autoscale_mode=off || return 1
    done

    # disable scrubs
    ceph osd set noscrub || return 1
    ceph osd set nodeep-scrub || return 1

    # Create a pool
    create_pool $poolname $PGNUM $PGPNUM
    wait_for_clean || return 1
    poolid=$(ceph osd dump | grep "^pool.*[']${poolname}[']" | awk '{ print $2 }')

    # write a few objects
    local TESTDATA="testdata.0"
    dd if=/dev/urandom of=$TESTDATA bs=4096 count=1
    for i in `seq 1 $objects`
    do
        rados -p $poolname put obj${i} $TESTDATA
    done
    rm -f $TESTDATA

    # create snapshots, clones
    NUMSNAPS=2
    for i in `seq 1 $NUMSNAPS`
    do
        rados -p $poolname mksnap snap${i}
        TESTDATA="testdata".${i}
        dd if=/dev/urandom of=$TESTDATA  bs=4096 count=1
        for i in `seq 1 $objects`
        do
            rados -p $poolname put obj${i} $TESTDATA
        done
        rm -f $TESTDATA
    done

    # remove the snapshots, should trigger snaptrim
    local total_objects_trimmed=0
    for i in `seq 1 $NUMSNAPS`
    do
        rados -p $poolname rmsnap snap${i}

        # check for snaptrim stats
        wait_for_clean || return 1
        sleep $WAIT_FOR_UPDATE
        local objects_trimmed=0
        local snaptrim_duration_total=0.0
        for i in $(seq 0 $(expr $PGNUM - 1))
        do
            local pgid="${poolid}.${i}"
            objects_trimmed=$(expr $objects_trimmed + $(ceph pg $pgid query | \
                jq '.info.stats.objects_trimmed'))
            snaptrim_duration_total=`echo $snaptrim_duration_total + $(ceph pg \
                $pgid query | jq '.info.stats.snaptrim_duration') | bc`
        done
        test $objects_trimmed -eq $objects || return 1
        echo "$snaptrim_duration_total > 0.0" | bc || return 1
        total_objects_trimmed=$(expr $total_objects_trimmed + $objects_trimmed)
    done

    test $total_objects_trimmed -eq $((objects * NUMSNAPS)) || return 1

    teardown $dir || return 1
}
main test-snaptrim-stats "$@"

# Local Variables:
# compile-command: "cd build ; make -j4 && \
#   ../qa/run-standalone.sh test-snaptrim-stats.sh"
# End: