]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / tools / rbd_mirror / image_replayer / snapshot / Replayer.cc
index ce803ed2203d78c762ce1ba0938dd5b70819b1b7..3561f6fc699419ddb9b229e63e568f53066615b3 100644 (file)
@@ -4,6 +4,8 @@
 #include "Replayer.h"
 #include "common/debug.h"
 #include "common/errno.h"
+#include "common/perf_counters.h"
+#include "common/perf_counters_key.h"
 #include "include/stringify.h"
 #include "common/Timer.h"
 #include "cls/rbd/cls_rbd_client.h"
@@ -58,7 +60,7 @@ std::pair<uint64_t, librbd::SnapInfo*> get_newest_mirror_snapshot(
   for (auto snap_info_it = image_ctx->snap_info.rbegin();
        snap_info_it != image_ctx->snap_info.rend(); ++snap_info_it) {
     const auto& snap_ns = snap_info_it->second.snap_namespace;
-    auto mirror_ns = boost::get<
+    auto mirror_ns = std::get_if<
       cls::rbd::MirrorSnapshotNamespace>(&snap_ns);
     if (mirror_ns == nullptr || !mirror_ns->complete) {
       continue;
@@ -254,6 +256,10 @@ bool Replayer<I>::get_replay_status(std::string* description,
   json_spirit::mObject root_obj;
   root_obj["replay_state"] = replay_state;
   root_obj["remote_snapshot_timestamp"] = remote_snap_info->timestamp.sec();
+  if (m_perf_counters) {
+    m_perf_counters->tset(l_rbd_mirror_snapshot_remote_timestamp,
+                          remote_snap_info->timestamp);
+  }
 
   auto matching_remote_snap_id = util::compute_remote_snap_id(
     m_state_builder->local_image_ctx->image_lock,
@@ -269,6 +275,10 @@ bool Replayer<I>::get_replay_status(std::string* description,
     // synced and not the consistency point in time.
     root_obj["local_snapshot_timestamp"] =
       matching_remote_snap_it->second.timestamp.sec();
+    if (m_perf_counters) {
+      m_perf_counters->tset(l_rbd_mirror_snapshot_local_timestamp,
+                            matching_remote_snap_it->second.timestamp);
+    }
   }
 
   matching_remote_snap_it = m_state_builder->remote_image_ctx->snap_info.find(
@@ -456,7 +466,7 @@ void Replayer<I>::scan_local_mirror_snapshots(
   for (auto snap_info_it = local_image_ctx->snap_info.begin();
        snap_info_it != local_image_ctx->snap_info.end(); ++snap_info_it) {
     const auto& snap_ns = snap_info_it->second.snap_namespace;
-    auto mirror_ns = boost::get<
+    auto mirror_ns = std::get_if<
       cls::rbd::MirrorSnapshotNamespace>(&snap_ns);
     if (mirror_ns == nullptr) {
       continue;
@@ -576,7 +586,7 @@ void Replayer<I>::scan_remote_mirror_snapshots(
   for (auto snap_info_it = remote_image_ctx->snap_info.begin();
        snap_info_it != remote_image_ctx->snap_info.end(); ++snap_info_it) {
     const auto& snap_ns = snap_info_it->second.snap_namespace;
-    auto mirror_ns = boost::get<
+    auto mirror_ns = std::get_if<
       cls::rbd::MirrorSnapshotNamespace>(&snap_ns);
     if (mirror_ns == nullptr) {
       continue;
@@ -768,8 +778,8 @@ void Replayer<I>::prune_non_primary_snapshot(uint64_t snap_id) {
       snap_namespace = snap_info->snap_namespace;
       snap_name = snap_info->name;
 
-      ceph_assert(boost::get<cls::rbd::MirrorSnapshotNamespace>(
-        &snap_namespace) != nullptr);
+      ceph_assert(std::holds_alternative<cls::rbd::MirrorSnapshotNamespace>(
+        snap_namespace));
     }
   }
 
@@ -913,7 +923,7 @@ void Replayer<I>::create_non_primary_snapshot() {
       return;
     }
 
-    auto mirror_ns = boost::get<cls::rbd::MirrorSnapshotNamespace>(
+    auto mirror_ns = std::get_if<cls::rbd::MirrorSnapshotNamespace>(
       &local_snap_info_it->second.snap_namespace);
     ceph_assert(mirror_ns != nullptr);
 
@@ -930,8 +940,8 @@ void Replayer<I>::create_non_primary_snapshot() {
 
       // we can ignore all non-user snapshots since image state only includes
       // user snapshots
-      if (boost::get<cls::rbd::UserSnapshotNamespace>(
-            &remote_snap_info.snap_namespace) == nullptr) {
+      if (!std::holds_alternative<cls::rbd::UserSnapshotNamespace>(
+            remote_snap_info.snap_namespace)) {
         continue;
       }
 
@@ -1119,16 +1129,19 @@ void Replayer<I>::handle_copy_image(int r) {
     m_last_snapshot_sync_seconds = duration.sec();
 
     if (g_snapshot_perf_counters) {
-      g_snapshot_perf_counters->inc(l_rbd_mirror_snapshot_replay_bytes,
+      g_snapshot_perf_counters->inc(l_rbd_mirror_snapshot_sync_bytes,
                                     m_snapshot_bytes);
-      g_snapshot_perf_counters->inc(l_rbd_mirror_snapshot_replay_snapshots);
-      g_snapshot_perf_counters->tinc(
-        l_rbd_mirror_snapshot_replay_snapshots_time, duration);
+      g_snapshot_perf_counters->inc(l_rbd_mirror_snapshot_snapshots);
+      g_snapshot_perf_counters->tinc(l_rbd_mirror_snapshot_sync_time,
+                                     duration);
     }
     if (m_perf_counters) {
-      m_perf_counters->inc(l_rbd_mirror_snapshot_replay_bytes, m_snapshot_bytes);
-      m_perf_counters->inc(l_rbd_mirror_snapshot_replay_snapshots);
-      m_perf_counters->tinc(l_rbd_mirror_snapshot_replay_snapshots_time, duration);
+      m_perf_counters->inc(l_rbd_mirror_snapshot_sync_bytes, m_snapshot_bytes);
+      m_perf_counters->inc(l_rbd_mirror_snapshot_snapshots);
+      m_perf_counters->tinc(l_rbd_mirror_snapshot_sync_time, duration);
+      m_perf_counters->tset(l_rbd_mirror_snapshot_last_sync_time, duration);
+      m_perf_counters->set(l_rbd_mirror_snapshot_last_sync_bytes,
+                           m_snapshot_bytes);
     }
   }
 
@@ -1280,7 +1293,7 @@ void Replayer<I>::unlink_peer(uint64_t remote_snap_id) {
     Replayer<I>, &Replayer<I>::handle_unlink_peer>(this);
   auto req = librbd::mirror::snapshot::UnlinkPeerRequest<I>::create(
     m_state_builder->remote_image_ctx, remote_snap_id,
-    m_remote_mirror_peer_uuid, ctx);
+    m_remote_mirror_peer_uuid, false, ctx);
   req->send();
 }
 
@@ -1563,16 +1576,32 @@ void Replayer<I>::register_perf_counters() {
 
   auto cct = static_cast<CephContext *>(m_state_builder->local_image_ctx->cct);
   auto prio = cct->_conf.get_val<int64_t>("rbd_mirror_image_perf_stats_prio");
-  PerfCountersBuilder plb(g_ceph_context,
-                          "rbd_mirror_snapshot_image_" + m_image_spec,
-                          l_rbd_mirror_snapshot_first,
+
+  auto local_image_ctx = m_state_builder->local_image_ctx;
+  std::string labels = ceph::perf_counters::key_create(
+      "rbd_mirror_snapshot_image",
+      {{"pool", local_image_ctx->md_ctx.get_pool_name()},
+       {"namespace", local_image_ctx->md_ctx.get_namespace()},
+       {"image", local_image_ctx->name}});
+
+  PerfCountersBuilder plb(g_ceph_context, labels, l_rbd_mirror_snapshot_first,
                           l_rbd_mirror_snapshot_last);
-  plb.add_u64_counter(l_rbd_mirror_snapshot_replay_snapshots,
-                      "snapshots", "Snapshots", "r", prio);
-  plb.add_time_avg(l_rbd_mirror_snapshot_replay_snapshots_time,
-                   "snapshots_time", "Snapshots time", "rl", prio);
-  plb.add_u64_counter(l_rbd_mirror_snapshot_replay_bytes, "replay_bytes",
-                      "Replayed data", "rb", prio, unit_t(UNIT_BYTES));
+  plb.add_u64_counter(l_rbd_mirror_snapshot_snapshots, "snapshots",
+                      "Number of snapshots synced", nullptr, prio);
+  plb.add_time_avg(l_rbd_mirror_snapshot_sync_time, "sync_time",
+                   "Average sync time", nullptr, prio);
+  plb.add_u64_counter(l_rbd_mirror_snapshot_sync_bytes, "sync_bytes",
+                      "Total bytes synced", nullptr, prio, unit_t(UNIT_BYTES));
+  plb.add_time(l_rbd_mirror_snapshot_remote_timestamp, "remote_timestamp",
+               "Timestamp of the remote snapshot", nullptr, prio);
+  plb.add_time(l_rbd_mirror_snapshot_local_timestamp, "local_timestamp",
+               "Timestamp of the local snapshot", nullptr, prio);
+  plb.add_time(l_rbd_mirror_snapshot_last_sync_time, "last_sync_time",
+               "Time taken to sync the last snapshot", nullptr, prio);
+  plb.add_u64(l_rbd_mirror_snapshot_last_sync_bytes, "last_sync_bytes",
+              "Bytes synced for the last snapshot", nullptr, prio,
+              unit_t(UNIT_BYTES));
+
   m_perf_counters = plb.create_perf_counters();
   g_ceph_context->get_perfcounters_collection()->add(m_perf_counters);
 }