Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/crimson/osd/osd_operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ enum class OperationTypeCode {
scrub_scan,
pgpct_request,
ecrep_request,
snap_trim_initiate,
last_op
};

Expand All @@ -133,6 +134,7 @@ static constexpr const char* const OP_NAMES[] = {
"scrub_scan",
"pgpct_request",
"ecrep_request",
"snap_trim_initiate",
};

// prevent the addition of OperationTypeCode-s with no matching OP_NAMES entry:
Expand Down
26 changes: 26 additions & 0 deletions src/crimson/osd/osd_operations/snaptrim_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ namespace crimson {
return {};
}
};

template <>
struct EventBackendRegistry<osd::SnapTrimInitiate> {
static std::tuple<> get_backends() {
return {};
}
};
}

namespace crimson::osd {
Expand Down Expand Up @@ -466,4 +473,23 @@ void SnapTrimObjSubEvent::dump_detail(Formatter *f) const
f->close_section();
}

void SnapTrimInitiate::print(std::ostream &lhs) const
{
fmt::print(lhs, "SnapTrimInitiate(pgid={})", pg->get_pgid());
}

void SnapTrimInitiate::dump_detail(Formatter *f) const
{
Formatter::ObjectSection section(*f, "SnapTrimInitiate");
f->dump_stream("pgid") << pg->get_pgid();
}

seastar::future<> SnapTrimInitiate::start()
{
logger().debug("{}: start", *this);
pg->initiate_snap_trim();
logger().debug("{}: complete", *this);
co_return;
}

} // namespace crimson::osd
31 changes: 31 additions & 0 deletions src/crimson/osd/osd_operations/snaptrim_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <iostream>
#include <seastar/core/future.hh>

#include "common/fmt_common.h"
#include "crimson/osd/object_context_loader.h"
#include "crimson/osd/osdmap_gate.h"
#include "crimson/osd/osd_operation.h"
Expand Down Expand Up @@ -173,6 +174,36 @@ class SnapTrimObjSubEvent : public PhasedOperationT<SnapTrimObjSubEvent> {
> tracking_events;
};

class SnapTrimInitiate final : public PhasedOperationT<SnapTrimInitiate> {
public:
static constexpr OperationTypeCode type =
OperationTypeCode::snap_trim_initiate;

SnapTrimInitiate(Ref<PG> pg) : pg(std::move(pg)) {}

void print(std::ostream &) const final;
void dump_detail(ceph::Formatter* f) const final;
seastar::future<> start();

template <typename FormatContext>
auto fmt_print_ctx(FormatContext& ctx) const {
return fmt::format_to(ctx.out(), "SnapTrimInitiate(pgid={})",
pg->get_pgid());
}

private:
Ref<PG> pg;
PipelineHandle handle;

public:
PipelineHandle& get_handle() { return handle; }

std::tuple<
StartEvent,
CompletionEvent
> tracking_events;
};

} // namespace crimson::osd

#if FMT_VERSION >= 90000
Expand Down
17 changes: 11 additions & 6 deletions src/crimson/osd/pg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,12 @@ PG::interruptible_future<seastar::stop_iteration> PG::trim_snap(
}

void PG::on_active_actmap()
{
logger().debug("{}: {}", *this, __func__);
initiate_snap_trim();
}

void PG::initiate_snap_trim()
{
logger().debug("{}: {} snap_trimq={}", *this, __func__, snap_trimq);
peering_state.state_clear(PG_STATE_SNAPTRIM_ERROR);
Expand All @@ -634,14 +640,13 @@ void PG::on_active_actmap()
logger().debug("{}: {} already trimming.", *this, __func__);
return;
}
// Temporary: defer snap trimming while scrubbing, until the full scrub
// scheduling code (including is_scrub_queued_or_active()) is merged.
// (mark https://tracker.ceph.com/issues/76428 as solved once fixed).
if (peering_state.state_test(PG_STATE_SCRUBBING)) {
logger().info("{}: {} scrubbing, deferring snap trim", *this, __func__);
return;
}
// loops until snap_trimq is empty or SNAPTRIM_ERROR.
if (snap_trimq.empty()) {
return;
}
Ref<PG> pg_ref = this;
std::ignore = interruptor::with_interruption([this] {
return interruptor::repeat(
Expand All @@ -658,7 +663,7 @@ void PG::on_active_actmap()
return trim_snap(to_trim, needs_pause);
}
).then_interruptible([this] {
logger().debug("{}: PG::on_active_actmap() finished trimming",
logger().debug("{}: PG::initiate_snap_trim() finished trimming",
*this);
peering_state.state_clear(PG_STATE_SNAPTRIM);
peering_state.state_clear(PG_STATE_SNAPTRIM_ERROR);
Expand All @@ -681,7 +686,7 @@ void PG::kick_snap_trim()
&& !snap_trimq.empty()
&& !peering_state.state_test(PG_STATE_SNAPTRIM)) {
logger().info("{}: scrub complete, retriggering snap trim", *this);
on_active_actmap();
(void) shard_services.start_operation<SnapTrimInitiate>(this);
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/crimson/osd/pg.h
Original file line number Diff line number Diff line change
Expand Up @@ -912,8 +912,12 @@ class PG
bool needs_pause);
/// Re-trigger snap trimming after scrub completion. Snap trimming is
/// deferred while the PG is scrubbing; call this from notify_scrub_end()
/// to resume.
/// to resume. Spawns a SnapTrimInitiate operation to avoid nesting
/// interrupt conditions.
void kick_snap_trim();
/// Initiate the snap trim loop with all state checks. Called from
/// SnapTrimInitiate and on_active_actmap().
void initiate_snap_trim();

private:
PG_OSDMapGate osdmap_gate;
Expand Down Expand Up @@ -1156,6 +1160,7 @@ class PG
friend class WatchTimeoutRequest;
friend class SnapTrimEvent;
friend class SnapTrimObjSubEvent;
friend class SnapTrimInitiate;
friend ECBackend;
private:

Expand Down
Loading