From 6439714927ce8ba1749dcb9a8553ec7a09ca7474 Mon Sep 17 00:00:00 2001 From: Xuehan Xu Date: Sun, 26 Apr 2020 11:41:28 +0800 Subject: [PATCH] crimson: prevent PG::schedule_event_after from creating daggling future Signed-off-by: Xuehan Xu --- src/crimson/osd/osd_operations/peering_event.cc | 11 ++++++++++- src/crimson/osd/osd_operations/peering_event.h | 13 ++++++++++++- src/crimson/osd/pg.h | 12 +++--------- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/crimson/osd/osd_operations/peering_event.cc b/src/crimson/osd/osd_operations/peering_event.cc index 9f1be69b604..8c4cfbc89b6 100644 --- a/src/crimson/osd/osd_operations/peering_event.cc +++ b/src/crimson/osd/osd_operations/peering_event.cc @@ -53,7 +53,16 @@ seastar::future<> PeeringEvent::start() logger().debug("{}: start", *this); IRef ref = this; - return get_pg().then([this](Ref pg) { + return [this] { + if (delay) { + return seastar::sleep(std::chrono::milliseconds( + std::lround(delay*1000))); + } else { + return seastar::now(); + } + }().then([this] { + return get_pg(); + }).then([this](Ref pg) { if (!pg) { logger().warn("{}: pg absent, did not create", *this); on_pg_absent(); diff --git a/src/crimson/osd/osd_operations/peering_event.h b/src/crimson/osd/osd_operations/peering_event.h index d9b57a3477a..3a6c0678c46 100644 --- a/src/crimson/osd/osd_operations/peering_event.h +++ b/src/crimson/osd/osd_operations/peering_event.h @@ -44,6 +44,7 @@ protected: PeeringCtx ctx; pg_shard_t from; spg_t pgid; + float delay = 0; PGPeeringEvent evt; const pg_shard_t get_from() const { @@ -73,7 +74,17 @@ public: pgid(pgid), evt(std::forward(args)...) {} - + template + PeeringEvent( + ShardServices &shard_services, const pg_shard_t &from, const spg_t &pgid, + float delay, Args&&... args) : + shard_services(shard_services), + ctx{ceph_release_t::octopus}, + from(from), + pgid(pgid), + delay(delay), + evt(std::forward(args)...) + {} void print(std::ostream &) const final; void dump_detail(ceph::Formatter* f) const final; diff --git a/src/crimson/osd/pg.h b/src/crimson/osd/pg.h index e5f20c701b9..c10139bff76 100644 --- a/src/crimson/osd/pg.h +++ b/src/crimson/osd/pg.h @@ -180,26 +180,20 @@ public: } template - void start_peering_event_operation(T &&evt) { + void start_peering_event_operation(T &&evt, float delay = 0) { shard_services.start_operation( this, shard_services, pg_whoami, pgid, + delay, std::forward(evt)); } void schedule_event_after( PGPeeringEventRef event, float delay) final { - // TODO: this is kind of a hack -- once the start_operation call - // happens, the operation will be registered, but during the delay - // it's just a dangling future. It would be nice for the - // operation machinery to have something to take care of this. - (void)seastar::sleep(std::chrono::milliseconds(std::lround(delay*1000))).then( - [this, event=std::move(event)]() { - start_peering_event_operation(std::move(*event)); - }); + start_peering_event_operation(std::move(*event), delay); } std::vector get_replica_recovery_order() const final { return peering_state.get_replica_recovery_order(); -- 2.47.3