]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/PG: clean up set_force_{recovery,backfill} interface
authorSage Weil <sage@redhat.com>
Wed, 13 Sep 2017 22:09:35 +0000 (18:09 -0400)
committerDavid Zafman <dzafman@redhat.com>
Wed, 6 Mar 2019 10:20:40 +0000 (10:20 +0000)
- update state under pg lock
- clean up PG interface
- log only when we adjust the state

Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit 2482b4cc91579b4ef5748097f1adacaad91510b1)

Conflicts:
src/osd/PG.h (trivial)

src/osd/OSD.cc
src/osd/PG.cc
src/osd/PG.h

index 0f968d33364547d4e7729e8409849ec27a36a2d2..e8b1f70b128e07510a786656fac0aba9b2c551eb 100644 (file)
@@ -9596,45 +9596,16 @@ bool OSDService::_recover_now(uint64_t *available_pushes)
 
 void OSDService::adjust_pg_priorities(const vector<PGRef>& pgs, int newflags)
 {
-  if (!pgs.size() || !(newflags & (OFR_BACKFILL | OFR_RECOVERY)))
+  if (!pgs.size() || !(newflags & (OFR_BACKFILL | OFR_RECOVERY))) {
     return;
-  int newstate = 0;
-
-  if (newflags & OFR_BACKFILL) {
-    newstate = PG_STATE_FORCED_BACKFILL;
-  } else if (newflags & OFR_RECOVERY) {
-    newstate = PG_STATE_FORCED_RECOVERY;
   }
-
-  // debug output here may get large, don't generate it if debug level is below
-  // 10 and use abbreviated pg ids otherwise
-  if ((cct)->_conf->subsys.should_gather(ceph_subsys_osd, 10)) {
-    stringstream ss;
-
-    for (auto& i : pgs) {
-      ss << i->get_pgid() << " ";
-    }
-
-    dout(10) << __func__ << " working on " << ss.str() << dendl;
-  }
-
-  if (newflags & OFR_CANCEL) {
-    for (auto& i : pgs) {
-      i->lock();
-      i->_change_recovery_force_mode(newstate, true);
-      i->unlock();
+  if (newflags & OFR_BACKFILL) {
+    for (auto& pg : pgs) {
+      pg->set_force_backfill(!(newflags & OFR_CANCEL));
     }
-  } else {
-    for (auto& i : pgs) {
-      // make sure the PG is in correct state before forcing backfill or recovery, or
-      // else we'll make PG keeping FORCE_* flag forever, requiring osds restart
-      // or forcing somehow recovery/backfill.
-      i->lock();
-      int pgstate = i->get_state();
-      if ( ((newstate == PG_STATE_FORCED_RECOVERY) && (pgstate & (PG_STATE_DEGRADED | PG_STATE_RECOVERY_WAIT | PG_STATE_RECOVERING))) ||
-           ((newstate == PG_STATE_FORCED_BACKFILL) && (pgstate & (PG_STATE_DEGRADED | PG_STATE_BACKFILL_WAIT | PG_STATE_BACKFILLING))) )
-        i->_change_recovery_force_mode(newstate, false);
-      i->unlock();
+  } else if (newflags & OFR_RECOVERY) {
+    for (auto& pg : pgs) {
+      pg->set_force_recovery(!(newflags & OFR_CANCEL));
     }
   }
 }
index f48d3ec03694899e2ad9144104bf83d18db47d83..8cd905dfd2af3eb5808ecec41cfcb67b79997e53 100644 (file)
@@ -2132,17 +2132,48 @@ void PG::mark_clean()
   kick_snap_trim();
 }
 
-void PG::_change_recovery_force_mode(int new_mode, bool clear)
+void PG::set_force_recovery(bool b)
 {
+  lock();
   if (!deleting) {
-    // we can't and shouldn't do anything if the PG is being deleted locally
-    if (clear) {
-      state_clear(new_mode);
-    } else {
-      state_set(new_mode);
+    if (b) {
+      if (!(state & PG_STATE_FORCED_RECOVERY) &&
+         (state & (PG_STATE_DEGRADED |
+                   PG_STATE_RECOVERY_WAIT |
+                   PG_STATE_RECOVERING))) {
+       dout(20) << __func__ << " set" << dendl;
+       state_set(PG_STATE_FORCED_RECOVERY);
+       publish_stats_to_osd();
+      }
+    } else if (state & PG_STATE_FORCED_RECOVERY) {
+      dout(20) << __func__ << " clear" << dendl;
+      state_clear(PG_STATE_FORCED_RECOVERY);
+      publish_stats_to_osd();
+    }
+  }
+  unlock();
+}
+
+void PG::set_force_backfill(bool b)
+{
+  lock();
+  if (!deleting) {
+    if (b) {
+      if (!(state & PG_STATE_FORCED_RECOVERY) &&
+         (state & (PG_STATE_DEGRADED |
+                   PG_STATE_BACKFILL_WAIT |
+                   PG_STATE_BACKFILLING))) {
+       dout(10) << __func__ << " set" << dendl;
+       state_set(PG_STATE_FORCED_RECOVERY);
+       publish_stats_to_osd();
+      }
+    } else if (state & PG_STATE_FORCED_RECOVERY) {
+      dout(10) << __func__ << " clear" << dendl;
+      state_clear(PG_STATE_FORCED_RECOVERY);
+      publish_stats_to_osd();
     }
-    publish_stats_to_osd();
   }
+  unlock();
 }
 
 inline int PG::clamp_recovery_priority(int priority)
index d782d897fedffa8c4d73a1483e8969e3d6237886..0afd4f49046dcefe294151a8f36d774d09379ca8 100644 (file)
@@ -252,6 +252,10 @@ struct PGPool {
  */
 
 class PG : public DoutPrefixProvider {
+public:
+  void set_force_recovery(bool b);
+  void set_force_backfill(bool b);
+
 protected:
   OSDService *osd;
   CephContext *cct;
@@ -1093,7 +1097,6 @@ public:
   unsigned get_backfill_priority();
 
   void mark_clean();  ///< mark an active pg clean
-  void _change_recovery_force_mode(int new_mode, bool clear);
 
   /// return [start,end) bounds for required past_intervals
   static pair<epoch_t, epoch_t> get_required_past_interval_bounds(