1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2013 Inktank Storage, Inc.
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #include "ECMsgTypes.h"
17 void ECSubWrite::encode(bufferlist &bl) const
19 ENCODE_START(4, 1, bl);
26 ::encode(at_version, bl);
27 ::encode(trim_to, bl);
28 ::encode(log_entries, bl);
29 ::encode(temp_added, bl);
30 ::encode(temp_removed, bl);
31 ::encode(updated_hit_set_history, bl);
32 ::encode(roll_forward_to, bl);
33 ::encode(backfill, bl);
37 void ECSubWrite::decode(bufferlist::iterator &bl)
46 ::decode(at_version, bl);
47 ::decode(trim_to, bl);
48 ::decode(log_entries, bl);
49 ::decode(temp_added, bl);
50 ::decode(temp_removed, bl);
52 ::decode(updated_hit_set_history, bl);
55 ::decode(roll_forward_to, bl);
57 roll_forward_to = trim_to;
60 ::decode(backfill, bl);
62 // The old protocol used an empty transaction to indicate backfill
68 std::ostream &operator<<(
69 std::ostream &lhs, const ECSubWrite &rhs)
71 lhs << "ECSubWrite(tid=" << rhs.tid
72 << ", reqid=" << rhs.reqid
73 << ", at_version=" << rhs.at_version
74 << ", trim_to=" << rhs.trim_to
75 << ", roll_forward_to=" << rhs.roll_forward_to;
76 if (rhs.updated_hit_set_history)
77 lhs << ", has_updated_hit_set_history";
83 void ECSubWrite::dump(Formatter *f) const
85 f->dump_unsigned("tid", tid);
86 f->dump_stream("reqid") << reqid;
87 f->dump_stream("at_version") << at_version;
88 f->dump_stream("trim_to") << trim_to;
89 f->dump_stream("roll_forward_to") << roll_forward_to;
90 f->dump_bool("has_updated_hit_set_history",
91 static_cast<bool>(updated_hit_set_history));
92 f->dump_bool("backfill", backfill);
95 void ECSubWrite::generate_test_instances(list<ECSubWrite*> &o)
97 o.push_back(new ECSubWrite());
99 o.back()->at_version = eversion_t(2, 100);
100 o.back()->trim_to = eversion_t(1, 40);
101 o.push_back(new ECSubWrite());
103 o.back()->reqid = osd_reqid_t(entity_name_t::CLIENT(123), 1, 45678);
104 o.back()->at_version = eversion_t(10, 300);
105 o.back()->trim_to = eversion_t(5, 42);
106 o.push_back(new ECSubWrite());
108 o.back()->reqid = osd_reqid_t(entity_name_t::CLIENT(123), 1, 45678);
109 o.back()->at_version = eversion_t(10, 300);
110 o.back()->trim_to = eversion_t(5, 42);
111 o.back()->roll_forward_to = eversion_t(8, 250);
114 void ECSubWriteReply::encode(bufferlist &bl) const
116 ENCODE_START(1, 1, bl);
119 ::encode(last_complete, bl);
120 ::encode(committed, bl);
121 ::encode(applied, bl);
125 void ECSubWriteReply::decode(bufferlist::iterator &bl)
130 ::decode(last_complete, bl);
131 ::decode(committed, bl);
132 ::decode(applied, bl);
136 std::ostream &operator<<(
137 std::ostream &lhs, const ECSubWriteReply &rhs)
140 << "ECSubWriteReply(tid=" << rhs.tid
141 << ", last_complete=" << rhs.last_complete
142 << ", committed=" << rhs.committed
143 << ", applied=" << rhs.applied << ")";
146 void ECSubWriteReply::dump(Formatter *f) const
148 f->dump_unsigned("tid", tid);
149 f->dump_stream("last_complete") << last_complete;
150 f->dump_bool("committed", committed);
151 f->dump_bool("applied", applied);
154 void ECSubWriteReply::generate_test_instances(list<ECSubWriteReply*>& o)
156 o.push_back(new ECSubWriteReply());
158 o.back()->last_complete = eversion_t(100, 2000);
159 o.back()->committed = true;
160 o.push_back(new ECSubWriteReply());
162 o.back()->last_complete = eversion_t(50, 200);
163 o.back()->applied = true;
166 void ECSubRead::encode(bufferlist &bl, uint64_t features) const
168 if ((features & CEPH_FEATURE_OSD_FADVISE_FLAGS) == 0) {
169 ENCODE_START(1, 1, bl);
172 map<hobject_t, list<pair<uint64_t, uint64_t> >> tmp;
173 for (map<hobject_t, list<boost::tuple<uint64_t, uint64_t, uint32_t> >>::const_iterator m = to_read.begin();
174 m != to_read.end(); ++m) {
175 list<pair<uint64_t, uint64_t> > tlist;
176 for (list<boost::tuple<uint64_t, uint64_t, uint32_t> >::const_iterator l = m->second.begin();
177 l != m->second.end(); ++l) {
178 tlist.push_back(std::make_pair(l->get<0>(), l->get<1>()));
180 tmp[m->first] = tlist;
183 ::encode(attrs_to_read, bl);
188 ENCODE_START(2, 2, bl);
191 ::encode(to_read, bl);
192 ::encode(attrs_to_read, bl);
196 void ECSubRead::decode(bufferlist::iterator &bl)
202 map<hobject_t, list<pair<uint64_t, uint64_t> >>tmp;
204 for (map<hobject_t, list<pair<uint64_t, uint64_t> >>::const_iterator m = tmp.begin();
205 m != tmp.end(); ++m) {
206 list<boost::tuple<uint64_t, uint64_t, uint32_t> > tlist;
207 for (list<pair<uint64_t, uint64_t> > ::const_iterator l = m->second.begin();
208 l != m->second.end(); ++l) {
209 tlist.push_back(boost::make_tuple(l->first, l->second, 0));
211 to_read[m->first] = tlist;
214 ::decode(to_read, bl);
216 ::decode(attrs_to_read, bl);
220 std::ostream &operator<<(
221 std::ostream &lhs, const ECSubRead &rhs)
224 << "ECSubRead(tid=" << rhs.tid
225 << ", to_read=" << rhs.to_read
226 << ", attrs_to_read=" << rhs.attrs_to_read << ")";
229 void ECSubRead::dump(Formatter *f) const
231 f->dump_stream("from") << from;
232 f->dump_unsigned("tid", tid);
233 f->open_array_section("objects");
234 for (map<hobject_t, list<boost::tuple<uint64_t, uint64_t, uint32_t> >>::const_iterator i =
238 f->open_object_section("object");
239 f->dump_stream("oid") << i->first;
240 f->open_array_section("extents");
241 for (list<boost::tuple<uint64_t, uint64_t, uint32_t> >::const_iterator j =
243 j != i->second.end();
245 f->open_object_section("extent");
246 f->dump_unsigned("off", j->get<0>());
247 f->dump_unsigned("len", j->get<1>());
248 f->dump_unsigned("flags", j->get<2>());
256 f->open_array_section("object_attrs_requested");
257 for (set<hobject_t>::const_iterator i = attrs_to_read.begin();
258 i != attrs_to_read.end();
260 f->open_object_section("object");
261 f->dump_stream("oid") << *i;
267 void ECSubRead::generate_test_instances(list<ECSubRead*>& o)
269 hobject_t hoid1(sobject_t("asdf", 1));
270 hobject_t hoid2(sobject_t("asdf2", CEPH_NOSNAP));
271 o.push_back(new ECSubRead());
272 o.back()->from = pg_shard_t(2, shard_id_t(-1));
274 o.back()->to_read[hoid1].push_back(boost::make_tuple(100, 200, 0));
275 o.back()->to_read[hoid1].push_back(boost::make_tuple(400, 600, 0));
276 o.back()->to_read[hoid2].push_back(boost::make_tuple(400, 600, 0));
277 o.back()->attrs_to_read.insert(hoid1);
278 o.push_back(new ECSubRead());
279 o.back()->from = pg_shard_t(2, shard_id_t(-1));
281 o.back()->to_read[hoid1].push_back(boost::make_tuple(300, 200, 0));
282 o.back()->to_read[hoid2].push_back(boost::make_tuple(400, 600, 0));
283 o.back()->to_read[hoid2].push_back(boost::make_tuple(2000, 600, 0));
284 o.back()->attrs_to_read.insert(hoid2);
287 void ECSubReadReply::encode(bufferlist &bl) const
289 ENCODE_START(1, 1, bl);
292 ::encode(buffers_read, bl);
293 ::encode(attrs_read, bl);
294 ::encode(errors, bl);
298 void ECSubReadReply::decode(bufferlist::iterator &bl)
303 ::decode(buffers_read, bl);
304 ::decode(attrs_read, bl);
305 ::decode(errors, bl);
309 std::ostream &operator<<(
310 std::ostream &lhs, const ECSubReadReply &rhs)
313 << "ECSubReadReply(tid=" << rhs.tid
314 << ", attrs_read=" << rhs.attrs_read.size()
318 void ECSubReadReply::dump(Formatter *f) const
320 f->dump_stream("from") << from;
321 f->dump_unsigned("tid", tid);
322 f->open_array_section("buffers_read");
323 for (map<hobject_t, list<pair<uint64_t, bufferlist> >>::const_iterator i =
324 buffers_read.begin();
325 i != buffers_read.end();
327 f->open_object_section("object");
328 f->dump_stream("oid") << i->first;
329 f->open_array_section("data");
330 for (list<pair<uint64_t, bufferlist> >::const_iterator j =
332 j != i->second.end();
334 f->open_object_section("extent");
335 f->dump_unsigned("off", j->first);
336 f->dump_unsigned("buf_len", j->second.length());
344 f->open_array_section("attrs_returned");
345 for (map<hobject_t, map<string, bufferlist>>::const_iterator i =
347 i != attrs_read.end();
349 f->open_object_section("object_attrs");
350 f->dump_stream("oid") << i->first;
351 f->open_array_section("attrs");
352 for (map<string, bufferlist>::const_iterator j = i->second.begin();
353 j != i->second.end();
355 f->open_object_section("attr");
356 f->dump_string("attr", j->first);
357 f->dump_unsigned("val_len", j->second.length());
365 f->open_array_section("errors");
366 for (map<hobject_t, int>::const_iterator i = errors.begin();
369 f->open_object_section("error_pair");
370 f->dump_stream("oid") << i->first;
371 f->dump_int("error", i->second);
377 void ECSubReadReply::generate_test_instances(list<ECSubReadReply*>& o)
379 hobject_t hoid1(sobject_t("asdf", 1));
380 hobject_t hoid2(sobject_t("asdf2", CEPH_NOSNAP));
384 bl2.append_zero(200);
385 o.push_back(new ECSubReadReply());
386 o.back()->from = pg_shard_t(2, shard_id_t(-1));
388 o.back()->buffers_read[hoid1].push_back(make_pair(20, bl));
389 o.back()->buffers_read[hoid1].push_back(make_pair(2000, bl2));
390 o.back()->buffers_read[hoid2].push_back(make_pair(0, bl));
391 o.back()->attrs_read[hoid1]["foo"] = bl;
392 o.back()->attrs_read[hoid1]["_"] = bl2;
393 o.push_back(new ECSubReadReply());
394 o.back()->from = pg_shard_t(2, shard_id_t(-1));
396 o.back()->buffers_read[hoid2].push_back(make_pair(0, bl2));
397 o.back()->attrs_read[hoid2]["foo"] = bl;
398 o.back()->attrs_read[hoid2]["_"] = bl2;
399 o.back()->errors[hoid1] = -2;