]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/OSDMap: cache get_up_osd_features
authorSage Weil <sage@redhat.com>
Mon, 16 Feb 2015 17:30:39 +0000 (09:30 -0800)
committerSage Weil <sage@redhat.com>
Mon, 23 Feb 2015 18:10:54 +0000 (10:10 -0800)
This method is O(n) and called from in a few places for each IO operation.
Cache the value since it does not change over the lifetime of a single
epoch.  Invalidate on apply_incremental() and decode.

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

index e93040c33c0b253aab1549ea620ed9b240ddcabd..4680488bdbd1083cd9e53ab21c8c458bf628942f 100644 (file)
@@ -1090,22 +1090,26 @@ uint64_t OSDMap::get_features(int entity_type, uint64_t *pmask) const
   return features;
 }
 
-uint64_t OSDMap::get_up_osd_features() const
+void OSDMap::_calc_up_osd_features()
 {
   bool first = true;
-  uint64_t features = 0;
+  cached_up_osd_features = 0;
   for (int osd = 0; osd < max_osd; ++osd) {
     if (!is_up(osd))
       continue;
     const osd_xinfo_t &xi = get_xinfo(osd);
     if (first) {
-      features = xi.features;
+      cached_up_osd_features = xi.features;
       first = false;
     } else {
-      features &= xi.features;
+      cached_up_osd_features &= xi.features;
     }
   }
-  return features;
+}
+
+uint64_t OSDMap::get_up_osd_features() const
+{
+  return cached_up_osd_features;
 }
 
 void OSDMap::dedup(const OSDMap *o, OSDMap *n)
@@ -1258,6 +1262,7 @@ int OSDMap::apply_incremental(const Incremental &inc)
     return -EINVAL;
   
   assert(inc.epoch == epoch+1);
+
   epoch++;
   modified = inc.modified;
 
@@ -1439,6 +1444,7 @@ int OSDMap::apply_incremental(const Incremental &inc)
   }
 
   calc_num_osds();
+  _calc_up_osd_features();
   return 0;
 }
 
@@ -2196,6 +2202,7 @@ void OSDMap::post_decode()
   }
 
   calc_num_osds();
+  _calc_up_osd_features();
 }
 
 void OSDMap::dump_erasure_code_profiles(const map<string,map<string,string> > &profiles,
index a38533db8b0ec6e9df200704fcac591d8f706f0f..ec048493e2419bb3c1e5c0324cc25aa6b6a78245 100644 (file)
@@ -245,9 +245,13 @@ private:
   string cluster_snapshot;
   bool new_blacklist_entries;
 
+  mutable uint64_t cached_up_osd_features;
+
   mutable bool crc_defined;
   mutable uint32_t crc;
 
+  void _calc_up_osd_features();
+
  public:
   bool have_crc() const { return crc_defined; }
   uint32_t get_crc() const { return crc; }
@@ -269,6 +273,7 @@ private:
             osd_uuid(new vector<uuid_d>),
             cluster_snapshot_epoch(0),
             new_blacklist_entries(false),
+            cached_up_osd_features(0),
             crc_defined(false), crc(0),
             crush(new CrushWrapper) {
     memset(&fsid, 0, sizeof(fsid));