]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/: change type of osd::osdmap to a shared_ptr
authorSamuel Just <samuel.just@dreamhost.com>
Tue, 8 Nov 2011 01:51:21 +0000 (17:51 -0800)
committerSamuel Just <samuel.just@dreamhost.com>
Wed, 9 Nov 2011 22:15:40 +0000 (14:15 -0800)
Signed-off-by: Samuel Just <samuel.just@dreamhost.com>
src/osd/OSD.cc
src/osd/OSD.h
src/osd/OSDMap.h
src/osd/PG.cc
src/osd/PG.h
src/osd/ReplicatedPG.cc
src/osd/ReplicatedPG.h

index f899b40a3fb3fe44eb63019916b58683c5fab0b6..7232d8f6f20c23f5af4d077388bcb735ab282952 100644 (file)
 #undef dout_prefix
 #define dout_prefix _prefix(*_dout, whoami, osdmap)
 
-static ostream& _prefix(std::ostream* _dout, int whoami, OSDMap *osdmap) {
+static ostream& _prefix(std::ostream* _dout, int whoami, OSDMapRef osdmap) {
   return *_dout << "osd." << whoami << " " << (osdmap ? osdmap->get_epoch():0) << " ";
 }
 
@@ -543,7 +543,6 @@ OSD::OSD(int id, Messenger *internal_messenger, Messenger *external_messenger,
   stat_lock("OSD::stat_lock"),
   finished_lock("OSD::finished_lock"),
   op_wq(this, g_conf->osd_op_thread_timeout, &op_tp),
-  osdmap(NULL),
   map_lock("OSD::map_lock"),
   peer_map_epoch_lock("OSD::peer_map_epoch_lock"),
   map_cache_lock("OSD::map_cache_lock"),
@@ -574,8 +573,6 @@ OSD::OSD(int id, Messenger *internal_messenger, Messenger *external_messenger,
 
   map_in_progress_cond = new Cond();
   
-  osdmap = 0;
-
   pending_ops = 0;
   waiting_for_no_ops = false;
 }
@@ -922,8 +919,6 @@ int OSD::shutdown()
   delete watch;
 
   clear_map_cache();
-  osdmap = 0;
-
   return r;
 }
 
@@ -1313,7 +1308,7 @@ void OSD::calc_priors_during(pg_t pgid, epoch_t start, epoch_t end, set<int>& ps
   dout(15) << "calc_priors_during " << pgid << " [" << start << "," << end << ")" << dendl;
   
   for (epoch_t e = start; e < end; e++) {
-    OSDMap *oldmap = get_map(e);
+    OSDMapRef oldmap = get_map(e);
     vector<int> acting;
     oldmap->pg_to_acting_osds(pgid, acting);
     dout(20) << "  " << pgid << " in epoch " << e << " was " << acting << dendl;
@@ -1353,7 +1348,7 @@ void OSD::project_pg_history(pg_t pgid, PG::Info::History& h, epoch_t from,
        e > from;
        e--) {
     // verify during intermediate epoch (e-1)
-    OSDMap *oldmap = get_map(e-1);
+    OSDMapRef oldmap = get_map(e-1);
 
     vector<int> up, acting;
     oldmap->pg_to_up_acting_osds(pgid, up, acting);
@@ -3241,7 +3236,7 @@ void OSD::handle_osd_map(MOSDMap *m)
       OSDMap *o = new OSDMap;
       if (e > 1) {
        bufferlist obl;
-       OSDMap *prev = get_map(e - 1);
+       OSDMapRef prev = get_map(e - 1);
        prev->encode(obl);
        o->decode(obl);
       }
@@ -3271,7 +3266,7 @@ void OSD::handle_osd_map(MOSDMap *m)
   // check for cluster snapshot
   string cluster_snap;
   for (epoch_t cur = start; cur <= last && cluster_snap.length() == 0; cur++) {
-    OSDMap *newmap = get_map(cur);
+    OSDMapRef newmap = get_map(cur);
     cluster_snap = newmap->get_cluster_snapshot();
   }
 
@@ -3312,7 +3307,7 @@ void OSD::handle_osd_map(MOSDMap *m)
   for (epoch_t cur = start; cur <= superblock.newest_map; cur++) {
     dout(10) << " advance to epoch " << cur << " (<= newest " << superblock.newest_map << ")" << dendl;
 
-    OSDMap *newmap = get_map(cur);
+    OSDMapRef newmap = get_map(cur);
     assert(newmap);  // we just cached it above!
 
     // kill connections to newly down osds
@@ -3559,7 +3554,7 @@ void OSD::advance_map(ObjectStore::Transaction& t)
   }
 
   // if we skipped a discontinuity and are the first epoch, we won't have a previous map.
-  OSDMap *lastmap = NULL;
+  OSDMapRef lastmap;
   if (osdmap->get_epoch() > superblock.oldest_map)
     lastmap = get_map(osdmap->get_epoch() - 1);
 
@@ -3726,16 +3721,17 @@ bool OSD::get_inc_map_bl(epoch_t e, bufferlist& bl)
   return store->read(coll_t::META_COLL, get_inc_osdmap_pobject_name(e), 0, 0, bl) >= 0;
 }
 
-void OSD::add_map(OSDMap *o)
+OSDMapRef OSD::add_map(OSDMap *o)
 {
   Mutex::Locker l(map_cache_lock);
   epoch_t e = o->get_epoch();
   if (map_cache.count(e) == 0) {
     dout(10) << "add_map " << e << " " << o << dendl;
-    map_cache[e] = o;
+    map_cache.insert(make_pair(e, OSDMapRef(o)));
   } else {
     dout(10) << "add_map " << e << " already have it" << dendl;
   }
+  return map_cache[e];
 }
 
 void OSD::add_map_bl(epoch_t e, bufferlist& bl)
@@ -3752,11 +3748,11 @@ void OSD::add_map_inc_bl(epoch_t e, bufferlist& bl)
   map_inc_bl[e] = bl;
 }
 
-OSDMap *OSD::get_map(epoch_t epoch)
+OSDMapRef OSD::get_map(epoch_t epoch)
 {
   {
     Mutex::Locker l(map_cache_lock);
-    map<epoch_t,OSDMap*>::iterator p = map_cache.find(epoch);
+    map<epoch_t,OSDMapRef>::iterator p = map_cache.find(epoch);
     if (p != map_cache.end()) {
       dout(30) << "get_map " << epoch << " - cached " << p->second << dendl;
       return p->second;
@@ -3772,8 +3768,7 @@ OSDMap *OSD::get_map(epoch_t epoch)
   } else {
     dout(20) << "get_map " << epoch << " - return initial " << map << dendl;
   }
-  add_map(map);
-  return map;
+  return add_map(map);
 }
 
 void OSD::trim_map_bl_cache(epoch_t oldest)
@@ -3794,9 +3789,8 @@ void OSD::trim_map_cache(epoch_t oldest)
         (map_cache.begin()->first < oldest ||
          (int)map_cache.size() > g_conf->osd_map_cache_max)) {
     epoch_t e = map_cache.begin()->first;
-    OSDMap *o = map_cache.begin()->second;
+    OSDMapRef o = map_cache.begin()->second;
     dout(10) << "trim_map_cache " << e << " " << o << dendl;
-    delete o;
     map_cache.erase(map_cache.begin());
   }
 }
@@ -3804,8 +3798,6 @@ void OSD::trim_map_cache(epoch_t oldest)
 void OSD::clear_map_cache()
 {
   while (!map_cache.empty()) {
-    OSDMap *o = map_cache.begin()->second;
-    delete o;
     map_cache.erase(map_cache.begin());
   }
 }
index 86efcc896182e4e438cb3a962eda109a11ea9b46..aaf760996012f9f4fda0e02d8f7c2eb1f4c6191d 100644 (file)
@@ -38,6 +38,7 @@
 
 #include <map>
 #include <memory>
+#include <tr1/memory>
 using namespace std;
 
 #include <ext/hash_map>
@@ -376,7 +377,7 @@ private:
  protected:
 
   // -- osd map --
-  OSDMap         *osdmap;
+  OSDMapRef       osdmap;
   utime_t         had_map_since;
   RWLock          map_lock;
   list<Message*>  waiting_for_osdmap;
@@ -401,13 +402,13 @@ private:
   void activate_map(ObjectStore::Transaction& t, list<Context*>& tfin);
 
   // osd map cache (past osd maps)
-  map<epoch_t,OSDMap*> map_cache;
+  map<epoch_t,OSDMapRef > map_cache;
   map<epoch_t,bufferlist> map_inc_bl;
   map<epoch_t,bufferlist> map_bl;
   Mutex map_cache_lock;
 
-  OSDMap* get_map(epoch_t e);
-  void add_map(OSDMap *o);
+  OSDMapRef get_map(epoch_t e);
+  OSDMapRef add_map(OSDMap *o);
   void add_map_bl(epoch_t e, bufferlist& bl);
   void add_map_inc_bl(epoch_t e, bufferlist& bl);
   void trim_map_cache(epoch_t oldest);
index a79d646c19e91beddbf5463d30b5eb8a86211651..6c13faf438b177fbb0a259694c1f795252500e30 100644 (file)
@@ -36,6 +36,7 @@
 #include <list>
 #include <set>
 #include <map>
+#include <tr1/memory>
 using namespace std;
 
 #include <ext/hash_set>
@@ -661,6 +662,8 @@ public:
 
 };
 
+typedef std::tr1::shared_ptr<OSDMap> OSDMapRef;
+
 inline ostream& operator<<(ostream& out, const OSDMap& m) {
   m.print_summary(out);
   return out;
index 0eee5b19109e2f52b89acf614be0c3665792cd84..0f1e603a669a082a4a560aea920c75ab68b51b15 100644 (file)
@@ -957,11 +957,11 @@ void PG::generate_past_intervals()
 
   dout(10) << __func__ << " over epochs " << stop << "-" << last_epoch << dendl;
 
-  OSDMap *nextmap = osd->get_map(last_epoch);
+  OSDMapRef nextmap = osd->get_map(last_epoch);
   for (;
        last_epoch >= stop;
        last_epoch = first_epoch - 1) {
-    OSDMap *lastmap = nextmap;
+    OSDMapRef lastmap = nextmap;
     vector<int> tup, tacting;
     lastmap->pg_to_up_acting_osds(get_pgid(), tup, tacting);
     
@@ -1034,7 +1034,7 @@ void PG::trim_past_intervals()
 }
 
 
-bool PG::adjust_need_up_thru(const OSDMap *osdmap)
+bool PG::adjust_need_up_thru(const OSDMapRef osdmap)
 {
   epoch_t up_thru = osd->osdmap->get_up_thru(osd->whoami);
   if (need_up_thru &&
@@ -1049,7 +1049,7 @@ bool PG::adjust_need_up_thru(const OSDMap *osdmap)
 /*
  * Returns true unless there is a non-lost OSD in might_have_unfound.
  */
-bool PG::all_unfound_are_queried_or_lost(const OSDMap* osdmap) const
+bool PG::all_unfound_are_queried_or_lost(const OSDMapRef osdmap) const
 {
   assert(is_primary());
 
@@ -3372,7 +3372,7 @@ void PG::fulfill_log(int from, const Query &query, epoch_t query_epoch)
 
 // true if all OSDs in prior intervals may have crashed, and we need to replay
 // false positives are okay, false negatives are not.
-bool PG::may_need_replay(const OSDMap *osdmap) const
+bool PG::may_need_replay(const OSDMapRef osdmap) const
 {
   bool crashed = false;
 
@@ -3483,11 +3483,11 @@ void PG::set_last_peering_reset() {
 }
 
 /* Called before initializing peering during advance_map */
-void PG::start_peering_interval(const OSDMap *lastmap,
+void PG::start_peering_interval(const OSDMapRef lastmap,
                                const vector<int>& newup,
                                const vector<int>& newacting)
 {
-  const OSDMap *osdmap = osd->osdmap;
+  const OSDMapRef osdmap = osd->osdmap;
 
   // -- there was a change! --
   kick();
@@ -4017,7 +4017,7 @@ boost::statechart::result
 PG::RecoveryState::Primary::react(const AdvMap& advmap) 
 {
   PG *pg = context< RecoveryMachine >().pg;
-  OSDMap *osdmap = advmap.osdmap;
+  OSDMapRef osdmap = advmap.osdmap;
 
   // Remove any downed osds from peer_info
   map<int,PG::Info>::iterator p = pg->peer_info.begin();
@@ -4735,7 +4735,7 @@ void PG::RecoveryState::handle_query(int from, const PG::Query& q,
   end_handle();
 }
 
-void PG::RecoveryState::handle_advance_map(OSDMap *osdmap, OSDMap *lastmap,
+void PG::RecoveryState::handle_advance_map(OSDMapRef osdmap, OSDMapRef lastmap,
                                           vector<int>& newup, vector<int>& newacting,
                                           RecoveryCtx *rctx)
 {
@@ -4922,7 +4922,7 @@ PG::PriorSet::PriorSet(const OSDMap &osdmap,
 }
 
 // true if the given map affects the prior set
-bool PG::PriorSet::affected_by_map(const OSDMap *osdmap, const PG *debug_pg) const
+bool PG::PriorSet::affected_by_map(const OSDMapRef osdmap, const PG *debug_pg) const
 {
   for (set<int>::iterator p = probe.begin();
        p != probe.end();
index a2ef11d72f3fb226a21da28c3132a25691be99e5..95e8e0e61d416cf8d92efce5727ba4a960930695 100644 (file)
@@ -886,13 +886,13 @@ public:
             const Info &info,
             const PG *debug_pg=NULL);
 
-    bool affected_by_map(const OSDMap *osdmap, const PG *debug_pg=0) const;
+    bool affected_by_map(const OSDMapRef osdmap, const PG *debug_pg=0) const;
   };
 
   friend std::ostream& operator<<(std::ostream& oss,
                                  const struct PriorSet &prior);
 
-  bool may_need_replay(const OSDMap *osdmap) const;
+  bool may_need_replay(const OSDMapRef osdmap) const;
 
 
 public:    
@@ -972,10 +972,10 @@ public:
     };
 
     struct AdvMap : boost::statechart::event< AdvMap > {
-      OSDMap *osdmap;
-      OSDMap *lastmap;
+      OSDMapRef osdmap;
+      OSDMapRef lastmap;
       vector<int> newup, newacting;
-      AdvMap(OSDMap *osdmap, OSDMap *lastmap, vector<int>& newup, vector<int>& newacting):
+      AdvMap(OSDMapRef osdmap, OSDMapRef lastmap, vector<int>& newup, vector<int>& newacting):
        osdmap(osdmap), lastmap(lastmap), newup(newup), newacting(newacting) {}
     };
 
@@ -1325,7 +1325,7 @@ public:
     void handle_query(int from, const PG::Query& q,
                      epoch_t query_epoch,
                      RecoveryCtx *ctx);
-    void handle_advance_map(OSDMap *osdmap, OSDMap *lastmap, 
+    void handle_advance_map(OSDMapRef osdmap, OSDMapRef lastmap,
                            vector<int>& newup, vector<int>& newacting, 
                            RecoveryCtx *ctx);
     void handle_activate_map(RecoveryCtx *ctx);
@@ -1401,9 +1401,9 @@ public:
   void build_prior(std::auto_ptr<PriorSet> &prior_set);
   void clear_prior();
 
-  bool adjust_need_up_thru(const OSDMap *osdmap);
+  bool adjust_need_up_thru(const OSDMapRef osdmap);
 
-  bool all_unfound_are_queried_or_lost(const OSDMap* osdmap) const;
+  bool all_unfound_are_queried_or_lost(const OSDMapRef osdmap) const;
   virtual void mark_all_unfound_lost(int how) = 0;
 
   bool calc_min_last_complete_ondisk() {
@@ -1488,7 +1488,7 @@ public:
   void clear_recovery_state();
   virtual void _clear_recovery_state() = 0;
   void defer_recovery();
-  virtual void check_recovery_op_pulls(const OSDMap *newmap) = 0;
+  virtual void check_recovery_op_pulls(const OSDMapRef newmap) = 0;
   void start_recovery_op(const hobject_t& soid);
   void finish_recovery_op(const hobject_t& soid, bool dequeue=false);
 
@@ -1634,7 +1634,7 @@ public:
   /// share new pg log entries after a pg is active
   void share_pg_log();
 
-  void start_peering_interval(const OSDMap *lastmap,
+  void start_peering_interval(const OSDMapRef lastmap,
                              const vector<int>& newup,
                              const vector<int>& newacting);
   void set_last_peering_reset();
@@ -1662,7 +1662,7 @@ public:
                    RecoveryCtx *rctx) {
     recovery_state.handle_query(from, q, query_epoch, rctx);
   }
-  void handle_advance_map(OSDMap *osdmap, OSDMap *lastmap, 
+  void handle_advance_map(OSDMapRef osdmap, OSDMapRef lastmap,
                          vector<int>& newup, vector<int>& newacting,
                          RecoveryCtx *rctx) {
     recovery_state.handle_advance_map(osdmap, lastmap, newup, newacting, rctx);
index 3ed552b5465df2c7df43aaa919452937034bdfc8..a2d843d0e1e3d42e48507108a1291c0b303a0e6e 100644 (file)
@@ -43,7 +43,7 @@
 #define DOUT_PREFIX_ARGS this, osd->whoami, osd->osdmap
 #undef dout_prefix
 #define dout_prefix _prefix(_dout, this, osd->whoami, osd->osdmap)
-static ostream& _prefix(std::ostream *_dout, PG *pg, int whoami, OSDMap *osdmap) {
+static ostream& _prefix(std::ostream *_dout, PG *pg, int whoami, OSDMapRef osdmap) {
   return *_dout << "osd." << whoami
                << " " << (osdmap ? osdmap->get_epoch():0) << " " << *pg << " ";
 }
@@ -4787,7 +4787,7 @@ void ReplicatedPG::_clear_recovery_state()
   pull_from_peer.clear();
 }
 
-void ReplicatedPG::check_recovery_op_pulls(const OSDMap *osdmap)
+void ReplicatedPG::check_recovery_op_pulls(const OSDMapRef osdmap)
 {
   for (map<int, set<hobject_t> >::iterator j = pull_from_peer.begin();
        j != pull_from_peer.end();
index 5cb5f98798f72080709f8a8cd49052b068e8da61..c51279247ccd1b3548506e3c0edd98f00d1b889a 100644 (file)
@@ -580,7 +580,7 @@ protected:
   void send_push_op_blank(const hobject_t& soid, int peer);
 
   // Cancels/resets pulls from peer
-  void check_recovery_op_pulls(const OSDMap *map);
+  void check_recovery_op_pulls(const OSDMapRef map);
   int pull(const hobject_t& oid, eversion_t v);
   void send_pull_op(const hobject_t& soid, eversion_t v, bool first, const interval_set<uint64_t>& data_subset, int fromosd);