]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/onode-staged-tree: convert hash to the reversed version
authorYingxin Cheng <yingxin.cheng@intel.com>
Wed, 22 Sep 2021 07:36:22 +0000 (15:36 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Wed, 22 Sep 2021 07:55:09 +0000 (15:55 +0800)
Store the reversed version of object hash to make sure that onodes in
the same PG are sorted together.

Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
src/common/hobject.h
src/crimson/os/seastore/onode_manager/staged-fltree/stages/key_layout.h

index 2fe722661c61f41a01151baabd48a43c2fcb442a..ef27e6f580ce6680f80f8fd33207e1759ef8e626 100644 (file)
@@ -146,6 +146,13 @@ public:
     build_hash_cache();
   }
 
+  // used by Crimson
+  hobject_t(const std::string &key, snapid_t snap, uint32_t reversed_hash,
+            int64_t pool, const std::string& nspace)
+    : oid(key), snap(snap), max(false), pool(pool), nspace(nspace) {
+    set_bitwise_key_u32(reversed_hash);
+  }
+
   /// @return min hobject_t ret s.t. ret.hash == this->hash
   hobject_t get_boundary() const {
     if (is_max())
@@ -397,10 +404,11 @@ public:
       shard_id(shard),
       max(false) {}
 
-  ghobject_t(shard_id_t shard, int64_t pool, uint32_t hash,
+  // used by Crimson
+  ghobject_t(shard_id_t shard, int64_t pool, uint32_t reversed_hash,
              const std::string& nspace, const std::string& oid,
              snapid_t snap, gen_t gen)
-    : hobj(object_t(oid), "", snap, hash, pool, nspace),
+    : hobj(oid, snap, reversed_hash, pool, nspace),
       generation(gen),
       shard_id(shard),
       max(false) {}
index c74438303503543fcbd1c40ed5a64796f732704f..82dec5c0634881bf9796295910b201d6bdd0f65e 100644 (file)
@@ -16,12 +16,13 @@ namespace crimson::os::seastore::onode {
 
 using shard_t = int8_t;
 using pool_t = int64_t;
+// Note: this is the reversed version of the object hash
 using crush_hash_t = uint32_t;
 using snap_t = uint64_t;
 using gen_t = uint64_t;
 static_assert(sizeof(shard_t) == sizeof(ghobject_t().shard_id.id));
 static_assert(sizeof(pool_t) == sizeof(ghobject_t().hobj.pool));
-static_assert(sizeof(crush_hash_t) == sizeof(ghobject_t().hobj.get_hash()));
+static_assert(sizeof(crush_hash_t) == sizeof(ghobject_t().hobj.get_bitwise_key_u32()));
 static_assert(sizeof(snap_t) == sizeof(ghobject_t().hobj.snap.val));
 static_assert(sizeof(gen_t) == sizeof(ghobject_t().generation));
 
@@ -78,6 +79,7 @@ inline MatchKindCMP compare_to(const shard_pool_t& l, const shard_pool_t& r) {
   return toMatchKindCMP(l.pool, r.pool);
 }
 
+// Note: this is the reversed version of the object hash
 struct crush_t {
   bool operator==(const crush_t& x) const { return crush == x.crush; }
   bool operator!=(const crush_t& x) const { return !(*this == x); }
@@ -486,8 +488,10 @@ inline const ghobject_t _MIN_OID() {
  * ghobject_t::get_max() if necessary.
  */
 inline const ghobject_t _MAX_OID() {
-  return ghobject_t(shard_id_t(MAX_SHARD), MAX_POOL, MAX_CRUSH,
-                    "MAX", "MAX", MAX_SNAP, MAX_GEN);
+  auto ret = ghobject_t(shard_id_t(MAX_SHARD), MAX_POOL, MAX_CRUSH,
+                        "MAX", "MAX", MAX_SNAP, MAX_GEN);
+  assert(ret.hobj.get_hash() == ret.hobj.get_bitwise_key_u32());
+  return ret;
 }
 
 // the valid key stored in tree should be in the range of (_MIN_OID, _MAX_OID)
@@ -523,7 +527,8 @@ class key_hobj_t {
     return ghobj.hobj.pool;
   }
   crush_hash_t crush() const {
-    return ghobj.hobj.get_hash();
+    // Note: this is the reversed version of the object hash
+    return ghobj.hobj.get_bitwise_key_u32();
   }
   laddr_t get_hint() const {
     return get_lba_hint(shard(), pool(), crush());
@@ -575,6 +580,7 @@ class key_hobj_t {
     ceph::decode(shard, delta);
     pool_t pool;
     ceph::decode(pool, delta);
+    // Note: this is the reversed version of the object hash
     crush_hash_t crush;
     ceph::decode(crush, delta);
     std::string nspace;