]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: Add multi_target_id to handle libcephfs mds_spce=* command
authorJimyeong Lee <jinmyeong.lee@linecorp.com>
Sun, 16 Jul 2023 15:42:12 +0000 (00:42 +0900)
committerJinmyeong Lee <jinmyeong.lee@linecorp.com>
Fri, 15 Sep 2023 03:06:13 +0000 (12:06 +0900)
To fix multi target MDSs command result overwritten issue, add multi_target_id feature in CommandTable.
Also, add multi_target_id in CommandOp to track all the multi target commands end to make formatted result

Signed-off-by: Jimyeong Lee <jinmyeong.lee@linecorp.com>
src/client/Client.h
src/common/CommandTable.h
src/mgr/MgrClient.h

index 1e4d5890d198dbbcb3c8bbd7801ed84918271162..53df27e409ea602a063853333f964d1551638320 100644 (file)
@@ -97,6 +97,7 @@ class MDSCommandOp : public CommandOp
   mds_gid_t     mds_gid;
 
   explicit MDSCommandOp(ceph_tid_t t) : CommandOp(t) {}
+  explicit MDSCommandOp(ceph_tid_t t, ceph_tid_t multi_id) : CommandOp(t, multi_id) {}
 };
 
 /* error code for ceph_fuse */
index 53218d65351fc0ead299cb16afe0af6396e1db57..672161af65229b1b80d78de84a0001acbb55904e 100644 (file)
@@ -23,6 +23,8 @@ class CommandOp
   public:
   ConnectionRef con;
   ceph_tid_t tid;
+  // multi_target_id == 0 means single target command
+  ceph_tid_t multi_target_id;
 
   std::vector<std::string> cmd;
   ceph::buffer::list    inbl;
@@ -48,9 +50,11 @@ class CommandOp
     }
   }
 
-  CommandOp(const ceph_tid_t t) : tid(t), on_finish(nullptr),
+  CommandOp(const ceph_tid_t t) : tid(t), multi_target_id(0), on_finish(nullptr),
                                   outbl(nullptr), outs(nullptr) {}
   CommandOp() : tid(0), on_finish(nullptr), outbl(nullptr), outs(nullptr) {}
+  CommandOp(const ceph_tid_t t, const ceph_tid_t multi_id) : tid(t), multi_target_id(multi_id),
+                                                             on_finish(nullptr), outbl(nullptr), outs(nullptr) {}
 };
 
 /**
@@ -62,23 +66,36 @@ class CommandTable
 {
 protected:
   ceph_tid_t last_tid;
+  ceph_tid_t last_multi_target_id;
+
   std::map<ceph_tid_t, T> commands;
+  std::map<ceph_tid_t, std::set<ceph_tid_t> > multi_targets;
 
 public:
 
   CommandTable()
-    : last_tid(0)
+    : last_tid(0), last_multi_target_id(0)
   {}
 
   ~CommandTable()
   {
     ceph_assert(commands.empty());
+    ceph_assert(multi_targets.empty());
+  }
+
+  ceph_tid_t get_new_multi_target_id()
+  {
+    return ++last_multi_target_id;
   }
 
-  T& start_command()
+  T& start_command(ceph_tid_t multi_id=0)
   {
     ceph_tid_t tid = last_tid++;
-    commands.insert(std::make_pair(tid, T(tid)) );
+    commands.insert(std::make_pair(tid, T(tid, multi_id)) );
+
+    if (multi_id != 0) {
+      multi_targets[multi_id].insert(tid);
+    }
 
     return commands.at(tid);
   }
@@ -93,18 +110,35 @@ public:
     return commands.count(tid) > 0;
   }
 
+  std::size_t count_multi_commands(ceph_tid_t multi_id)
+  {
+    return multi_targets[multi_id].size();
+  }
+
   T& get_command(ceph_tid_t tid)
   {
     return commands.at(tid);
   }
 
+  bool get_multi_target_id(ceph_tid_t tid) const
+  {
+    return commands.at(tid).multi_target_id;
+  }
+
   void erase(ceph_tid_t tid)
   {
+    ceph_tid_t multi_id = commands.at(tid).multi_target_id;
     commands.erase(tid);
+    multi_targets[multi_id].erase(tid);
+
+    if(count_multi_commands(multi_id) == 0) {
+      multi_targets.erase(multi_id);
+    }
   }
 
   void clear() {
     commands.clear();
+    multi_targets.clear();
   }
 };
 
index a48ae163e18a8da011efeb81729d7022dc1e8da3..1f9bb397fbec16b2efa0b93de54a54be0daea2d5 100644 (file)
@@ -54,6 +54,7 @@ class MgrCommand : public CommandOp
   bool tell = false;
 
   explicit MgrCommand(ceph_tid_t t) : CommandOp(t) {}
+  explicit MgrCommand(ceph_tid_t t, ceph_tid_t multi_id) : CommandOp(t, multi_id) {}
   MgrCommand() : CommandOp() {}
 };