]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: cleanup replica_map access
authorPatrick Donnelly <pdonnell@redhat.com>
Thu, 27 Jul 2017 19:06:23 +0000 (12:06 -0700)
committerPatrick Donnelly <pdonnell@redhat.com>
Tue, 12 Sep 2017 22:46:22 +0000 (15:46 -0700)
The gymnastics protecting the map failed as the code evolved. Just expose it
normally with a getter.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/include/compact_map.h
src/mds/CDentry.h
src/mds/CDir.cc
src/mds/CInode.cc
src/mds/Locker.cc
src/mds/MDCache.cc
src/mds/MDSCacheObject.cc
src/mds/MDSCacheObject.h
src/mds/Migrator.cc
src/mds/SimpleLock.h

index 12ba8b3504a30e21b8e7f71b9dc50a2105352373..975baa064d3dd312464bbcdb8394445607f49901 100644 (file)
@@ -61,6 +61,9 @@ protected:
       --it;
       return *this;
     }
+    const std::pair<const Key,T>& operator*() {
+      return *it;
+    }
     const std::pair<const Key,T>* operator->() {
       return it.operator->();
     }
@@ -103,6 +106,9 @@ protected:
       --it;
       return *this;
     }
+    std::pair<const Key,T>& operator*() {
+      return *it;
+    }
     std::pair<const Key,T>* operator->() {
       return it.operator->();
     }
index 01e3d3c4992041daa9ee9f8e753e3e97263a7c0a..29c5cd63308d724052de57ff3a6bd480f1b71edc 100644 (file)
@@ -266,7 +266,7 @@ public:
     ::encode(version, bl);
     ::encode(projected_version, bl);
     ::encode(lock, bl);
-    ::encode(replica_map, bl);
+    ::encode(get_replicas(), bl);
     get(PIN_TEMPEXPORTING);
   }
   void finish_export() {
@@ -288,14 +288,14 @@ public:
     ::decode(version, blp);
     ::decode(projected_version, blp);
     ::decode(lock, blp);
-    ::decode(replica_map, blp);
+    ::decode(get_replicas(), blp);
 
     // twiddle
     state &= MASK_STATE_IMPORT_KEPT;
     state_set(CDentry::STATE_AUTH);
     if (nstate & STATE_DIRTY)
       _mark_dirty(ls);
-    if (!replica_map.empty())
+    if (is_replicated())
       get(PIN_REPLICATED);
     replica_nonce = 0;
   }
index c190cca175b479f89f74d8dc55c118adff491351..57b1e981f03ae05a954cbb2b43c524eca8091200 100644 (file)
@@ -932,7 +932,7 @@ void CDir::finish_old_fragment(list<MDSInternalContextBase*>& waiters, bool repl
 
 void CDir::init_fragment_pins()
 {
-  if (!replica_map.empty())
+  if (is_replicated())
     get(PIN_REPLICATED);
   if (state_test(STATE_DIRTY))
     get(PIN_DIRTY);
@@ -976,7 +976,7 @@ void CDir::split(int bits, list<CDir*>& subs, list<MDSInternalContextBase*>& wai
   for (list<frag_t>::iterator p = frags.begin(); p != frags.end(); ++p) {
     CDir *f = new CDir(inode, *p, cache, is_auth());
     f->state_set(state & (MASK_STATE_FRAGMENT_KEPT | STATE_COMPLETE));
-    f->replica_map = replica_map;
+    f->get_replicas() = get_replicas();
     f->dir_auth = dir_auth;
     f->init_fragment_pins();
     f->set_version(get_version());
@@ -1085,12 +1085,10 @@ void CDir::merge(list<CDir*>& subs, list<MDSInternalContextBase*>& waiters, bool
       steal_dentry(dir->items.begin()->second);
     
     // merge replica map
-    for (compact_map<mds_rank_t,unsigned>::iterator p = dir->replicas_begin();
-        p != dir->replicas_end();
-        ++p) {
-      unsigned cur = replica_map[p->first];
-      if (p->second > cur)
-       replica_map[p->first] = p->second;
+    for (const auto &p : dir->get_replicas()) {
+      unsigned cur = get_replicas()[p.first];
+      if (p.second > cur)
+       get_replicas()[p.first] = p.second;
     }
 
     // merge version
@@ -2432,7 +2430,7 @@ void CDir::encode_export(bufferlist& bl)
   ::encode(pop_auth_subtree, bl);
 
   ::encode(dir_rep_by, bl);  
-  ::encode(replica_map, bl);
+  ::encode(get_replicas(), bl);
 
   get(PIN_TEMPEXPORTING);
 }
@@ -2473,8 +2471,8 @@ void CDir::decode_import(bufferlist::iterator& blp, utime_t now, LogSegment *ls)
   pop_auth_subtree_nested.add(now, cache->decayrate, pop_auth_subtree);
 
   ::decode(dir_rep_by, blp);
-  ::decode(replica_map, blp);
-  if (!replica_map.empty()) get(PIN_REPLICATED);
+  ::decode(get_replicas(), blp);
+  if (is_replicated()) get(PIN_REPLICATED);
 
   replica_nonce = 0;  // no longer defined
 
index 3b0d6ba4a164188515fc479a3e2028645e7257d5..3b4e76d92a2f29d57b05c9bbc4ba5eb5fd013548 100644 (file)
@@ -3622,7 +3622,7 @@ void CInode::encode_export(bufferlist& bl)
 
   ::encode(pop, bl);
 
-  ::encode(replica_map, bl);
+  ::encode(get_replicas(), bl);
 
   // include scatterlock info for any bounding CDirs
   bufferlist bounding;
@@ -3687,8 +3687,8 @@ void CInode::decode_import(bufferlist::iterator& p,
 
   ::decode(pop, ceph_clock_now(), p);
 
-  ::decode(replica_map, p);
-  if (!replica_map.empty())
+  ::decode(get_replicas(), p);
+  if (is_replicated())
     get(PIN_REPLICATED);
   replica_nonce = 0;
 
index f76c698d8beb03b9bc67b54896db53dcd8b8e787..01bc1e2c4492361765f780f309972950ed4db367 100644 (file)
@@ -130,28 +130,24 @@ void Locker::tick()
 
 void Locker::send_lock_message(SimpleLock *lock, int msg)
 {
-  for (compact_map<mds_rank_t,unsigned>::iterator it = lock->get_parent()->replicas_begin();
-       it != lock->get_parent()->replicas_end();
-       ++it) {
+  for (const auto &it : lock->get_parent()->get_replicas()) {
     if (mds->is_cluster_degraded() &&
-       mds->mdsmap->get_state(it->first) < MDSMap::STATE_REJOIN) 
+       mds->mdsmap->get_state(it.first) < MDSMap::STATE_REJOIN)
       continue;
     MLock *m = new MLock(lock, msg, mds->get_nodeid());
-    mds->send_message_mds(m, it->first);
+    mds->send_message_mds(m, it.first);
   }
 }
 
 void Locker::send_lock_message(SimpleLock *lock, int msg, const bufferlist &data)
 {
-  for (compact_map<mds_rank_t,unsigned>::iterator it = lock->get_parent()->replicas_begin();
-       it != lock->get_parent()->replicas_end();
-       ++it) {
+  for (const auto &it : lock->get_parent()->get_replicas()) {
     if (mds->is_cluster_degraded() &&
-       mds->mdsmap->get_state(it->first) < MDSMap::STATE_REJOIN) 
+       mds->mdsmap->get_state(it.first) < MDSMap::STATE_REJOIN)
       continue;
     MLock *m = new MLock(lock, msg, mds->get_nodeid());
     m->set_data(data);
-    mds->send_message_mds(m, it->first);
+    mds->send_message_mds(m, it.first);
   }
 }
 
index 0bb1cda9b90a86c9aa9837f40b1e1759fb62ab7c..9e423bada23dd388aa54cb3ddc1b62f386d3a022 100644 (file)
@@ -2017,12 +2017,10 @@ update:
     msg->quota = i->quota;
     mds->send_message_client_counted(msg, session->connection);
   }
-  for (compact_map<mds_rank_t, unsigned>::iterator it = in->replicas_begin();
-       it != in->replicas_end();
-       ++it) {
+  for (const auto &it : in->get_replicas()) {
     MGatherCaps *msg = new MGatherCaps;
     msg->ino = in->ino();
-    mds->send_message_mds(msg, it->first);
+    mds->send_message_mds(msg, it.first);
   }
 }
 
@@ -5953,13 +5951,11 @@ void MDCache::rejoin_send_acks()
       dq.pop_front();
       
       // dir
-      for (compact_map<mds_rank_t,unsigned>::iterator r = dir->replicas_begin();
-          r != dir->replicas_end();
-          ++r) {
-       auto it = acks.find(r->first);
+      for (auto &r : dir->get_replicas()) {
+       auto it = acks.find(r.first);
        if (it == acks.end())
          continue;
-       it->second->add_strong_dirfrag(dir->dirfrag(), ++r->second, dir->dir_rep);
+       it->second->add_strong_dirfrag(dir->dirfrag(), ++r.second, dir->dir_rep);
        it->second->add_dirfrag_base(dir);
       }
           
@@ -5975,36 +5971,32 @@ void MDCache::rejoin_send_acks()
          in = dnl->get_inode();
 
        // dentry
-       for (compact_map<mds_rank_t,unsigned>::iterator r = dn->replicas_begin();
-            r != dn->replicas_end();
-            ++r) {
-         auto it = acks.find(r->first);
+       for (auto &r : dn->get_replicas()) {
+         auto it = acks.find(r.first);
          if (it == acks.end())
            continue;
          it->second->add_strong_dentry(dir->dirfrag(), dn->name, dn->first, dn->last,
                                           dnl->is_primary() ? dnl->get_inode()->ino():inodeno_t(0),
                                           dnl->is_remote() ? dnl->get_remote_ino():inodeno_t(0),
                                           dnl->is_remote() ? dnl->get_remote_d_type():0,
-                                          ++r->second,
+                                          ++r.second,
                                           dn->lock.get_replica_state());
          // peer missed MDentrylink message ?
-         if (in && !in->is_replica(r->first))
-           in->add_replica(r->first);
+         if (in && !in->is_replica(r.first))
+           in->add_replica(r.first);
        }
        
        if (!in)
          continue;
 
-       for (compact_map<mds_rank_t,unsigned>::iterator r = in->replicas_begin();
-            r != in->replicas_end();
-            ++r) {
-         auto it = acks.find(r->first);
+       for (auto &r : in->get_replicas()) {
+         auto it = acks.find(r.first);
          if (it == acks.end())
            continue;
          it->second->add_inode_base(in, mds->mdsmap->get_up_features());
          bufferlist bl;
-         in->_encode_locks_state_for_rejoin(bl, r->first);
-         it->second->add_inode_locks(in, ++r->second, bl);
+         in->_encode_locks_state_for_rejoin(bl, r.first);
+         it->second->add_inode_locks(in, ++r.second, bl);
        }
        
        // subdirs in this subtree?
@@ -6015,28 +6007,24 @@ void MDCache::rejoin_send_acks()
 
   // base inodes too
   if (root && root->is_auth()) 
-    for (compact_map<mds_rank_t,unsigned>::iterator r = root->replicas_begin();
-        r != root->replicas_end();
-        ++r) {
-      auto it = acks.find(r->first);
+    for (auto &r : root->get_replicas()) {
+      auto it = acks.find(r.first);
       if (it == acks.end())
        continue;
       it->second->add_inode_base(root, mds->mdsmap->get_up_features());
       bufferlist bl;
-      root->_encode_locks_state_for_rejoin(bl, r->first);
-      it->second->add_inode_locks(root, ++r->second, bl);
+      root->_encode_locks_state_for_rejoin(bl, r.first);
+      it->second->add_inode_locks(root, ++r.second, bl);
     }
   if (myin)
-    for (compact_map<mds_rank_t,unsigned>::iterator r = myin->replicas_begin();
-        r != myin->replicas_end();
-        ++r) {
-      auto it = acks.find(r->first);
+    for (auto &r : myin->get_replicas()) {
+      auto it = acks.find(r.first);
       if (it == acks.end())
        continue;
       it->second->add_inode_base(myin, mds->mdsmap->get_up_features());
       bufferlist bl;
-      myin->_encode_locks_state_for_rejoin(bl, r->first);
-      it->second->add_inode_locks(myin, ++r->second, bl);
+      myin->_encode_locks_state_for_rejoin(bl, r.first);
+      it->second->add_inode_locks(myin, ++r.second, bl);
     }
 
   // include inode base for any inodes whose scatterlocks may have updated
@@ -6044,10 +6032,8 @@ void MDCache::rejoin_send_acks()
        p != rejoin_potential_updated_scatterlocks.end();
        ++p) {
     CInode *in = *p;
-    for (compact_map<mds_rank_t,unsigned>::iterator r = in->replicas_begin();
-        r != in->replicas_end();
-        ++r) {
-      auto it = acks.find(r->first);
+    for (const auto &r : in->get_replicas()) {
+      auto it = acks.find(r.first);
       if (it == acks.end())
        continue;
       it->second->add_inode_base(in, mds->mdsmap->get_up_features());
@@ -7251,7 +7237,7 @@ void MDCache::handle_cache_expire(MCacheExpire *m)
       if (nonce == dir->get_replica_nonce(from)) {
        // remove from our cached_by
        dout(7) << " dir expire on " << *dir << " from mds." << from
-               << " replicas was " << dir->replica_map << dendl;
+               << " replicas was " << dir->get_replicas() << dendl;
        dir->remove_replica(from);
       } 
       else {
@@ -10295,10 +10281,9 @@ int MDCache::send_dir_updates(CDir *dir, bool bcast)
   if (bcast) {
     mds->get_mds_map()->get_active_mds_set(who);
   } else {
-    for (compact_map<mds_rank_t,unsigned>::iterator p = dir->replicas_begin();
-        p != dir->replicas_end();
-        ++p)
-      who.insert(p->first);
+    for (const auto &p : dir->get_replicas()) {
+      who.insert(p.first);
+    }
   }
   
   dout(7) << "sending dir_update on " << *dir << " bcast " << bcast << " to " << who << dendl;
@@ -10381,22 +10366,20 @@ void MDCache::send_dentry_link(CDentry *dn, MDRequestRef& mdr)
   dout(7) << "send_dentry_link " << *dn << dendl;
 
   CDir *subtree = get_subtree_root(dn->get_dir());
-  for (compact_map<mds_rank_t,unsigned>::iterator p = dn->replicas_begin();
-       p != dn->replicas_end();
-       ++p) {
+  for (const auto &p : dn->get_replicas()) {
     // don't tell (rename) witnesses; they already know
-    if (mdr.get() && mdr->more()->witnessed.count(p->first))
+    if (mdr.get() && mdr->more()->witnessed.count(p.first))
       continue;
-    if (mds->mdsmap->get_state(p->first) < MDSMap::STATE_REJOIN ||
-       (mds->mdsmap->get_state(p->first) == MDSMap::STATE_REJOIN &&
-        rejoin_gather.count(p->first)))
+    if (mds->mdsmap->get_state(p.first) < MDSMap::STATE_REJOIN ||
+       (mds->mdsmap->get_state(p.first) == MDSMap::STATE_REJOIN &&
+        rejoin_gather.count(p.first)))
       continue;
     CDentry::linkage_t *dnl = dn->get_linkage();
     MDentryLink *m = new MDentryLink(subtree->dirfrag(), dn->get_dir()->dirfrag(),
                                     dn->name, dnl->is_primary());
     if (dnl->is_primary()) {
       dout(10) << "  primary " << *dnl->get_inode() << dendl;
-      replicate_inode(dnl->get_inode(), p->first, m->bl,
+      replicate_inode(dnl->get_inode(), p.first, m->bl,
                      mds->mdsmap->get_up_features());
     } else if (dnl->is_remote()) {
       inodeno_t ino = dnl->get_remote_ino();
@@ -10406,7 +10389,7 @@ void MDCache::send_dentry_link(CDentry *dn, MDRequestRef& mdr)
       ::encode(d_type, m->bl);
     } else
       ceph_abort();   // aie, bad caller!
-    mds->send_message_mds(m, p->first);
+    mds->send_message_mds(m, p.first);
   }
 }
 
@@ -11322,12 +11305,10 @@ void MDCache::_fragment_stored(MDRequestRef& mdr)
 
   // tell peers
   CDir *first = *info.resultfrags.begin();
-  for (compact_map<mds_rank_t,unsigned>::iterator p = first->replicas_begin();
-       p != first->replicas_end();
-       ++p) {
-    if (mds->mdsmap->get_state(p->first) < MDSMap::STATE_REJOIN ||
-       (mds->mdsmap->get_state(p->first) == MDSMap::STATE_REJOIN &&
-        rejoin_gather.count(p->first)))
+  for (const auto &p : first->get_replicas()) {
+    if (mds->mdsmap->get_state(p.first) < MDSMap::STATE_REJOIN ||
+       (mds->mdsmap->get_state(p.first) == MDSMap::STATE_REJOIN &&
+        rejoin_gather.count(p.first)))
       continue;
 
     MMDSFragmentNotify *notify = new MMDSFragmentNotify(basedirfrag, info.bits);
@@ -11336,9 +11317,9 @@ void MDCache::_fragment_stored(MDRequestRef& mdr)
     for (list<CDir*>::iterator q = info.resultfrags.begin();
         q != info.resultfrags.end();
         ++q)
-      replicate_dir(*q, p->first, notify->basebl);
+      replicate_dir(*q, p.first, notify->basebl);
 
-    mds->send_message_mds(notify, p->first);
+    mds->send_message_mds(notify, p.first);
   }
 
   // journal commit
index 1265a4a9e8912d93822e0174a77cd6f3889f6a72..eca6fac148b42e05afc8e484771a39c100a96cb6 100644 (file)
@@ -21,12 +21,10 @@ void MDSCacheObject::dump(Formatter *f) const
   f->open_object_section("auth_state");
   {
     f->open_object_section("replicas");
-    const compact_map<mds_rank_t,unsigned>& replicas = get_replicas();
-    for (compact_map<mds_rank_t,unsigned>::const_iterator i = replicas.begin();
-         i != replicas.end(); ++i) {
+    for (const auto &it : get_replicas()) {
       std::ostringstream rank_str;
-      rank_str << i->first;
-      f->dump_int(rank_str.str().c_str(), i->second);
+      rank_str << it.first;
+      f->dump_int(rank_str.str().c_str(), it.second);
     }
     f->close_section();
   }
index 1bc80cfed67307f6f22792f44e1d397e35022907..0d5c2aeeed48d3830cbbaca68570dfd0ac2e0ab0 100644 (file)
@@ -286,14 +286,12 @@ protected:
       put(PIN_REPLICATED);
     replica_map.clear();
   }
-  compact_map<mds_rank_t,unsigned>::iterator replicas_begin() { return replica_map.begin(); }
-  compact_map<mds_rank_t,unsigned>::iterator replicas_end() { return replica_map.end(); }
+  compact_map<mds_rank_t,unsigned>& get_replicas() { return replica_map; }
   const compact_map<mds_rank_t,unsigned>& get_replicas() const { return replica_map; }
   void list_replicas(std::set<mds_rank_t>& ls) const {
-    for (compact_map<mds_rank_t,unsigned>::const_iterator p = replica_map.begin();
-        p != replica_map.end();
-        ++p)
-      ls.insert(p->first);
+    for (const auto &p : replica_map) {
+      ls.insert(p.first);
+    }
   }
 
   unsigned get_replica_nonce() const { return replica_nonce; }
index 6ff5a931b95a5d5f35929fd42d0c27e8bdd9358b..59a82dcd42be235a7fd1804e103d3299aac80cf8 100644 (file)
@@ -1087,12 +1087,10 @@ void Migrator::export_frozen(CDir *dir, uint64_t tid)
   MExportDirPrep *prep = new MExportDirPrep(dir->dirfrag(), it->second.tid);
 
   // include list of bystanders
-  for (compact_map<mds_rank_t,unsigned>::iterator p = dir->replicas_begin();
-       p != dir->replicas_end();
-       ++p) {
-    if (p->first != it->second.peer) {
-      dout(10) << "bystander mds." << p->first << dendl;
-      prep->add_bystander(p->first);
+  for (const auto &p : dir->get_replicas()) {
+    if (p.first != it->second.peer) {
+      dout(10) << "bystander mds." << p.first << dendl;
+      prep->add_bystander(p.first);
     }
   }
 
@@ -1272,22 +1270,20 @@ void Migrator::handle_export_prep_ack(MExportDirPrepAck *m)
          it->second.warning_ack_waiting.count(MDS_RANK_NONE) > 0));
   assert(it->second.notify_ack_waiting.empty());
 
-  for (compact_map<mds_rank_t,unsigned>::iterator p = dir->replicas_begin();
-       p != dir->replicas_end();
-       ++p) {
-    if (p->first == it->second.peer) continue;
+  for (const auto &p : dir->get_replicas()) {
+    if (p.first == it->second.peer) continue;
     if (mds->is_cluster_degraded() &&
-       !mds->mdsmap->is_clientreplay_or_active_or_stopping(p->first))
+       !mds->mdsmap->is_clientreplay_or_active_or_stopping(p.first))
       continue;  // only if active
-    it->second.warning_ack_waiting.insert(p->first);
-    it->second.notify_ack_waiting.insert(p->first);  // we'll eventually get a notifyack, too!
+    it->second.warning_ack_waiting.insert(p.first);
+    it->second.notify_ack_waiting.insert(p.first);  // we'll eventually get a notifyack, too!
 
     MExportDirNotify *notify = new MExportDirNotify(dir->dirfrag(), it->second.tid, true,
                                                    mds_authority_t(mds->get_nodeid(),CDIR_AUTH_UNKNOWN),
                                                    mds_authority_t(mds->get_nodeid(),it->second.peer));
     for (set<CDir*>::iterator q = bounds.begin(); q != bounds.end(); ++q)
       notify->get_bounds().push_back((*q)->dirfrag());
-    mds->send_message_mds(notify, p->first);
+    mds->send_message_mds(notify, p.first);
     
   }
 
index 27eae7bebd4a0937b4daad52406eb2a608106678..56d1c4b0b7ed52751b8a1858ace82a2cc6d0dffe 100644 (file)
@@ -373,10 +373,9 @@ public:
   }
 
   void init_gather() {
-    for (compact_map<mds_rank_t,unsigned>::iterator p = parent->replicas_begin();
-        p != parent->replicas_end();
-        ++p)
-      more()->gather_set.insert(p->first);
+    for (const auto p : parent->get_replicas()) {
+      more()->gather_set.insert(p.first);
+    }
   }
   bool is_gathering() const {
     return have_more() && !more()->gather_set.empty();