Skip to content

Commit ce9771b

Browse files
authored
Merge pull request ceph#53104 from ceph/revert-49428-maintain_prefix_itr
Revert "osd/SnapMapper: Maintain the prefix_itr between calls to avoid search…" Reviewed-by: Gabriel BenHanokh <[email protected]> Reviewed-by: Neha Ojha <[email protected]>
2 parents 4a6f6ed + b77ebe8 commit ce9771b

File tree

7 files changed

+49
-403
lines changed

7 files changed

+49
-403
lines changed

qa/suites/rados/singleton-nomsgr/all/ceph-snapmapper.yaml

Lines changed: 0 additions & 22 deletions
This file was deleted.

qa/tasks/ceph.conf.template

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@
5555
osd debug shutdown = true
5656
osd debug op order = true
5757
osd debug verify stray on activate = true
58-
osd debug trim objects = true
5958

60-
osd open classes on start = true
59+
osd open classes on start = true
6160
osd debug pg log writeout = true
6261

6362
osd deep scrub update digest min age = 30

src/common/options/osd.yaml.in

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,6 @@ options:
194194
load on busy clusters.
195195
default: false
196196
with_legacy: true
197-
- name: osd_debug_trim_objects
198-
type: bool
199-
level: advanced
200-
desc: Asserts that no clone-objects were added to a snap after we start trimming it
201-
default: false
202197
- name: osd_repair_during_recovery
203198
type: bool
204199
level: advanced

src/osd/SnapMapper.cc

Lines changed: 17 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -540,28 +540,36 @@ void SnapMapper::add_oid(
540540
backend.set_keys(to_add, t);
541541
}
542542

543-
void SnapMapper::get_objects_by_prefixes(
543+
int SnapMapper::get_next_objects_to_trim(
544544
snapid_t snap,
545545
unsigned max,
546546
vector<hobject_t> *out)
547547
{
548-
/// maintain the prefix_itr between calls to avoid searching depleted prefixes
549-
for ( ; prefix_itr != prefixes.end(); prefix_itr++) {
550-
string prefix(get_prefix(pool, snap) + *prefix_itr);
548+
ceph_assert(out);
549+
ceph_assert(out->empty());
550+
551+
// if max would be 0, we return ENOENT and the caller would mistakenly
552+
// trim the snaptrim queue
553+
ceph_assert(max > 0);
554+
int r = 0;
555+
556+
/// \todo cache the prefixes-set in update_bits()
557+
for (set<string>::iterator i = prefixes.begin();
558+
i != prefixes.end() && out->size() < max && r == 0;
559+
++i) {
560+
string prefix(get_prefix(pool, snap) + *i);
551561
string pos = prefix;
552562
while (out->size() < max) {
553563
pair<string, ceph::buffer::list> next;
554-
// access RocksDB (an expensive operation!)
555-
int r = backend.get_next(pos, &next);
564+
r = backend.get_next(pos, &next);
556565
dout(20) << __func__ << " get_next(" << pos << ") returns " << r
557566
<< " " << next << dendl;
558567
if (r != 0) {
559-
return; // Done
568+
break; // Done
560569
}
561570

562571
if (next.first.substr(0, prefix.size()) !=
563572
prefix) {
564-
// TBD: we access the DB twice for the first object of each iterator...
565573
break; // Done with this prefix
566574
}
567575

@@ -575,59 +583,15 @@ void SnapMapper::get_objects_by_prefixes(
575583
out->push_back(next_decoded.second);
576584
pos = next.first;
577585
}
578-
579-
if (out->size() >= max) {
580-
return;
581-
}
582586
}
583-
}
584-
585-
int SnapMapper::get_next_objects_to_trim(
586-
snapid_t snap,
587-
unsigned max,
588-
vector<hobject_t> *out)
589-
{
590-
ceph_assert(out);
591-
ceph_assert(out->empty());
592-
593-
// if max would be 0, we return ENOENT and the caller would mistakenly
594-
// trim the snaptrim queue
595-
ceph_assert(max > 0);
596-
597-
// The prefix_itr is bound to a prefix_itr_snap so if we trim another snap
598-
// we must reset the prefix_itr (should not happen normally)
599-
if (prefix_itr_snap != snap) {
600-
dout(10) << __func__ << "::Reset prefix_itr(unexpcted) snap was changed from <"
601-
<< prefix_itr_snap << "> to <" << snap << ">" << dendl;
602-
reset_prefix_itr(snap);
603-
}
604-
605-
// when reaching the end of the DB reset the prefix_ptr and verify
606-
// we didn't miss objects which were added after we started trimming
607-
// This should never happen in reality because the snap was logically deleted
608-
// before trimming starts (and so no new clone-objects could be added)
609-
// For more info see PG::filter_snapc()
610-
//
611-
// We still like to be extra careful and run one extra loop over all prefeixes
612-
get_objects_by_prefixes(snap, max, out);
613-
if (out->size() == 0) {
614-
dout(10) << __func__ << "::Reset prefix_itr after a complete trim!" << dendl;
615-
reset_prefix_itr(snap);
616-
get_objects_by_prefixes(snap, max, out);
617-
618-
bool osd_debug_trim_objects = cct->_conf.get_val<bool>("osd_debug_trim_objects");
619-
if (osd_debug_trim_objects) {
620-
ceph_assert(out->size() == 0);
621-
}
622-
}
623-
624587
if (out->size() == 0) {
625588
return -ENOENT;
626589
} else {
627590
return 0;
628591
}
629592
}
630593

594+
631595
int SnapMapper::remove_oid(
632596
const hobject_t &oid,
633597
MapCacher::Transaction<std::string, ceph::buffer::list> *t)

src/osd/SnapMapper.h

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -281,24 +281,6 @@ class SnapMapper : public Scrub::SnapMapReaderI {
281281
tl::expected<object_snaps, SnapMapReaderI::result_t> get_snaps_common(
282282
const hobject_t &hoid) const;
283283

284-
/// file @out vector with the first objects with @snap as a snap
285-
void get_objects_by_prefixes(
286-
snapid_t snap,
287-
unsigned max,
288-
std::vector<hobject_t> *out);
289-
290-
std::set<std::string> prefixes;
291-
// maintain a current active prefix
292-
std::set<std::string>::iterator prefix_itr;
293-
// associate the active prefix with a snap
294-
snapid_t prefix_itr_snap;
295-
296-
// reset the prefix iterator to the first prefix hash
297-
void reset_prefix_itr(snapid_t snap) {
298-
prefix_itr_snap = snap;
299-
prefix_itr = prefixes.begin();
300-
}
301-
302284
public:
303285
static std::string make_shard_prefix(shard_id_t shard) {
304286
if (shard == shard_id_t::NO_SHARD)
@@ -327,6 +309,7 @@ class SnapMapper : public Scrub::SnapMapReaderI {
327309
update_bits(mask_bits);
328310
}
329311

312+
std::set<std::string> prefixes;
330313
/// Update bits in case of pg split or merge
331314
void update_bits(
332315
uint32_t new_bits ///< [in] new split bits
@@ -340,12 +323,6 @@ class SnapMapper : public Scrub::SnapMapReaderI {
340323
for (auto i = _prefixes.begin(); i != _prefixes.end(); ++i) {
341324
prefixes.insert(shard_prefix + *i);
342325
}
343-
344-
reset_prefix_itr(CEPH_NOSNAP);
345-
}
346-
347-
const std::set<std::string>::iterator get_prefix_itr() {
348-
return prefix_itr;
349326
}
350327

351328
/// Update snaps for oid, empty new_snaps removes the mapping

src/test/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,6 @@ add_executable(ceph_test_snap_mapper
466466
$<TARGET_OBJECTS:unit-main>
467467
)
468468
target_link_libraries(ceph_test_snap_mapper osd global ${BLKID_LIBRARIES} ${UNITTEST_LIBS})
469-
470-
install(TARGETS
471-
ceph_test_snap_mapper
472-
DESTINATION ${CMAKE_INSTALL_BINDIR})
473469
endif(NOT WIN32)
474470

475471
add_executable(ceph_test_stress_watch

0 commit comments

Comments
 (0)