]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
PGPool::update: optimize removed_snaps comparison when possible
authorZac Medico <zmedico@gmail.com>
Thu, 31 Aug 2017 20:36:30 +0000 (13:36 -0700)
committerZac Medico <zmedico@gmail.com>
Thu, 6 Sep 2018 21:12:32 +0000 (14:12 -0700)
In self/unmanaged snaps mode, optimize removed_snaps comparison
for cases where removed_snaps has not changed. This exploits the
fact that remove_unmanaged_snap adds a dummy removed snapshot
to the end of removed_snaps, allowing for inexpensive detection
of changes. In cases where removed_snaps is very large, this
optimization improves performance dramatically.

Signed-off-by: Zac Medico <zmedico@gmail.com>
(cherry picked from commit caf6803b13d9dbd4540da366b018d721fcfc371a)

src/osd/PG.cc
src/osd/osd_types.cc
src/osd/osd_types.h

index 1e32d202dae470701816e8ae016ce5cdeb47ba11..4da64a3a0b390ad4bda3be584ab71d132a4028b2 100644 (file)
@@ -237,20 +237,23 @@ void PGPool::update(OSDMapRef map)
   if ((map->get_epoch() != cached_epoch + 1) ||
       (pi->get_snap_epoch() == map->get_epoch())) {
     updated = true;
-    pi->build_removed_snaps(newly_removed_snaps);
-    interval_set<snapid_t> intersection;
-    intersection.intersection_of(newly_removed_snaps, cached_removed_snaps);
-    if (intersection == cached_removed_snaps) {
-        cached_removed_snaps.swap(newly_removed_snaps);
-        newly_removed_snaps = cached_removed_snaps;
-        newly_removed_snaps.subtract(intersection);
-    } else {
-        lgeneric_subdout(cct, osd, 0) << __func__
-          << " cached_removed_snaps shrank from " << cached_removed_snaps
-          << " to " << newly_removed_snaps << dendl;
-        cached_removed_snaps.swap(newly_removed_snaps);
-        newly_removed_snaps.clear();
-    }
+    if (pi->maybe_updated_removed_snaps(cached_removed_snaps)) {
+      pi->build_removed_snaps(newly_removed_snaps);
+      interval_set<snapid_t> intersection;
+      intersection.intersection_of(newly_removed_snaps, cached_removed_snaps);
+      if (intersection == cached_removed_snaps) {
+          cached_removed_snaps.swap(newly_removed_snaps);
+          newly_removed_snaps = cached_removed_snaps;
+          newly_removed_snaps.subtract(intersection);
+      } else {
+          lgeneric_subdout(cct, osd, 0) << __func__
+            << " cached_removed_snaps shrank from " << cached_removed_snaps
+            << " to " << newly_removed_snaps << dendl;
+          cached_removed_snaps.swap(newly_removed_snaps);
+          newly_removed_snaps.clear();
+      }
+    } else
+      newly_removed_snaps.clear();
     snapc = pi->get_snap_context();
   } else {
     /* 1) map->get_epoch() == cached_epoch + 1 &&
index 5fb226221d1289a34696cd019b4bb7a347680444..194b020ff206c2f82683d0faa3df26ecf19ae2c5 100644 (file)
@@ -1312,6 +1312,16 @@ void pg_pool_t::build_removed_snaps(interval_set<snapid_t>& rs) const
   }
 }
 
+bool pg_pool_t::maybe_updated_removed_snaps(const interval_set<snapid_t>& cached) const
+{
+  if (is_unmanaged_snaps_mode()) { // remove_unmanaged_snap increments range_end
+    if (removed_snaps.empty() || cached.empty()) // range_end is undefined
+      return removed_snaps.empty() != cached.empty();
+    return removed_snaps.range_end() != cached.range_end();
+  }
+  return true;
+}
+
 snapid_t pg_pool_t::snap_exists(const char *s) const
 {
   for (map<snapid_t,pool_snap_info_t>::const_iterator p = snaps.begin();
index 254e7b4264f49406a7213cf620c10720c86d2049..58cdfdefbd139ca2c3a95d3073c0cce87518d3ec 100644 (file)
@@ -1567,6 +1567,7 @@ public:
    * explicit removed_snaps set.
    */
   void build_removed_snaps(interval_set<snapid_t>& rs) const;
+  bool maybe_updated_removed_snaps(const interval_set<snapid_t>& cached) const;
   snapid_t snap_exists(const char *s) const;
   void add_snap(const char *n, utime_t stamp);
   void add_unmanaged_snap(uint64_t& snapid);