From: Sage Weil Date: Wed, 25 Apr 2012 22:10:34 +0000 (-0700) Subject: osdmap: use shared_ptr for addrs, addr vectors X-Git-Tag: v0.47~87^2~15 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=313c1566d3b649ef81fcdc722678d77dccfa888f;p=ceph.git osdmap: use shared_ptr for addrs, addr vectors We share a lot of identical addresses between map versions because they don't tend to change very often. Instead of having a separate copy for every map, use shared_ptr and share references. Also use a reference for the entire addr vector(s) in case no addrs differ at all. Create new encode/decode macros for vector< shared_ptr >. Signed-off-by: Sage Weil --- diff --git a/src/include/encoding.h b/src/include/encoding.h index 7e5bb3a476f4..9ab05a957aa4 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -469,6 +469,30 @@ inline void decode_nohead(int len, std::vector& v, bufferlist::iterator& p) decode(v[i], p); } +// vector (shared_ptr) +template +inline void encode(const std::vector >& v, bufferlist& bl) +{ + __u32 n = v.size(); + encode(n, bl); + for (typename std::vector >::const_iterator p = v.begin(); p != v.end(); ++p) + if (*p) + encode(**p, bl); + else + encode(T(), bl); +} +template +inline void decode(std::vector >& v, bufferlist::iterator& p) +{ + __u32 n; + decode(n, p); + v.resize(n); + for (__u32 i=0; i diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index a1055ae3c59f..db6c7acd569b 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -479,9 +479,9 @@ void OSDMap::set_max_osd(int m) osd_weight[o] = CEPH_OSD_OUT; } osd_info.resize(m); - osd_addr.resize(m); - osd_cluster_addr.resize(m); - osd_hb_addr.resize(m); + osd_addrs->client_addr.resize(m); + osd_addrs->cluster_addr.resize(m); + osd_addrs->hb_addr.resize(m); calc_num_osds(); } @@ -548,16 +548,16 @@ void OSDMap::adjust_osd_weights(const map& weights, Incremental& inc int OSDMap::identify_osd(const entity_addr_t& addr) const { - for (unsigned i=0; ifirst] |= CEPH_OSD_EXISTS | CEPH_OSD_UP; - osd_addr[i->first] = i->second; + osd_addrs->client_addr[i->first].reset(new entity_addr_t(i->second)); if (inc.new_hb_up.empty()) - osd_hb_addr[i->first] = i->second; //this is a backward-compatibility hack + osd_addrs->hb_addr[i->first].reset(new entity_addr_t(i->second)); //this is a backward-compatibility hack else - osd_hb_addr[i->first] = inc.new_hb_up[i->first]; + osd_addrs->hb_addr[i->first].reset(new entity_addr_t(inc.new_hb_up[i->first])); osd_info[i->first].up_from = epoch; } for (map::iterator i = inc.new_up_internal.begin(); i != inc.new_up_internal.end(); i++) - osd_cluster_addr[i->first] = i->second; + osd_addrs->cluster_addr[i->first].reset(new entity_addr_t(i->second)); // info for (map::iterator i = inc.new_up_thru.begin(); i != inc.new_up_thru.end(); @@ -887,7 +887,7 @@ void OSDMap::encode_client_old(bufferlist& bl) const ::encode(max_osd, bl); ::encode(osd_state, bl); ::encode(osd_weight, bl); - ::encode(osd_addr, bl); + ::encode(osd_addrs->client_addr, bl); // for ::encode(pg_temp, bl); n = pg_temp.size(); @@ -931,7 +931,7 @@ void OSDMap::encode(bufferlist& bl, uint64_t features) const ::encode(max_osd, bl); ::encode(osd_state, bl); ::encode(osd_weight, bl); - ::encode(osd_addr, bl); + ::encode(osd_addrs->client_addr, bl); ::encode(pg_temp, bl); @@ -943,10 +943,10 @@ void OSDMap::encode(bufferlist& bl, uint64_t features) const // extended __u16 ev = CEPH_OSDMAP_VERSION_EXT; ::encode(ev, bl); - ::encode(osd_hb_addr, bl); + ::encode(osd_addrs->hb_addr, bl); ::encode(osd_info, bl); ::encode(blacklist, bl); - ::encode(osd_cluster_addr, bl); + ::encode(osd_addrs->cluster_addr, bl); ::encode(cluster_snapshot_epoch, bl); ::encode(cluster_snapshot, bl); } @@ -1009,7 +1009,7 @@ void OSDMap::decode(bufferlist::iterator& p) ::decode(max_osd, p); ::decode(osd_state, p); ::decode(osd_weight, p); - ::decode(osd_addr, p); + ::decode(osd_addrs->client_addr, p); if (v <= 5) { pg_temp.clear(); ::decode(n, p); @@ -1032,16 +1032,16 @@ void OSDMap::decode(bufferlist::iterator& p) __u16 ev = 0; if (v >= 5) ::decode(ev, p); - ::decode(osd_hb_addr, p); + ::decode(osd_addrs->hb_addr, p); ::decode(osd_info, p); if (v < 5) ::decode(pool_name, p); ::decode(blacklist, p); if (ev >= 6) - ::decode(osd_cluster_addr, p); + ::decode(osd_addrs->cluster_addr, p); else - osd_cluster_addr.resize(osd_addr.size()); + osd_addrs->cluster_addr.resize(osd_addrs->client_addr.size()); if (ev >= 7) { ::decode(cluster_snapshot_epoch, p); diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index c629230104bb..9e622d28f9d3 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -170,9 +170,14 @@ private: int num_osd; // not saved int32_t max_osd; vector osd_state; - vector osd_addr; - vector osd_cluster_addr; - vector osd_hb_addr; + + struct addrs_s { + vector > client_addr; + vector > cluster_addr; + vector > hb_addr; + }; + std::tr1::shared_ptr osd_addrs; + vector<__u32> osd_weight; // 16.16 fixed point, 0x10000 = "in", 0 = "out" vector osd_info; map > pg_temp; // temp pg mapping (e.g. while we rebuild) @@ -198,6 +203,7 @@ private: pool_max(-1), flags(0), num_osd(0), max_osd(0), + osd_addrs(new addrs_s), cluster_snapshot_epoch(0) { memset(&fsid, 0, sizeof(fsid)); } @@ -307,34 +313,29 @@ private: } const entity_addr_t &get_addr(int osd) const { assert(exists(osd)); - return osd_addr[osd]; + return *osd_addrs->client_addr[osd]; } const entity_addr_t &get_cluster_addr(int osd) const { assert(exists(osd)); - if (osd_cluster_addr[osd] == entity_addr_t()) + if (*osd_addrs->cluster_addr[osd] == entity_addr_t()) return get_addr(osd); - return osd_cluster_addr[osd]; + return *osd_addrs->cluster_addr[osd]; } const entity_addr_t &get_hb_addr(int osd) const { assert(exists(osd)); - return osd_hb_addr[osd]; + return *osd_addrs->hb_addr[osd]; } entity_inst_t get_inst(int osd) const { - assert(exists(osd)); assert(is_up(osd)); - return entity_inst_t(entity_name_t::OSD(osd), osd_addr[osd]); + return entity_inst_t(entity_name_t::OSD(osd), get_addr(osd)); } entity_inst_t get_cluster_inst(int osd) const { - assert(exists(osd)); assert(is_up(osd)); - if (osd_cluster_addr[osd] == entity_addr_t()) - return get_inst(osd); - return entity_inst_t(entity_name_t::OSD(osd), osd_cluster_addr[osd]); + return entity_inst_t(entity_name_t::OSD(osd), get_cluster_addr(osd)); } entity_inst_t get_hb_inst(int osd) const { - assert(exists(osd)); assert(is_up(osd)); - return entity_inst_t(entity_name_t::OSD(osd), osd_hb_addr[osd]); + return entity_inst_t(entity_name_t::OSD(osd), get_hb_addr(osd)); } const epoch_t& get_up_from(int osd) const {