librbd: only use snapshot namespace type in unique key sort
authorJason Dillaman <dillaman@redhat.com>
Fri, 7 Feb 2020 18:30:00 +0000 (13:30 -0500)
committerJason Dillaman <dillaman@redhat.com>
Wed, 19 Feb 2020 15:36:40 +0000 (10:36 -0500)
Don't use the internal snapshot namespace comparator since for
the mirror snapshot the data can change. The important fact is
that snapshot names should be unique within the namespace type.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/ImageCtx.h
src/test/librbd/mock/MockImageCtx.h

index 53d14452043b9439729a2c6bd64b36d89dc21c07..e9132025d0fae0cdf79674919b7f56a719605042 100644 (file)
@@ -69,6 +69,17 @@ namespace librbd {
   }
 
   struct ImageCtx {
+    typedef std::pair<cls::rbd::SnapshotNamespace, std::string> SnapKey;
+    struct SnapKeyComparator {
+      inline bool operator()(const SnapKey& lhs, const SnapKey& rhs) const {
+        // only compare by namespace type and name
+        if (lhs.first.which() != rhs.first.which()) {
+          return lhs.first.which() < rhs.first.which();
+        }
+        return lhs.second < rhs.second;
+      }
+    };
+
     static const string METADATA_CONF_PREFIX;
 
     CephContext *cct;
@@ -81,7 +92,7 @@ namespace librbd {
     std::vector<librados::snap_t> snaps; // this mirrors snapc.snaps, but is in
                                         // a format librados can understand
     std::map<librados::snap_t, SnapInfo> snap_info;
-    std::map<std::pair<cls::rbd::SnapshotNamespace, std::string>, librados::snap_t> snap_ids;
+    std::map<SnapKey, librados::snap_t, SnapKeyComparator> snap_ids;
     uint64_t open_snap_id = CEPH_NOSNAP;
     uint64_t snap_id;
     bool snap_exists; // false if our snap_id was deleted
index 0e7616227134bc75f607d500a8ff70c4586c5458..870bbe08dcc8d018f202151c8b7d0a21af3860a7 100644 (file)
@@ -230,7 +230,7 @@ struct MockImageCtx {
   ::SnapContext snapc;
   std::vector<librados::snap_t> snaps;
   std::map<librados::snap_t, SnapInfo> snap_info;
-  std::map<std::pair<cls::rbd::SnapshotNamespace, std::string>, librados::snap_t> snap_ids;
+  std::map<ImageCtx::SnapKey, librados::snap_t, ImageCtx::SnapKeyComparator> snap_ids;
 
   bool old_format;
   bool read_only;