summaryrefslogtreecommitdiffstats
path: root/src/common/scrub_types.cc
blob: 4b2cfa613d66f52d0d5eda42cb0c0d61c55d4f1c (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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#include "scrub_types.h"

using std::map;

using namespace librados;

void object_id_wrapper::encode(bufferlist& bl) const
{
  ENCODE_START(1, 1, bl);
  encode(name, bl);
  encode(nspace, bl);
  encode(locator, bl);
  encode(snap, bl);
  ENCODE_FINISH(bl);
}

void object_id_wrapper::decode(bufferlist::const_iterator& bp)
{
  DECODE_START(1, bp);
  decode(name, bp);
  decode(nspace, bp);
  decode(locator, bp);
  decode(snap, bp);
  DECODE_FINISH(bp);
}

namespace librados {
static void encode(const object_id_t& obj, bufferlist& bl)
{
  reinterpret_cast<const object_id_wrapper&>(obj).encode(bl);
}
}

void osd_shard_wrapper::encode(bufferlist& bl) const
{
  ENCODE_START(1, 1, bl);
  encode(osd, bl);
  encode(shard, bl);
  ENCODE_FINISH(bl);
}

void osd_shard_wrapper::decode(bufferlist::const_iterator& bp)
{
  DECODE_START(1, bp);
  decode(osd, bp);
  decode(shard, bp);
  DECODE_FINISH(bp);
}

namespace librados {
static void encode(const osd_shard_t& shard, bufferlist& bl) {
  reinterpret_cast<const osd_shard_wrapper&>(shard).encode(bl);
}
}

void shard_info_wrapper::set_object(const ScrubMap::object& object)
{
  for (auto attr : object.attrs) {
    bufferlist bl;
    bl.push_back(attr.second);
    attrs.insert(std::make_pair(attr.first, std::move(bl)));
  }
  size = object.size;
  if (object.omap_digest_present) {
    omap_digest_present = true;
    omap_digest = object.omap_digest;
  }
  if (object.digest_present) {
    data_digest_present = true;
    data_digest = object.digest;
  }
}

void shard_info_wrapper::encode(bufferlist& bl) const
{
  ENCODE_START(3, 3, bl);
  encode(errors, bl);
  encode(primary, bl);
  if (!has_shard_missing()) {
    encode(attrs, bl);
    encode(size, bl);
    encode(omap_digest_present, bl);
    encode(omap_digest, bl);
    encode(data_digest_present, bl);
    encode(data_digest, bl);
    encode(selected_oi, bl);
  }
  ENCODE_FINISH(bl);
}

void shard_info_wrapper::decode(bufferlist::const_iterator& bp)
{
  DECODE_START(3, bp);
  decode(errors, bp);
  decode(primary, bp);
  if (!has_shard_missing()) {
    decode(attrs, bp);
    decode(size, bp);
    decode(omap_digest_present, bp);
    decode(omap_digest, bp);
    decode(data_digest_present, bp);
    decode(data_digest, bp);
    decode(selected_oi, bp);
  }
  DECODE_FINISH(bp);
}

inconsistent_obj_wrapper::inconsistent_obj_wrapper(const hobject_t& hoid)
  : inconsistent_obj_t{librados::object_id_t{hoid.oid.name,
                                 hoid.nspace,
                                 hoid.get_key(), hoid.snap}}
{}

void inconsistent_obj_wrapper::add_shard(const pg_shard_t& pgs,
                                         const shard_info_wrapper& shard)
{
  union_shards.errors |= shard.errors;
  shards.emplace(osd_shard_t{pgs.osd, int8_t(pgs.shard)}, shard);
}

void
inconsistent_obj_wrapper::set_auth_missing(const hobject_t& hoid,
                                           const map<pg_shard_t, ScrubMap*>& maps,
					   map<pg_shard_t, shard_info_wrapper> &shard_map,
					   int &shallow_errors, int &deep_errors,
					   const pg_shard_t &primary)
{
  for (auto pg_map : maps) {
    auto oid_object = pg_map.second->objects.find(hoid);
    shard_map[pg_map.first].primary = (pg_map.first == primary);
    if (oid_object == pg_map.second->objects.end())
      shard_map[pg_map.first].set_missing();
    else
      shard_map[pg_map.first].set_object(oid_object->second);
    if (shard_map[pg_map.first].has_deep_errors())
      ++deep_errors;
    else if (shard_map[pg_map.first].has_shallow_errors())
      ++shallow_errors;
    union_shards.errors |= shard_map[pg_map.first].errors;
    shards.emplace(osd_shard_t{pg_map.first.osd, pg_map.first.shard}, shard_map[pg_map.first]);
  }
}

namespace librados {
  static void encode(const shard_info_t& shard, bufferlist& bl)
  {
    reinterpret_cast<const shard_info_wrapper&>(shard).encode(bl);
  }
}

void inconsistent_obj_wrapper::encode(bufferlist& bl) const
{
  ENCODE_START(2, 2, bl);
  encode(errors, bl);
  encode(object, bl);
  encode(version, bl);
  encode(shards, bl);
  encode(union_shards.errors, bl);
  ENCODE_FINISH(bl);
}

void inconsistent_obj_wrapper::decode(bufferlist::const_iterator& bp)
{
  DECODE_START(2, bp);
  DECODE_OLDEST(2);
  decode(errors, bp);
  decode(object, bp);
  decode(version, bp);
  decode(shards, bp);
  decode(union_shards.errors, bp);
  DECODE_FINISH(bp);
}

inconsistent_snapset_wrapper::inconsistent_snapset_wrapper(const hobject_t& hoid)
  : inconsistent_snapset_t{object_id_t{hoid.oid.name,
                                       hoid.nspace,
                                       hoid.get_key(),
                                       hoid.snap}}
{}

using inc_snapset_t = inconsistent_snapset_t;

void inconsistent_snapset_wrapper::set_headless()
{
  errors |= inc_snapset_t::HEADLESS_CLONE;
}

void inconsistent_snapset_wrapper::set_snapset_missing()
{
  errors |= inc_snapset_t::SNAPSET_MISSING;
}

void inconsistent_snapset_wrapper::set_info_missing()
{
  errors |= inc_snapset_t::INFO_MISSING;
}

void inconsistent_snapset_wrapper::set_snapset_corrupted()
{
  errors |= inc_snapset_t::SNAPSET_CORRUPTED;
}

void inconsistent_snapset_wrapper::set_info_corrupted()
{
  errors |= inc_snapset_t::INFO_CORRUPTED;
}

void inconsistent_snapset_wrapper::set_clone_missing(snapid_t snap)
{
  errors |= inc_snapset_t::CLONE_MISSING;
  missing.push_back(snap);
}

void inconsistent_snapset_wrapper::set_clone(snapid_t snap)
{
  errors |= inc_snapset_t::EXTRA_CLONES;
  clones.push_back(snap);
}

void inconsistent_snapset_wrapper::set_snapset_error()
{
  errors |= inc_snapset_t::SNAP_ERROR;
}

void inconsistent_snapset_wrapper::set_size_mismatch()
{
  errors |= inc_snapset_t::SIZE_MISMATCH;
}

void inconsistent_snapset_wrapper::encode(bufferlist& bl) const
{
  ENCODE_START(2, 1, bl);
  encode(errors, bl);
  encode(object, bl);
  encode(clones, bl);
  encode(missing, bl);
  encode(ss_bl, bl);
  ENCODE_FINISH(bl);
}

void inconsistent_snapset_wrapper::decode(bufferlist::const_iterator& bp)
{
  DECODE_START(2, bp);
  decode(errors, bp);
  decode(object, bp);
  decode(clones, bp);
  decode(missing, bp);
  if (struct_v >= 2) {
    decode(ss_bl, bp);
  }
  DECODE_FINISH(bp);
}

void scrub_ls_arg_t::encode(bufferlist& bl) const
{
  ENCODE_START(1, 1, bl);
  encode(interval, bl);
  encode(get_snapsets, bl);
  encode(start_after.name, bl);
  encode(start_after.nspace, bl);
  encode(start_after.snap, bl);
  encode(max_return, bl);
  ENCODE_FINISH(bl);
}

void scrub_ls_arg_t::decode(bufferlist::const_iterator& bp)
{
  DECODE_START(1, bp);
  decode(interval, bp);
  decode(get_snapsets, bp);
  decode(start_after.name, bp);
  decode(start_after.nspace, bp);
  decode(start_after.snap, bp);
  decode(max_return, bp);
  DECODE_FINISH(bp);
}

void scrub_ls_result_t::encode(bufferlist& bl) const
{
  ENCODE_START(1, 1, bl);
  encode(interval, bl);
  encode(vals, bl);
  ENCODE_FINISH(bl);
}

void scrub_ls_result_t::decode(bufferlist::const_iterator& bp)
{
  DECODE_START(1, bp);
  decode(interval, bp);
  decode(vals, bp);
  DECODE_FINISH(bp);
}