]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
osd/SnapMapper: include poolid in snap index
authorSage Weil <sage@redhat.com>
Wed, 5 Jun 2019 21:53:25 +0000 (16:53 -0500)
committerSage Weil <sage@redhat.com>
Tue, 2 Jul 2019 13:37:49 +0000 (08:37 -0500)
We want to sort starting with (pool, snapid, ...) so that we align with
the structure of the purged_snaps.  Simply flattening all snaps across
pools is less than ideal because the purge records are intervals (with the
snap in the key the last snap for the interval); flattening means we'd have
to look at many records (across pools) to conclude anything.  Putting
these in the form we really want them simplifies things going forward.

Signed-off-by: Sage Weil <sage@redhat.com>
src/osd/SnapMapper.cc
src/osd/SnapMapper.h

index 1510c5f9a42879ec88cebf7fe4e1c7d1a94400de..e745fff23f6dbc01b9963885483d43f9d0de671b 100644 (file)
@@ -21,7 +21,8 @@
 
 using std::string;
 
-const string SnapMapper::MAPPING_PREFIX = "MAP_";
+const string SnapMapper::LEGACY_MAPPING_PREFIX = "MAP_";
+const string SnapMapper::MAPPING_PREFIX = "SNA_";
 const string SnapMapper::OBJECT_PREFIX = "OBJ_";
 
 /*
@@ -40,6 +41,16 @@ const string SnapMapper::OBJECT_PREFIX = "OBJ_";
   + hobject_t::to_str() ("%llx.%8x.%lx.name...." % pool, hash, snap)
   -> SnapMapping::Mapping { snap, hoid }
 
+  "SNA_"
+  + ("%lld" % poolid)
+  + "_"
+  + ("%016x" % snapid)
+  + "_"
+  + (".%x" % shard_id)
+  + "_"
+  + hobject_t::to_str() ("%llx.%8x.%lx.name...." % pool, hash, snap)
+  -> SnapMapping::Mapping { snap, hoid }
+
   "OBJ_" +
   + (".%x" % shard_id)
   + hobject_t::to_str()
@@ -95,20 +106,31 @@ struct Mapping {
 };
 WRITE_CLASS_ENCODER(Mapping)
 
-string SnapMapper::get_prefix(snapid_t snap)
+string SnapMapper::get_legacy_prefix(snapid_t snap)
+{
+  char buf[100];
+  int len = snprintf(
+    buf, sizeof(buf),
+    "%.*X_",
+    (int)(sizeof(snap)*2), static_cast<unsigned>(snap));
+  return LEGACY_MAPPING_PREFIX + string(buf, len);
+}
+
+string SnapMapper::get_prefix(int64_t pool, snapid_t snap)
 {
   char buf[100];
   int len = snprintf(
     buf, sizeof(buf),
-    "%.*X_", (int)(sizeof(snap)*2),
-    static_cast<unsigned>(snap));
+    "%lld_%.*X_",
+    (long long)pool,
+    (int)(sizeof(snap)*2), static_cast<unsigned>(snap));
   return MAPPING_PREFIX + string(buf, len);
 }
 
 string SnapMapper::to_raw_key(
   const pair<snapid_t, hobject_t> &in)
 {
-  return get_prefix(in.first) + shard_prefix + in.second.to_str();
+  return get_prefix(pool, in.first) + shard_prefix + in.second.to_str();
 }
 
 pair<string, bufferlist> SnapMapper::to_raw(
@@ -322,7 +344,7 @@ int SnapMapper::get_next_objects_to_trim(
   for (set<string>::iterator i = prefixes.begin();
        i != prefixes.end() && out->size() < max && r == 0;
        ++i) {
-    string prefix(get_prefix(snap) + *i);
+    string prefix(get_prefix(pool, snap) + *i);
     string pos = prefix;
     while (out->size() < max) {
       pair<string, bufferlist> next;
index 21157ef2ae1469bcd70a3ee8fd14c386ca59bae8..2a9236c1f90e8e7755defc59e5ea7af1e5cb9ee0 100644 (file)
@@ -85,7 +85,7 @@ public:
  *
  * We accomplish this using two sets of keys:
  *  1) OBJECT_PREFIX + obj.str() -> encoding of object_snaps
- *  2) MAPPING_PREFIX + snapid_t + obj.str() -> encoding of pair<snapid_t, obj>
+ *  2) MAPPING_PREFIX + poolid + snapid_t + obj.str() -> encoding of pair<snapid_t, obj>
  *
  * The on disk strings and encodings are implemented in to_raw, to_raw_key,
  * from_raw, to_object_key.
@@ -114,10 +114,12 @@ public:
 private:
   MapCacher::MapCacher<std::string, bufferlist> backend;
 
+  static const std::string LEGACY_MAPPING_PREFIX;
   static const std::string MAPPING_PREFIX;
   static const std::string OBJECT_PREFIX;
 
-  static std::string get_prefix(snapid_t snap);
+  static std::string get_legacy_prefix(snapid_t snap);
+  static std::string get_prefix(int64_t pool, snapid_t snap);
 
   std::string to_raw_key(
     const std::pair<snapid_t, hobject_t> &to_map);