From: Yanhu Cao Date: Tue, 11 Aug 2020 08:10:26 +0000 (+0800) Subject: client: choose a random replica mds to send the request X-Git-Tag: wip-pdonnell-testing-20200918.022351~296^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=504c8cbc2cfcfd0822a70b07b07330be2abb8212;p=ceph-ci.git client: choose a random replica mds to send the request Fixes: https://tracker.ceph.com/issues/46894 Signed-off-by: Yanhu Cao --- diff --git a/src/client/Client.cc b/src/client/Client.cc index e7eb2c23ef7..bf414edbfda 100755 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -84,6 +84,7 @@ #include "include/lru.h" #include "include/compat.h" #include "include/stringify.h" +#include "include/random.h" #include "Client.h" #include "Inode.h" @@ -1073,7 +1074,11 @@ void Client::update_dir_dist(Inode *in, DirStat *dst) } // replicated - in->dir_replicated = !dst->dist.empty(); // FIXME that's just one frag! + in->dir_replicated = !dst->dist.empty(); + if (!dst->dist.empty()) + in->frag_repmap[dst->frag].assign(dst->dist.begin(), dst->dist.end()) ; + else + in->frag_repmap.erase(dst->frag); } void Client::clear_dir_complete_and_ordered(Inode *diri, bool complete) @@ -1498,9 +1503,16 @@ mds_rank_t Client::choose_target_mds(MetaRequest *req, Inode** phash_diri) ldout(cct, 20) << __func__ << " " << *in << " is_hash=" << is_hash << " hash=" << hash << dendl; - if (is_hash && S_ISDIR(in->mode) && !in->fragmap.empty()) { + if (is_hash && S_ISDIR(in->mode) && (!in->fragmap.empty() || !in->frag_repmap.empty())) { frag_t fg = in->dirfragtree[hash]; - if (in->fragmap.count(fg)) { + if (!req->auth_is_best()) { + auto repmapit = in->frag_repmap.find(fg); + if (repmapit != in->frag_repmap.end()) { + auto& repmap = repmapit->second; + auto r = ceph::util::generate_random_number(0, repmap.size()-1); + mds = repmap.at(r); + } + } else if (in->fragmap.count(fg)) { mds = in->fragmap[fg]; if (phash_diri) *phash_diri = in; diff --git a/src/client/Inode.h b/src/client/Inode.h index afaf64e0515..dce9be84569 100644 --- a/src/client/Inode.h +++ b/src/client/Inode.h @@ -227,6 +227,7 @@ struct Inode { string symlink; // symlink content, if it's a symlink map xattrs; map fragmap; // known frag -> mds mappings + map> frag_repmap; // non-auth mds mappings std::list waitfor_caps; std::list waitfor_commit;