]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: Apply multi target MDS result handling
authorJimyeong Lee <jinmyeong.lee@linecorp.com>
Sun, 16 Jul 2023 15:44:19 +0000 (00:44 +0900)
committerRishabh Dave <ridave@redhat.com>
Wed, 8 Nov 2023 17:18:39 +0000 (22:48 +0530)
To fix the issue that multi target MDSs result is overwritten

Signed-off-by: Jimyeong Lee <jinmyeong.lee@linecorp.com>
(cherry picked from commit 0d03e9793b6a91b8938d50eac88ba097587b4313)

src/client/Client.cc

index 2b7db5a894d1cc325e2fd2a3d2d7a114d24484e1..21940dde6f317d8b43b9d7c40622601eebac679e 100644 (file)
@@ -6354,6 +6354,12 @@ int Client::mds_command(
     populate_metadata("");
   }
 
+  ceph_tid_t multi_target_id = 0;
+  if (non_laggy.size() > 1) {
+      std::scoped_lock cmd_lock(command_lock);
+      multi_target_id = command_table.get_new_multi_target_id();
+  }
+
   // Send commands to targets
   C_GatherBuilder gather(cct, onfinish);
   for (const auto& target_gid : non_laggy) {
@@ -6366,7 +6372,7 @@ int Client::mds_command(
     {
       std::scoped_lock cmd_lock(command_lock);
       // Generate MDSCommandOp state
-      auto &op = command_table.start_command();
+      auto &op = command_table.start_command(multi_target_id);
 
       op.on_finish = gather.new_sub();
       op.cmd = cmd;
@@ -6403,8 +6409,33 @@ void Client::handle_command_reply(const MConstRef<MCommandReply>& m)
   }
 
   auto &op = command_table.get_command(tid);
+  ceph_tid_t multi_id = command_table.get_multi_target_id(tid);
+
   if (op.outbl) {
-    *op.outbl = m->get_data();
+    if (multi_id != 0 && m->r == 0) {
+      string prefix;
+      string suffix = "}";
+      string mds_name = fmt::format("mds.{}", fsmap->get_info_gid(op.mds_gid).name);
+
+      if (op.outbl->length() == 0) { // very first command result
+        prefix = fmt::format("[{{\"{}\":", mds_name);
+      }
+      else {
+        prefix = fmt::format(",{{\"{}\":", mds_name);
+      }
+
+      op.outbl->append(prefix);
+      op.outbl->append(m->get_data());
+      op.outbl->append(suffix);
+
+      // when this command is the last one
+      if (command_table.count_multi_commands(multi_id) == 1) {
+        op.outbl->append("]");
+      }
+    }
+    else if (multi_id == 0) {
+      *op.outbl = m->get_data();
+    }
   }
   if (op.outs) {
     *op.outs = m->rs;