Skip to content

Commit 85dff0d

Browse files
committed
crimson/osd: purge strays when PGs go clean
Signed-off-by: Xuehan Xu <[email protected]>
1 parent 82de5f0 commit 85dff0d

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

src/crimson/osd/osd.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "messages/MOSDOp.h"
2424
#include "messages/MOSDPeeringOp.h"
2525
#include "messages/MOSDPGCreate2.h"
26+
#include "messages/MOSDPGRemove.h"
2627
#include "messages/MOSDPGUpdateLogMissing.h"
2728
#include "messages/MOSDPGUpdateLogMissingReply.h"
2829
#include "messages/MOSDRepOpReply.h"
@@ -863,6 +864,8 @@ OSD::do_ms_dispatch(
863864
[[fallthrough]];
864865
case MSG_OSD_PG_LOG:
865866
return handle_peering_op(conn, boost::static_pointer_cast<MOSDPeeringOp>(m));
867+
case MSG_OSD_PG_REMOVE:
868+
return handle_pg_remove(conn, boost::static_pointer_cast<MOSDPGRemove>(m));
866869
case MSG_OSD_REPOP:
867870
return handle_rep_op(conn, boost::static_pointer_cast<MOSDRepOp>(m));
868871
case MSG_OSD_REPOPREPLY:
@@ -1555,6 +1558,27 @@ seastar::future<> OSD::handle_peering_op(
15551558
std::move(*evt)).second;
15561559
}
15571560

1561+
seastar::future<> OSD::handle_pg_remove(
1562+
crimson::net::ConnectionRef conn,
1563+
Ref<MOSDPGRemove> m)
1564+
{
1565+
LOG_PREFIX(OSD::handle_pg_remove);
1566+
const int from = m->get_source().num();
1567+
std::vector<seastar::future<>> futs;
1568+
for (auto &pg : m->pg_list) {
1569+
DEBUG("{} from {}", pg, from);
1570+
futs.emplace_back(
1571+
pg_shard_manager.start_pg_operation<RemotePeeringEvent>(
1572+
conn,
1573+
pg_shard_t{from, pg.shard},
1574+
pg,
1575+
m->get_epoch(),
1576+
m->get_epoch(),
1577+
PeeringState::DeleteStart()).second);
1578+
}
1579+
return seastar::when_all_succeed(std::move(futs));
1580+
}
1581+
15581582
seastar::future<> OSD::check_osdmap_features()
15591583
{
15601584
LOG_PREFIX(OSD::check_osdmap_features);

src/crimson/osd/osd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ class OSD final : public crimson::net::Dispatcher,
208208
Ref<MOSDRepOpReply> m);
209209
seastar::future<> handle_peering_op(crimson::net::ConnectionRef conn,
210210
Ref<MOSDPeeringOp> m);
211+
seastar::future<> handle_pg_remove(crimson::net::ConnectionRef conn,
212+
Ref<MOSDPGRemove> m);
211213
seastar::future<> handle_recovery_subreq(crimson::net::ConnectionRef conn,
212214
Ref<MOSDFastDispatchOp> m);
213215
seastar::future<> handle_scrub_command(crimson::net::ConnectionRef conn,

src/crimson/osd/pg.cc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,8 @@ Context *PG::on_clean()
517517
{
518518
recovery_handler->on_pg_clean();
519519
scrubber.on_primary_active_clean();
520-
return nullptr;
520+
recovery_finisher = new C_PG_FinishRecovery(*this);
521+
return recovery_finisher;
521522
}
522523

523524
seastar::future<> PG::clear_temp_objects()
@@ -1883,4 +1884,19 @@ void PG::cancel_pglog_based_recovery_op() {
18831884
pglog_based_recovery_op->cancel();
18841885
reset_pglog_based_recovery_op();
18851886
}
1887+
1888+
void PG::C_PG_FinishRecovery::finish(int r) {
1889+
LOG_PREFIX(PG::C_PG_FinishRecovery::finish);
1890+
auto &peering_state = pg.get_peering_state();
1891+
if (peering_state.is_deleting() || !peering_state.is_clean()) {
1892+
DEBUGDPP("raced with delete or repair", pg);
1893+
return;
1894+
}
1895+
if (this == pg.recovery_finisher) {
1896+
peering_state.purge_strays();
1897+
pg.recovery_finisher = nullptr;
1898+
} else {
1899+
DEBUGDPP("stale recovery finsher", pg);
1900+
}
1901+
}
18861902
}

src/crimson/osd/pg.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ class PG : public boost::intrusive_ref_counter<
375375
}
376376
void check_blocklisted_watchers() final;
377377
void clear_primary_state() final {
378-
// Not needed yet
378+
recovery_finisher = nullptr;
379379
}
380380

381381
void queue_check_readable(epoch_t last_peering_reset,
@@ -394,7 +394,7 @@ class PG : public boost::intrusive_ref_counter<
394394
void on_replica_activate() final;
395395
void on_activate_complete() final;
396396
void on_new_interval() final {
397-
// Not needed yet
397+
recovery_finisher = nullptr;
398398
}
399399
Context *on_clean() final;
400400
void on_activate_committed() final {
@@ -712,9 +712,17 @@ class PG : public boost::intrusive_ref_counter<
712712
}
713713
seastar::future<> stop();
714714
private:
715+
class C_PG_FinishRecovery : public Context {
716+
public:
717+
explicit C_PG_FinishRecovery(PG &pg) : pg(pg) {}
718+
void finish(int r) override;
719+
private:
720+
PG& pg;
721+
};
715722
std::unique_ptr<PGBackend> backend;
716723
std::unique_ptr<RecoveryBackend> recovery_backend;
717724
std::unique_ptr<PGRecovery> recovery_handler;
725+
C_PG_FinishRecovery *recovery_finisher;
718726

719727
PeeringState peering_state;
720728
eversion_t projected_last_update;

0 commit comments

Comments
 (0)