From 51cabbff7b51c01853bf159e513bc889287306c4 Mon Sep 17 00:00:00 2001 From: Yingxin Cheng Date: Fri, 28 Feb 2020 12:22:54 +0800 Subject: [PATCH] crimson/osd: use cancellable timer to dispatch delayed events Signed-off-by: Yingxin Cheng --- src/crimson/osd/pg.cc | 11 ++++++++--- src/crimson/osd/pg.h | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/crimson/osd/pg.cc b/src/crimson/osd/pg.cc index 991002b90b207..37f7535d40656 100644 --- a/src/crimson/osd/pg.cc +++ b/src/crimson/osd/pg.cc @@ -13,7 +13,6 @@ #include #include #include -#include #include "messages/MOSDOp.h" #include "messages/MOSDOpReply.h" @@ -141,7 +140,8 @@ bool PG::try_flush_or_schedule_async() { void PG::queue_check_readable(epoch_t last_peering_reset, ceph::timespan delay) { // handle the peering event in the background - std::ignore = seastar::sleep(delay).then([last_peering_reset, this] { + check_readable_timer.cancel(); + check_readable_timer.set_callback([last_peering_reset, this] { shard_services.start_operation( this, shard_services, @@ -151,6 +151,8 @@ void PG::queue_check_readable(epoch_t last_peering_reset, ceph::timespan delay) last_peering_reset, PeeringState::CheckReadable{}); }); + check_readable_timer.arm( + std::chrono::duration_cast(delay)); } void PG::recheck_readable() @@ -329,7 +331,8 @@ HeartbeatStampsRef PG::get_hb_stamps(int peer) void PG::schedule_renew_lease(epoch_t last_peering_reset, ceph::timespan delay) { // handle the peering event in the background - std::ignore = seastar::sleep(delay).then([last_peering_reset, this] { + renew_lease_timer.cancel(); + renew_lease_timer.set_callback([last_peering_reset, this] { shard_services.start_operation( this, shard_services, @@ -339,6 +342,8 @@ void PG::schedule_renew_lease(epoch_t last_peering_reset, ceph::timespan delay) last_peering_reset, RenewLease{}); }); + renew_lease_timer.arm( + std::chrono::duration_cast(delay)); } diff --git a/src/crimson/osd/pg.h b/src/crimson/osd/pg.h index 1ced9b22e77d9..781958f3074b3 100644 --- a/src/crimson/osd/pg.h +++ b/src/crimson/osd/pg.h @@ -62,6 +62,10 @@ class PG : public boost::intrusive_ref_counter< pg_shard_t pg_whoami; crimson::os::CollectionRef coll_ref; ghobject_t pgmeta_oid; + + seastar::timer check_readable_timer; + seastar::timer renew_lease_timer; + public: PG(spg_t pgid, pg_shard_t pg_shard, -- 2.39.5