]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/mon: use a vector for mon_commands
authorKefu Chai <kchai@redhat.com>
Tue, 2 Mar 2021 10:08:27 +0000 (18:08 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 2 Mar 2021 11:04:28 +0000 (19:04 +0800)
for smaller memory foot print. as we don't have lots of mon_command in
flight, hence not likely to benefit from a O(log(n)) lookup.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/mon/MonClient.cc
src/crimson/mon/MonClient.h

index 3dcd4e699782d917e3db4fe0af742ed370a722eb..b42e98f885694f04ae3f28d58dc48e93481e45a8 100644 (file)
@@ -829,9 +829,13 @@ Client::handle_get_version_reply(Ref<MMonGetVersionReply> m)
 seastar::future<> Client::handle_mon_command_ack(Ref<MMonCommandAck> m)
 {
   const auto tid = m->get_tid();
-  if (auto found = mon_commands.find(tid);
+  if (auto found = std::find_if(mon_commands.begin(),
+                                mon_commands.end(),
+                                [tid](auto& cmd) {
+                                  return cmd.req->get_tid() == tid;
+                                });
       found != mon_commands.end()) {
-    auto& command = found->second;
+    auto& command = *found;
     logger().trace("{} {}", __func__, tid);
     command.result.set_value(std::make_tuple(m->r, m->rs, std::move(m->get_data())));
     mon_commands.erase(found);
@@ -1005,10 +1009,9 @@ Client::run_command(std::string&& cmd,
   m->set_tid(tid);
   m->cmd = {std::move(cmd)};
   m->set_data(std::move(bl));
-  [[maybe_unused]] auto [command, added] =
-    mon_commands.try_emplace(tid, m);
-  assert(added);
-  return send_message(m).then([&result=command->second.result] {
+  mon_commands.emplace_back(m);
+  auto& command = mon_commands.back();
+  return send_message(command.req).then([&result=command.result] {
     return result.get_future();
   });
 }
@@ -1037,8 +1040,8 @@ seastar::future<> Client::on_session_opened()
     return seastar::now();
   }).then([this] {
     return seastar::parallel_for_each(mon_commands,
-      [this](auto &tid_command) {
-      return send_message(tid_command.second.req);
+      [this](auto &command) {
+      return send_message(command.req);
     });
   });
 }
index 335f76bf0a98832f78cec964532111cb76205588..f6bb75da3aa135cfd8cc7c1db9063efc387185b0 100644 (file)
@@ -4,6 +4,7 @@
 #pragma once
 
 #include <memory>
+#include <vector>
 
 #include <seastar/core/future.hh>
 #include <seastar/core/gate.hh>
@@ -73,7 +74,7 @@ class Client : public crimson::net::Dispatcher,
     typename command_result_t::promise_type result;
     mon_command_t(ceph::ref_t<MMonCommand> req);
   };
-  std::map<ceph_tid_t, mon_command_t> mon_commands;
+  std::vector<mon_command_t> mon_commands;
 
   MonSub sub;