]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: move MDRequestImpl::batch_reqs into Batch_Getattr_Lookup
authorYan, Zheng <zyan@redhat.com>
Fri, 27 Mar 2020 11:06:14 +0000 (19:06 +0800)
committerVicente Cheng <freeze.bilsted@gmail.com>
Mon, 7 Sep 2020 09:58:07 +0000 (09:58 +0000)
Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
(cherry picked from commit 7e59369230e71a541a0a9927513c8ab1c39cf853)

src/mds/BatchOp.h
src/mds/Mutation.h
src/mds/Server.cc

index b54ad9699694c3e611edf03273f42dc29fe9454a..bc4e21bcea9591a2fba1433062b604c5f350093a 100644 (file)
@@ -25,7 +25,7 @@ public:
   virtual ~BatchOp() {}
 
   virtual void add_request(const ceph::ref_t<class MDRequestImpl>& mdr) = 0;
-  virtual void set_request(const ceph::ref_t<class MDRequestImpl>& mdr) = 0;
+  virtual ceph::ref_t<class MDRequestImpl> find_new_head() = 0;
 
   virtual void print(std::ostream&) = 0;
 
index b80aef2866fb47dc3c65091585f207ecd879265b..44f901380c315c82dbfa2db8fd626edd6f41dbe0 100644 (file)
@@ -446,7 +446,6 @@ struct MDRequestImpl : public MutationImpl {
   // indicator for vxattr osdmap update
   bool waited_for_osdmap = false;
 
-  std::vector<Ref> batch_reqs;
 protected:
   void _dump(Formatter *f) const override;
   void _dump_op_descriptor_unlocked(ostream& stream) const override;
index d2895f0238ee67e022555c94fb68713ababa9e3c..b27b42f03bb8982c7ab8f2f8bb7a9aab6e631894 100644 (file)
@@ -82,6 +82,7 @@ class Batch_Getattr_Lookup : public BatchOp {
 protected:
   Server* server;
   ceph::ref_t<MDRequestImpl> mdr;
+  std::vector<ceph::ref_t<MDRequestImpl>> batch_reqs;
   int res = 0;
 public:
   Batch_Getattr_Lookup(Server* s, const ceph::ref_t<MDRequestImpl>& r)
@@ -91,32 +92,43 @@ public:
     else
       mdr->batch_op_map = &mdr->in[0]->batch_ops;
   }
-  void add_request(const ceph::ref_t<MDRequestImpl>& m) override {
-    mdr->batch_reqs.push_back(m);
+  void add_request(const ceph::ref_t<MDRequestImpl>& r) override {
+    batch_reqs.push_back(r);
   }
-  void set_request(const ceph::ref_t<MDRequestImpl>& m) override {
-    mdr = m;
+  ceph::ref_t<MDRequestImpl> find_new_head() override {
+    while (!batch_reqs.empty()) {
+      auto r = std::move(batch_reqs.back());
+      batch_reqs.pop_back();
+      if (r->killed)
+       continue;
+
+      r->batch_op_map = mdr->batch_op_map;
+      mdr->batch_op_map = nullptr;
+      mdr = r;
+      return mdr;
+    }
+    return nullptr;
   }
   void _forward(mds_rank_t t) override {
     MDCache* mdcache = server->mdcache;
     mdcache->mds->forward_message_mds(mdr->release_client_request(), t);
     mdr->set_mds_stamp(ceph_clock_now());
-    for (auto& m : mdr->batch_reqs) {
+    for (auto& m : batch_reqs) {
       if (!m->killed)
        mdcache->request_forward(m, t);
     }
-    mdr->batch_reqs.clear();
+    batch_reqs.clear();
   }
   void _respond(int r) override {
     mdr->set_mds_stamp(ceph_clock_now());
-    for (auto& m : mdr->batch_reqs) {
+    for (auto& m : batch_reqs) {
       if (!m->killed) {
        m->tracei = mdr->tracei;
        m->tracedn = mdr->tracedn;
        server->respond_to_request(m, r);
       }
     }
-    mdr->batch_reqs.clear();
+    batch_reqs.clear();
     server->reply_client_request(mdr, make_message<MClientReply>(*mdr->client_request, r));
   }
   void print(std::ostream& o) {
@@ -2406,31 +2418,12 @@ void Server::dispatch_client_request(MDRequestRef& mdr)
     if (mdr->is_batch_head()) {
       int mask = mdr->client_request->head.args.getattr.mask;
       auto it = mdr->batch_op_map->find(mask);
-
-      if (!mdr->batch_reqs.empty()) {
-       MDRequestRef new_batch_head;
-       for (auto itr = mdr->batch_reqs.cbegin(); itr != mdr->batch_reqs.cend();) {
-         auto req = *itr;
-         itr = mdr->batch_reqs.erase(itr);
-         if (!req->killed) {
-           new_batch_head = req;
-           break;
-         }
-       }
-       if (!new_batch_head) {
-         mdr->batch_op_map->erase(it);
-         return;
-       }
-
-       new_batch_head->batch_reqs = std::move(mdr->batch_reqs);
-       new_batch_head->batch_op_map = mdr->batch_op_map;
-       mdr->batch_op_map = nullptr;
-       it->second->set_request(new_batch_head);
-       mdr = new_batch_head;
-      } else {
+      auto new_batch_head = it->second->find_new_head();
+      if (!new_batch_head) {
        mdr->batch_op_map->erase(it);
        return;
       }
+      mdr = std::move(new_batch_head);
     } else {
       return;
     }