]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
ceph nvmeof monitor
authorAlexander Indenbaum <aindenba@redhat.com>
Sun, 21 Apr 2024 14:00:22 +0000 (14:00 +0000)
committerAlexander Indenbaum <aindenba@redhat.com>
Thu, 20 Nov 2025 08:55:27 +0000 (10:55 +0200)
Resolves: rhbz#2277099

- src/messages/MNVMeofGwMap.h: add version

Signed-off-by: Alexander Indenbaum <aindenba@redhat.com>
  (cherry picked from commit 30bf8407498237eac8259f97b624ad3e92ac5f8d)

- NVMeofGwMonitorClient: implement monitor disconnect panic

Signed-off-by: Alexander Indenbaum <aindenba@redhat.com>
  (cherry picked from commit 84ea2a9399c3a51a9f7763a1b5255a82948386a5)

Signed-off-by: Alexander Indenbaum <aindenba@redhat.com>
(cherry picked from commit 29299a83a4f4b79a83cc1187e32d40ce79f2bb9a)
Signed-off-by: Alexander Indenbaum <aindenba@redhat.com>
src/messages/MNVMeofGwMap.h
src/nvmeof/NVMeofGwMonitorClient.cc
src/nvmeof/NVMeofGwMonitorClient.h

index add2554b137f90d30e856d6eabe0a04e660da73d..f2f6bc9c6df48d542c9b2ea5d0c5d00aa7e206e3 100644 (file)
@@ -19,6 +19,9 @@
 #include "mon/NVMeofGwMap.h"
 
 class MNVMeofGwMap final : public Message {
+private:
+  static constexpr int VERSION = 1;
+
 protected:
   std::map<NvmeGroupKey, NvmeGwMap> map;
   epoch_t                           gwmap_epoch;
@@ -42,11 +45,15 @@ public:
 
   void decode_payload() override {
     auto p = payload.cbegin();
+    int version;
+    decode(version, p);
+    ceph_assert(version == VERSION);
     decode(gwmap_epoch, p);
     decode(map, p);
   }
   void encode_payload(uint64_t features) override {
     using ceph::encode;
+    encode(VERSION, payload);
     encode(gwmap_epoch, payload);
     encode(map, payload);
   }
index 1893baaaf53d3f431acac7148304c9198f49e749..ed510a9ef3166e85829f82377e29be36e2a45ff6 100644 (file)
@@ -38,6 +38,7 @@ NVMeofGwMonitorClient::NVMeofGwMonitorClient(int argc, const char **argv) :
   Dispatcher(g_ceph_context),
   osdmap_epoch(0),
   gwmap_epoch(0),
+  last_map_time(std::chrono::steady_clock::now()),
   monc{g_ceph_context, poolctx},
   client_messenger(Messenger::create(g_ceph_context, "async", entity_name_t::CLIENT(-1), "client", getpid())),
   objecter{g_ceph_context, client_messenger.get(), &monc, poolctx},
@@ -232,9 +233,22 @@ void NVMeofGwMonitorClient::send_beacon()
   monc.send_mon_message(std::move(m));
 }
 
+void NVMeofGwMonitorClient::disconnect_panic()
+{
+  auto disconnect_panic_duration = g_conf().get_val<std::chrono::seconds>("mon_nvmeofgw_beacon_grace").count();
+  auto now = std::chrono::steady_clock::now();
+  auto elapsed_seconds = std::chrono::duration_cast<std::chrono::seconds>(now - last_map_time).count();
+  if (elapsed_seconds > disconnect_panic_duration) {
+    dout(4) << "Triggering a panic upon disconnection from the monitor, elapsed " << elapsed_seconds << ", configured disconnect panic duration " << disconnect_panic_duration << dendl;
+    throw std::runtime_error("Lost connection to the monitor (mon).");
+  }
+}
+
 void NVMeofGwMonitorClient::tick()
 {
   dout(0) << dendl;
+
+  disconnect_panic();
   send_beacon();
 
   timer.add_event_after(
@@ -270,6 +284,8 @@ void NVMeofGwMonitorClient::shutdown()
 
 void NVMeofGwMonitorClient::handle_nvmeof_gw_map(ceph::ref_t<MNVMeofGwMap> nmap)
 {
+  last_map_time = std::chrono::steady_clock::now(); // record time of last monitor message
+
   auto &new_map = nmap->get_map();
   gwmap_epoch = nmap->get_gwmap_epoch();
   auto group_key = std::make_pair(pool, group);
index 1c4c58f5d2f058655b2c3d25f7b3d973a6596927..c9a2b4d164a0ddaa64c7b3a627cbb38b5574994c 100644 (file)
@@ -38,7 +38,9 @@ private:
   std::string server_cert;
   std::string client_cert;
   epoch_t     osdmap_epoch; // last awaited osdmap_epoch
-  epoch_t     gwmap_epoch; // last received gw map epoch
+  epoch_t     gwmap_epoch;  // last received gw map epoch
+  std::chrono::time_point<std::chrono::steady_clock>
+              last_map_time; // used to panic on disconnect
 
 protected:
   ceph::async::io_context_pool poolctx;
@@ -75,6 +77,7 @@ public:
   void shutdown();
   int main(std::vector<const char *> args);
   void tick();
+  void disconnect_panic();
 
   void handle_nvmeof_gw_map(ceph::ref_t<MNVMeofGwMap> m);
 };