3 # Copyright (C) 2014 Red Hat <contact@redhat.com>
5 # Author: Loic Dachary <loic@dachary.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU Library Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Library Public License for more details.
17 source $CEPH_ROOT/qa
/standalone
/ceph-helpers.sh
19 # Test development and debugging
20 # Set to "yes" in order to ignore diff errors and save results to update test
23 # Filter out mtime and local_mtime dates, version, prior_version and last_reqid (client) from any object_info.
24 jqfilter
='def walk(f):
26 | if type == "object" then
28 ( {}; . + { ($key): ($in[$key] | walk(f)) } ) | f
29 elif type == "array" then map( walk(f) ) | f
32 walk(if type == "object" then del(.mtime) else . end)
33 | walk(if type == "object" then del(.local_mtime) else . end)
34 | walk(if type == "object" then del(.last_reqid) else . end)
35 | walk(if type == "object" then del(.version) else . end)
36 | walk(if type == "object" then del(.prior_version) else . end)
37 | walk(if type == "object" then del(.redirect_target) else . end)
38 | walk(if type == "object" then del(.legacy_snaps) else . end)'
40 sortkeys
='import json; import sys ; JSON=sys.stdin.read() ; ud = json.loads(JSON) ; print json.dumps(ud, sort_keys=True, indent=2)'
46 export CEPH_MON
="127.0.0.1:7107" # git grep '\<7107\>' : there must be only one
48 CEPH_ARGS
+="--fsid=$(uuidgen) --auth-supported=none "
49 CEPH_ARGS
+="--mon-host=$CEPH_MON "
50 CEPH_ARGS
+="--osd-distrust-data-digest=true "
52 local funcs
=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
53 for func
in $funcs ; do
54 $func $dir ||
return 1
58 function add_something
() {
61 local obj
=${3:-SOMETHING}
62 local scrub
=${4:-noscrub}
64 if [ "$scrub" = "noscrub" ];
66 ceph osd
set noscrub ||
return 1
67 ceph osd
set nodeep-scrub ||
return 1
69 ceph osd
unset noscrub ||
return 1
70 ceph osd
unset nodeep-scrub ||
return 1
74 echo $payload > $dir/ORIGINAL
75 rados
--pool $poolname put
$obj $dir/ORIGINAL ||
return 1
79 # Test automatic repair with distrust set
81 function TEST_distrust_scrub_replicated
() {
83 local poolname
=dsr_pool
86 setup
$dir ||
return 1
87 run_mon
$dir a
--osd_pool_default_size=2 ||
return 1
88 run_mgr
$dir x ||
return 1
89 run_osd
$dir 0 ||
return 1
90 run_osd
$dir 1 ||
return 1
91 create_rbd_pool ||
return 1
92 wait_for_clean ||
return 1
94 create_pool foo
1 ||
return 1
95 create_pool
$poolname 1 1 ||
return 1
96 wait_for_clean ||
return 1
98 for i
in $
(seq 1 $total_objs) ; do
100 add_something
$dir $poolname $objname ||
return 1
103 local pg
=$
(get_pg
$poolname ROBJ0
)
105 for i
in $
(seq 1 $total_objs) ; do
110 # Deep-scrub only (all replicas are diffent than the object info
112 echo $payload > $dir/new.ROBJ1
113 objectstore_tool
$dir 0 $objname set-bytes
$dir/new.ROBJ1 ||
return 1
114 objectstore_tool
$dir 1 $objname set-bytes
$dir/new.ROBJ1 ||
return 1
118 # Deep-scrub only (all replicas are diffent than the object info
120 echo $payload > $dir/new.ROBJ2
121 objectstore_tool
$dir 0 $objname set-bytes
$dir/new.ROBJ2 ||
return 1
122 objectstore_tool
$dir 1 $objname set-bytes
$dir/new.ROBJ2 ||
return 1
123 # Make one replica have a different object info, so a full repair must happen too
124 objectstore_tool
$dir 0 $objname corrupt-info ||
return 1
129 # This should fix the data_digest because osd-distrust-data-digest is true
132 # This hangs if the scrub didn't repair the data_digest
133 timeout
30 rados
-p $poolname get ROBJ1
$dir/robj1.out ||
return 1
134 diff -q $dir/new.ROBJ1
$dir/robj1.out ||
return 1
135 rm -f $dir/new.ROBJ1
$dir/robj1.out ||
return 1
137 rados list-inconsistent-pg
$poolname > $dir/json ||
return 1
139 test $
(jq
'. | length' $dir/json
) = "1" ||
return 1
141 test $
(jq
-r '.[0]' $dir/json
) = $pg ||
return 1
143 rados list-inconsistent-obj
$pg > $dir/json ||
return 1
144 # Get epoch for repair-get requests
145 epoch
=$
(jq .epoch
$dir/json
)
147 jq
"$jqfilter" << EOF | jq '.inconsistents' | python -c "$sortkeys" > $dir/checkcsjson
158 "pool": -9223372036854776000,
167 "alloc_hint_flags": 255,
168 "expected_write_size": 0,
169 "local_mtime": "2018-07-24 15:05:56.027234",
170 "mtime": "2018-07-24 15:05:56.021775",
173 "last_reqid": "client.4137.0:1",
174 "prior_version": "0'0",
193 "data_digest": "0x2ddbf8f5",
194 "omap_digest": "0xffffffff",
195 "expected_object_size": 0
197 "data_digest": "0x0bb7ab52",
198 "omap_digest": "0xffffffff",
210 "pool": -9223372036854776000,
219 "alloc_hint_flags": 0,
220 "expected_write_size": 0,
221 "local_mtime": "2018-07-24 15:05:56.027234",
222 "mtime": "2018-07-24 15:05:56.021775",
225 "last_reqid": "client.4137.0:1",
226 "prior_version": "0'0",
245 "data_digest": "0x2ddbf8f5",
246 "omap_digest": "0xffffffff",
247 "expected_object_size": 0
249 "data_digest": "0x0bb7ab52",
250 "omap_digest": "0xffffffff",
257 "selected_object_info": {
262 "pool": -9223372036854776000,
271 "alloc_hint_flags": 0,
272 "expected_write_size": 0,
273 "local_mtime": "2018-07-24 15:05:56.027234",
274 "mtime": "2018-07-24 15:05:56.021775",
277 "last_reqid": "client.4137.0:1",
278 "prior_version": "0'0",
297 "data_digest": "0x2ddbf8f5",
298 "omap_digest": "0xffffffff",
299 "expected_object_size": 0
301 "union_shard_errors": [],
303 "object_info_inconsistency"
318 jq
"$jqfilter" $dir/json | jq
'.inconsistents' | python
-c "$sortkeys" > $dir/csjson
319 diff ${DIFFCOLOPTS} $dir/checkcsjson
$dir/csjson ||
test $getjson = "yes" ||
return 1
320 if test $getjson = "yes"
322 jq
'.' $dir/json
> save1.json
325 if test "$LOCALRUN" = "yes" && which jsonschema
> /dev
/null
;
327 jsonschema
-i $dir/json
$CEPH_ROOT/doc
/rados
/command
/list-inconsistent-obj.json ||
return 1
333 timeout
30 rados
-p $poolname get ROBJ2
$dir/robj2.out ||
return 1
334 diff -q $dir/new.ROBJ2
$dir/robj2.out ||
return 1
335 rm -f $dir/new.ROBJ2
$dir/robj2.out ||
return 1
337 rados rmpool
$poolname $poolname --yes-i-really-really-mean-it
338 teardown
$dir ||
return 1
341 main osd-scrub-distrust
"$@"
344 # compile-command: "cd build ; make -j4 && \
345 # ../qa/run-standalone.sh osd-scrub-distrust"