]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/OSDMap: add [near]full_ratio to OSDMap[::Incremental]
authorSage Weil <sage@redhat.com>
Thu, 23 Feb 2017 18:59:19 +0000 (13:59 -0500)
committerSage Weil <sage@redhat.com>
Mon, 6 Mar 2017 18:59:59 +0000 (13:59 -0500)
This used to live in PGMap; we're moving it here for luminous
(which makes more sense anyway!).

Signed-off-by: Sage Weil <sage@redhat.com>
src/osd/OSDMap.cc
src/osd/OSDMap.h

index 8c1bf7dccfc65cc36d469360e176785a6756d131..03bc64ec260b2d70589b814849ac26a93dec28cd 100644 (file)
@@ -440,7 +440,11 @@ void OSDMap::Incremental::encode(bufferlist& bl, uint64_t features) const
   }
 
   {
-    ENCODE_START(2, 1, bl); // extended, osd-only data
+    uint8_t target_v = 3;
+    if (!HAVE_FEATURE(features, SERVER_LUMINOUS)) {
+      target_v = 2;
+    }
+    ENCODE_START(target_v, 1, bl); // extended, osd-only data
     ::encode(new_hb_back_up, bl, features);
     ::encode(new_up_thru, bl);
     ::encode(new_last_clean_interval, bl);
@@ -453,6 +457,10 @@ void OSDMap::Incremental::encode(bufferlist& bl, uint64_t features) const
     ::encode(new_xinfo, bl);
     ::encode(new_hb_front_up, bl, features);
     ::encode(features, bl);         // NOTE: features arg, not the member
+    if (target_v >= 3) {
+      ::encode(new_nearfull_ratio, bl);
+      ::encode(new_full_ratio, bl);
+    }
     ENCODE_FINISH(bl); // osd-only data
   }
 
@@ -630,7 +638,7 @@ void OSDMap::Incremental::decode(bufferlist::iterator& bl)
   }
 
   {
-    DECODE_START(2, bl); // extended, osd-only data
+    DECODE_START(3, bl); // extended, osd-only data
     ::decode(new_hb_back_up, bl);
     ::decode(new_up_thru, bl);
     ::decode(new_last_clean_interval, bl);
@@ -646,6 +654,13 @@ void OSDMap::Incremental::decode(bufferlist::iterator& bl)
       ::decode(encode_features, bl);
     else
       encode_features = CEPH_FEATURE_PGID64 | CEPH_FEATURE_OSDMAP_ENC;
+    if (struct_v >= 3) {
+      ::decode(new_nearfull_ratio, bl);
+      ::decode(new_full_ratio, bl);
+    } else {
+      new_nearfull_ratio = -1;
+      new_full_ratio = -1;
+    }
     DECODE_FINISH(bl); // osd-only data
   }
 
@@ -687,6 +702,8 @@ void OSDMap::Incremental::dump(Formatter *f) const
   f->dump_stream("modified") << modified;
   f->dump_int("new_pool_max", new_pool_max);
   f->dump_int("new_flags", new_flags);
+  f->dump_float("new_full_ratio", new_full_ratio);
+  f->dump_float("new_nearfull_ratio", new_nearfull_ratio);
 
   if (fullmap.length()) {
     f->open_object_section("full_map");
@@ -950,6 +967,20 @@ int OSDMap::calc_num_osds()
   return num_osd;
 }
 
+void OSDMap::count_full_nearfull_osds(int *full, int *nearfull) const
+{
+  *full = 0;
+  *nearfull = 0;
+  for (int i = 0; i < max_osd; ++i) {
+    if (exists(i) && is_up(i) && is_in(i)) {
+      if (osd_state[i] & CEPH_OSD_FULL)
+       ++(*full);
+      else if (osd_state[i] & CEPH_OSD_NEARFULL)
+       ++(*nearfull);
+    }
+  }
+}
+
 void OSDMap::get_all_osds(set<int32_t>& ls) const
 {
   for (int i=0; i<max_osd; i++)
@@ -1469,6 +1500,13 @@ int OSDMap::apply_incremental(const Incremental &inc)
     cluster_snapshot_epoch = 0;
   }
 
+  if (inc.new_nearfull_ratio >= 0) {
+    nearfull_ratio = inc.new_nearfull_ratio;
+  }
+  if (inc.new_full_ratio >= 0) {
+    full_ratio = inc.new_full_ratio;
+  }
+
   // do new crush map last (after up/down stuff)
   if (inc.crush.length()) {
     bufferlist bl(inc.crush);
@@ -1972,7 +2010,11 @@ void OSDMap::encode(bufferlist& bl, uint64_t features) const
   }
 
   {
-    ENCODE_START(1, 1, bl); // extended, osd-only data
+    uint8_t target_v = 2;
+    if (!HAVE_FEATURE(features, SERVER_LUMINOUS)) {
+      target_v = 1;
+    }
+    ENCODE_START(target_v, 1, bl); // extended, osd-only data
     ::encode(osd_addrs->hb_back_addr, bl, features);
     ::encode(osd_info, bl);
     {
@@ -1990,6 +2032,10 @@ void OSDMap::encode(bufferlist& bl, uint64_t features) const
     ::encode(*osd_uuid, bl);
     ::encode(osd_xinfo, bl);
     ::encode(osd_addrs->hb_front_addr, bl, features);
+    if (target_v >= 2) {
+      ::encode(nearfull_ratio, bl);
+      ::encode(full_ratio, bl);
+    }
     ENCODE_FINISH(bl); // osd-only data
   }
 
@@ -2199,7 +2245,7 @@ void OSDMap::decode(bufferlist::iterator& bl)
   }
 
   {
-    DECODE_START(1, bl); // extended, osd-only data
+    DECODE_START(2, bl); // extended, osd-only data
     ::decode(osd_addrs->hb_back_addr, bl);
     ::decode(osd_info, bl);
     ::decode(blacklist, bl);
@@ -2209,6 +2255,13 @@ void OSDMap::decode(bufferlist::iterator& bl)
     ::decode(*osd_uuid, bl);
     ::decode(osd_xinfo, bl);
     ::decode(osd_addrs->hb_front_addr, bl);
+    if (struct_v >= 2) {
+      ::decode(nearfull_ratio, bl);
+      ::decode(full_ratio, bl);
+    } else {
+      nearfull_ratio = 0;
+      full_ratio = 0;
+    }
     DECODE_FINISH(bl); // osd-only data
   }
 
@@ -2281,6 +2334,8 @@ void OSDMap::dump(Formatter *f) const
   f->dump_stream("created") << get_created();
   f->dump_stream("modified") << get_modified();
   f->dump_string("flags", get_flag_string());
+  f->dump_float("full_ratio", full_ratio);
+  f->dump_float("nearfull_ratio", nearfull_ratio);
   f->dump_string("cluster_snapshot", get_cluster_snapshot());
   f->dump_int("pool_max", get_pool_max());
   f->dump_int("max_osd", get_max_osd());
@@ -2473,6 +2528,8 @@ void OSDMap::print(ostream& out) const
       << "modified " << get_modified() << "\n";
 
   out << "flags " << get_flag_string() << "\n";
+  out << "full_ratio " << full_ratio << "\n";
+  out << "nearfull_ratio " << nearfull_ratio << "\n";
   if (get_cluster_snapshot().length())
     out << "cluster_snapshot " << get_cluster_snapshot() << "\n";
   out << "\n";
index 64d0580f7b371666dd5cb4c13421a45e18b6269a..88eeec334618ff4bacd1033056914f0eb0aa3dbf 100644 (file)
@@ -150,6 +150,9 @@ public:
 
     string cluster_snapshot;
 
+    float new_nearfull_ratio = -1;
+    float new_full_ratio = -1;
+
     mutable bool have_crc;      ///< crc values are defined
     uint32_t full_crc;  ///< crc of the resulting OSDMap
     mutable uint32_t inc_crc;   ///< crc of this incremental
@@ -243,6 +246,8 @@ private:
   string cluster_snapshot;
   bool new_blacklist_entries;
 
+  float full_ratio = 0, nearfull_ratio = 0;
+
   mutable uint64_t cached_up_osd_features;
 
   mutable bool crc_defined;
@@ -320,6 +325,14 @@ public:
     return string();
   }
 
+  float get_full_ratio() const {
+    return full_ratio;
+  }
+  float get_nearfull_ratio() const {
+    return nearfull_ratio;
+  }
+  void count_full_nearfull_osds(int *full, int *nearfull) const;
+
   /***** cluster state *****/
   /* osds */
   int get_max_osd() const { return max_osd; }