]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson: prevent PG::schedule_event_after from creating daggling future 34429/head
authorXuehan Xu <xxhdx1985126@163.com>
Sun, 26 Apr 2020 03:41:28 +0000 (11:41 +0800)
committerXuehan Xu <xxhdx1985126@163.com>
Sun, 26 Apr 2020 07:46:35 +0000 (15:46 +0800)
Signed-off-by: Xuehan Xu <xxhdx1985126@163.com>
src/crimson/osd/osd_operations/peering_event.cc
src/crimson/osd/osd_operations/peering_event.h
src/crimson/osd/pg.h

index 9f1be69b604a61dadd8a97e80b9ce2c10a394a51..8c4cfbc89b6ad3a79da30352aa7938b6c5482250 100644 (file)
@@ -53,7 +53,16 @@ seastar::future<> PeeringEvent::start()
   logger().debug("{}: start", *this);
 
   IRef ref = this;
-  return get_pg().then([this](Ref<PG> 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> pg) {
     if (!pg) {
       logger().warn("{}: pg absent, did not create", *this);
       on_pg_absent();
index d9b57a3477ad81306352da709e9b7dfae8d30d0c..3a6c0678c46ac752cf8e2443a397be72bcb4b4d5 100644 (file)
@@ -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>(args)...)
   {}
-
+  template <typename... Args>
+  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>(args)...)
+  {}
 
   void print(std::ostream &) const final;
   void dump_detail(ceph::Formatter* f) const final;
index e5f20c701b93da111bd89cb214d47eed8be52bf9..c10139bff762d291509a330257d9222312985edd 100644 (file)
@@ -180,26 +180,20 @@ public:
   }
 
   template <typename T>
-  void start_peering_event_operation(T &&evt) {
+  void start_peering_event_operation(T &&evt, float delay = 0) {
     shard_services.start_operation<LocalPeeringEvent>(
       this,
       shard_services,
       pg_whoami,
       pgid,
+      delay,
       std::forward<T>(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<pg_shard_t> get_replica_recovery_order() const final {
     return peering_state.get_replica_recovery_order();