Skip to content

Commit 38d9cf4

Browse files
committed
osd/scrub: introduce ScrubStore::at_level_t
to hold the caching and backend details related to the representation of scrub-detected errors as OMap entries of a uniquely-named object. In a followup commit - the ScrubStore is modified to hold two of these objects, one for the shallow errors and one for the deep errors. Signed-off-by: Ronen Friedman <[email protected]>
1 parent 398563d commit 38d9cf4

File tree

2 files changed

+79
-23
lines changed

2 files changed

+79
-23
lines changed

src/osd/scrubber/ScrubStore.cc

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,29 @@ Store::create(ObjectStore* store,
109109
ceph_assert(t);
110110
ghobject_t oid = make_scrub_object(pgid);
111111
t->touch(coll, oid);
112-
return new Store{coll, oid, store};
112+
return new Store{*store, t, pgid, coll};
113+
}
114+
115+
116+
Store::Store(
117+
ObjectStore& osd_store,
118+
ObjectStore::Transaction* t,
119+
const spg_t& pgid,
120+
const coll_t& coll)
121+
: object_store{osd_store}
122+
, coll{coll}
123+
{
124+
ceph_assert(t);
125+
126+
const auto err_obj = pgid.make_temp_ghobject(fmt::format("scrub_{}", pgid));
127+
t->touch(coll, err_obj);
128+
errors_db.emplace(pgid, err_obj, OSDriver{&object_store, coll, err_obj});
113129
}
114130

115-
Store::Store(const coll_t& coll, const ghobject_t& oid, ObjectStore* store)
116-
: coll(coll),
117-
hoid(oid),
118-
driver(store, coll, hoid),
119-
backend(&driver)
120-
{}
121131

122132
Store::~Store()
123133
{
124-
ceph_assert(results.empty());
134+
ceph_assert(!errors_db || errors_db->results.empty());
125135
}
126136

127137
void Store::add_error(int64_t pool, const inconsistent_obj_wrapper& e)
@@ -131,11 +141,13 @@ void Store::add_error(int64_t pool, const inconsistent_obj_wrapper& e)
131141

132142
void Store::add_object_error(int64_t pool, const inconsistent_obj_wrapper& e)
133143
{
144+
const auto key = to_object_key(pool, e.object);
134145
bufferlist bl;
135146
e.encode(bl);
136-
results[to_object_key(pool, e.object)] = bl;
147+
errors_db->results[key] = bl;
137148
}
138149

150+
139151
void Store::add_error(int64_t pool, const inconsistent_snapset_wrapper& e)
140152
{
141153
add_snap_error(pool, e);
@@ -145,26 +157,28 @@ void Store::add_snap_error(int64_t pool, const inconsistent_snapset_wrapper& e)
145157
{
146158
bufferlist bl;
147159
e.encode(bl);
148-
results[to_snap_key(pool, e.object)] = bl;
160+
errors_db->results[to_snap_key(pool, e.object)] = bl;
149161
}
150162

151163
bool Store::empty() const
152164
{
153-
return results.empty();
165+
return errors_db->results.empty();
154166
}
155167

156168
void Store::flush(ObjectStore::Transaction* t)
157169
{
158170
if (t) {
159-
OSDriver::OSTransaction txn = driver.get_transaction(t);
160-
backend.set_keys(results, &txn);
171+
OSDriver::OSTransaction txn = errors_db->driver.get_transaction(t);
172+
errors_db->backend.set_keys(errors_db->results, &txn);
161173
}
162-
results.clear();
174+
errors_db->results.clear();
163175
}
164176

165177
void Store::cleanup(ObjectStore::Transaction* t)
166178
{
167-
t->remove(coll, hoid);
179+
ceph_assert(t);
180+
if (errors_db)
181+
t->remove(coll, errors_db->errors_hoid);
168182
}
169183

170184
std::vector<bufferlist>
@@ -195,8 +209,11 @@ Store::get_errors(const string& begin,
195209
uint64_t max_return) const
196210
{
197211
vector<bufferlist> errors;
212+
if (!errors_db)
213+
return errors;
214+
198215
auto next = std::make_pair(begin, bufferlist{});
199-
while (max_return && !backend.get_next(next.first, &next)) {
216+
while (max_return && !errors_db->backend.get_next(next.first, &next)) {
200217
if (next.first >= end)
201218
break;
202219
errors.push_back(next.second);

src/osd/scrubber/ScrubStore.h

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define CEPH_SCRUB_RESULT_H
66

77
#include "common/map_cacher.hpp"
8+
#include "osd/osd_types_fmt.h"
89
#include "osd/SnapMapper.h" // for OSDriver
910

1011
namespace librados {
@@ -45,18 +46,56 @@ class Store {
4546
uint64_t max_return) const;
4647

4748
private:
48-
Store(const coll_t& coll, const ghobject_t& oid, ObjectStore* store);
49+
/**
50+
* at_level_t
51+
*
52+
* The machinery for caching and storing errors at a specific scrub level.
53+
*/
54+
struct at_level_t {
55+
at_level_t(const spg_t& pgid, const ghobject_t& err_obj, OSDriver&& drvr)
56+
: errors_hoid{err_obj}
57+
, driver{std::move(drvr)}
58+
, backend{&driver}
59+
{}
60+
61+
/// the object in the PG store, where the errors are stored
62+
ghobject_t errors_hoid;
63+
64+
/// abstracted key fetching
65+
OSDriver driver;
66+
67+
/// a K,V cache for the errors that are detected during the scrub
68+
/// session. The errors marked for a specific object are stored as
69+
/// an OMap entry with the object's name as the key.
70+
MapCacher::MapCacher<std::string, ceph::buffer::list> backend;
71+
72+
/// a temp object mapping seq-id to inconsistencies
73+
std::map<std::string, ceph::buffer::list> results;
74+
};
75+
76+
Store(ObjectStore& osd_store,
77+
ObjectStore::Transaction* t,
78+
const spg_t& pgid,
79+
const coll_t& coll);
80+
4981
std::vector<ceph::buffer::list> get_errors(const std::string& start,
5082
const std::string& end,
5183
uint64_t max_return) const;
5284
private:
85+
/// the OSD's storage backend
86+
ObjectStore& object_store;
87+
88+
/// the collection (i.e. - the PG store) in which the errors are stored
5389
const coll_t coll;
54-
const ghobject_t hoid;
55-
// a temp object holding mappings from seq-id to inconsistencies found in
56-
// scrubbing
57-
OSDriver driver;
58-
mutable MapCacher::MapCacher<std::string, ceph::buffer::list> backend;
59-
std::map<std::string, ceph::buffer::list> results;
90+
91+
/**
92+
* the machinery (backend details, cache, etc.) for storing both levels
93+
* of errors (note: 'optional' to allow delayed creation w/o dynamic
94+
* allocations; and 'mutable', as the caching mechanism is used in const
95+
* methods)
96+
*/
97+
mutable std::optional<at_level_t> errors_db;
98+
// not yet: mutable std::optional<at_level_t> deep_db;
6099
};
61100
} // namespace Scrub
62101

0 commit comments

Comments
 (0)