Skip to content

Commit

Permalink
mds: cleanup replica_map access
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
batrick committed Sep 12, 2017
1 parent 5fa557d commit d1b6cad
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 116 deletions.
6 changes: 6 additions & 0 deletions src/include/compact_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class compact_map_base {
--it;
return *this;
}
const std::pair<const Key,T>& operator*() {
return *it;
}
const std::pair<const Key,T>* operator->() {
return it.operator->();
}
Expand Down Expand Up @@ -103,6 +106,9 @@ class compact_map_base {
--it;
return *this;
}
std::pair<const Key,T>& operator*() {
return *it;
}
std::pair<const Key,T>* operator->() {
return it.operator->();
}
Expand Down
6 changes: 3 additions & 3 deletions src/mds/CDentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class CDentry : public MDSCacheObject, public LRUObject, public Counter<CDentry>
::encode(version, bl);
::encode(projected_version, bl);
::encode(lock, bl);
::encode(replica_map, bl);
::encode(get_replicas(), bl);
get(PIN_TEMPEXPORTING);
}
void finish_export() {
Expand All @@ -288,14 +288,14 @@ class CDentry : public MDSCacheObject, public LRUObject, public Counter<CDentry>
::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;
}
Expand Down
20 changes: 9 additions & 11 deletions src/mds/CDir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/mds/CInode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
16 changes: 6 additions & 10 deletions src/mds/Locker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
101 changes: 41 additions & 60 deletions src/mds/MDCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2017,12 +2017,10 @@ void MDCache::broadcast_quota_to_client(CInode *in)
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);
}
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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?
Expand All @@ -6015,39 +6007,33 @@ 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
for (set<CInode*>::iterator p = rejoin_potential_updated_scatterlocks.begin();
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());
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
8 changes: 3 additions & 5 deletions src/mds/MDSCacheObject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Loading

0 comments on commit d1b6cad

Please sign in to comment.