Skip to content

Commit e2733f3

Browse files
committed
osd: use with_array_sections()
... in a couple of functions, as a demonstration of its usage. Signed-off-by: Ronen Friedman <[email protected]>
1 parent dff8360 commit e2733f3

File tree

2 files changed

+70
-77
lines changed

2 files changed

+70
-77
lines changed

src/osd/ECMsgTypes.cc

Lines changed: 63 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ using std::set;
2222
using ceph::bufferlist;
2323
using ceph::Formatter;
2424

25+
using namespace std::literals;
26+
2527
void ECSubWrite::encode(bufferlist &bl) const
2628
{
2729
ENCODE_START(4, 1, bl);
@@ -242,32 +244,28 @@ std::ostream &operator<<(
242244

243245
void ECSubRead::dump(Formatter *f) const
244246
{
247+
using extent_t = boost::tuple<uint64_t, uint64_t, uint32_t>;
248+
245249
f->dump_stream("from") << from;
246250
f->dump_unsigned("tid", tid);
247-
f->open_array_section("objects");
248-
for (auto i = to_read.cbegin(); i != to_read.cend(); ++i) {
249-
f->open_object_section("object");
250-
f->dump_stream("oid") << i->first;
251-
f->open_array_section("extents");
252-
for (auto j = i->second.cbegin(); j != i->second.cend(); ++j) {
253-
f->open_object_section("extent");
254-
f->dump_unsigned("off", j->get<0>());
255-
f->dump_unsigned("len", j->get<1>());
256-
f->dump_unsigned("flags", j->get<2>());
257-
f->close_section();
258-
}
259-
f->close_section();
260-
f->close_section();
261-
}
262-
f->close_section();
263251

264-
f->open_array_section("object_attrs_requested");
265-
for (auto i = attrs_to_read.cbegin(); i != attrs_to_read.cend(); ++i) {
266-
f->open_object_section("object");
267-
f->dump_stream("oid") << *i;
268-
f->close_section();
269-
}
270-
f->close_section();
252+
// 'to_read' (map<hobject_t, list<tuple<offset, length, flags>>>)
253+
f->with_obj_array_section(
254+
"object"sv, to_read,
255+
[](Formatter& f, const hobject_t& oid, const list<extent_t>& extents) {
256+
f.dump_stream("oid") << oid;
257+
f.with_obj_array_section(
258+
"extent", extents, [](Formatter& f, const extent_t& extent) {
259+
f.dump_unsigned("off", extent.get<0>());
260+
f.dump_unsigned("len", extent.get<1>());
261+
f.dump_unsigned("flags", extent.get<2>());
262+
});
263+
});
264+
265+
// 'object_attrs_requested': 'attrs_to_read' (set<hobject_t>)
266+
f->with_obj_array_section(
267+
"object_attrs_requested"sv, attrs_to_read,
268+
[](Formatter& f, const hobject_t& oid) { f.dump_stream("oid") << oid; });
271269
}
272270

273271
void ECSubRead::generate_test_instances(list<ECSubRead*>& o)
@@ -321,50 +319,51 @@ std::ostream &operator<<(
321319
<< ")";
322320
}
323321

324-
void ECSubReadReply::dump(Formatter *f) const
322+
323+
void ECSubReadReply::dump(Formatter* f) const
325324
{
325+
using offset_pair_t = pair<uint64_t, bufferlist>;
326+
using extents_list_t = list<offset_pair_t>;
327+
326328
f->dump_stream("from") << from;
327329
f->dump_unsigned("tid", tid);
328-
f->open_array_section("buffers_read");
329-
for (auto i = buffers_read.cbegin(); i != buffers_read.cend(); ++i) {
330-
f->open_object_section("object");
331-
f->dump_stream("oid") << i->first;
332-
f->open_array_section("data");
333-
for (auto j = i->second.cbegin(); j != i->second.cend(); ++j) {
334-
f->open_object_section("extent");
335-
f->dump_unsigned("off", j->first);
336-
f->dump_unsigned("buf_len", j->second.length());
337-
f->close_section();
338-
}
339-
f->close_section();
340-
f->close_section();
341-
}
342-
f->close_section();
343-
344-
f->open_array_section("attrs_returned");
345-
for (auto i = attrs_read.cbegin(); i != attrs_read.cend(); ++i) {
346-
f->open_object_section("object_attrs");
347-
f->dump_stream("oid") << i->first;
348-
f->open_array_section("attrs");
349-
for (auto j = i->second.cbegin(); j != i->second.cend(); ++j) {
350-
f->open_object_section("attr");
351-
f->dump_string("attr", j->first);
352-
f->dump_unsigned("val_len", j->second.length());
353-
f->close_section();
354-
}
355-
f->close_section();
356-
f->close_section();
357-
}
358-
f->close_section();
359-
360-
f->open_array_section("errors");
361-
for (auto i = errors.cbegin(); i != errors.cend(); ++i) {
362-
f->open_object_section("error_pair");
363-
f->dump_stream("oid") << i->first;
364-
f->dump_int("error", i->second);
365-
f->close_section();
366-
}
367-
f->close_section();
330+
331+
// 'buffers_read' (map<hobject_t, list<pair<uint64_t, bufferlist>>>)
332+
f->with_obj_array_section(
333+
"object"sv, buffers_read,
334+
[](Formatter& f, const hobject_t& oid, const extents_list_t& l) {
335+
f.dump_stream("oid") << oid;
336+
f.with_obj_array_section(
337+
"extent", l,
338+
[](Formatter& f, const offset_pair_t& offset_n_bl) {
339+
const auto& [off, bl] = offset_n_bl;
340+
f.dump_unsigned("off", off);
341+
f.dump_unsigned("buf_len", bl.length());
342+
});
343+
});
344+
345+
// "attrs_returned" (mapping hobject_t to a <string to bl> table)
346+
f->with_obj_array_section(
347+
"object_attrs"sv, attrs_read,
348+
[](Formatter& f, const hobject_t& oid,
349+
const std::map<std::string, ceph::buffer::list, std::less<>>& m) {
350+
f.dump_stream("oid") << oid;
351+
f.with_obj_array_section(
352+
"attr", m,
353+
[](Formatter& f, const std::string& attr,
354+
const ceph::buffer::list& bl) {
355+
f.dump_string("attr", attr);
356+
f.dump_unsigned("val_len", bl.length());
357+
});
358+
});
359+
360+
// "errors": map<hobject_t, int>
361+
f->with_obj_array_section(
362+
"error_pair"sv, errors,
363+
[](Formatter& f, const hobject_t& oid, int err) {
364+
f.dump_stream("oid") << oid;
365+
f.dump_int("error", err);
366+
});
368367
}
369368

370369
void ECSubReadReply::generate_test_instances(list<ECSubReadReply*>& o)

src/osd/scrubber/pg_scrubber.cc

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,12 +2342,10 @@ void PgScrubber::dump_active_scrubber(ceph::Formatter* f) const
23422342
f->dump_int("shallow_errors", m_shallow_errors);
23432343
f->dump_int("deep_errors", m_deep_errors);
23442344
f->dump_int("fixed", m_fixed_count);
2345-
{
2346-
Formatter::ArraySection waiting_on_whom{*f, "waiting_on_whom"sv};
2347-
for (const auto& p : m_maps_status.get_awaited()) {
2348-
f->dump_stream("shard") << p;
2349-
}
2350-
}
2345+
f->with_array_section(
2346+
"waiting_on_whom"sv, m_maps_status.get_awaited(),
2347+
[](Formatter& f, const pg_shard_t& sh) { f.dump_stream("shard") << sh; });
2348+
23512349
if (m_scrub_job->blocked) {
23522350
f->dump_string("schedule", "blocked");
23532351
} else {
@@ -2480,13 +2478,9 @@ void PgScrubber::handle_query_state(ceph::Formatter* f)
24802478
f->dump_stream("scrubber.max_end") << m_max_end;
24812479
f->dump_stream("scrubber.subset_last_update") << m_subset_last_update;
24822480
f->dump_bool("scrubber.deep", m_is_deep);
2483-
{
2484-
Formatter::ArraySection waiting_on_whom{*f, "waiting_on_whom"sv};
2485-
for (const auto& p : m_maps_status.get_awaited()) {
2486-
f->dump_stream("shard") << p;
2487-
}
2488-
}
2489-
2481+
f->with_array_section(
2482+
"waiting_on_whom"sv, m_maps_status.get_awaited(),
2483+
[](Formatter& f, const pg_shard_t& sh) { f.dump_stream("shard") << sh; });
24902484
f->dump_string("comment", "DEPRECATED - may be removed in the next release");
24912485
}
24922486

0 commit comments

Comments
 (0)