]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
object.h: Sort hobject_t by nibble reversed hash
authorSamuel Just <samuel.just@dreamhost.com>
Wed, 30 Nov 2011 18:38:09 +0000 (10:38 -0800)
committerSamuel Just <samuel.just@dreamhost.com>
Wed, 7 Dec 2011 19:40:10 +0000 (11:40 -0800)
To match the HashIndex ordering, we need to sort hobject_t by the nibble
reversed hash.  We store objects in the filestore in a directory tree
with the least significant nibble at the top and the most at the bottom
to facilitate pg splitting in the future.

Signed-off-by: Samuel Just <samuel.just@dreamhost.com>
src/include/object.h

index c7884711e6e26e2ac7a0f78255bd8b2ab1f415e3..be27b8b42ed980f89a8c854d6cfb58f299558f6b 100644 (file)
@@ -259,6 +259,7 @@ namespace __gnu_cxx {
   };
 }
 
+typedef uint32_t filestore_hobject_key_t;
 struct hobject_t {
   object_t oid;
   snapid_t snap;
@@ -289,6 +290,15 @@ public:
     return h;
   }
 
+  filestore_hobject_key_t get_filestore_key() const {
+    uint32_t retval = hash;
+    // reverse nibbles
+    retval = ((retval & 0x0f0f0f0f) << 4) | ((retval & 0xf0f0f0f0) >> 4);
+    retval = ((retval & 0x00ff00ff) << 8) | ((retval & 0xff00ff00) >> 8);
+    retval = ((retval & 0x0000ffff) << 16) | ((retval & 0xffff0000) >> 16);
+    return retval;
+  }
+
   /* Do not use when a particular hash function is needed */
   explicit hobject_t(const sobject_t &o) :
     oid(o.oid), snap(o.snap) {
@@ -341,7 +351,7 @@ namespace __gnu_cxx {
   };
 }
 
-// sort hobject_t's by <hash,name,snapid>
+// sort hobject_t's by <get_filestore_key,name,snapid>
 inline bool operator==(const hobject_t &l, const hobject_t &r) {
   return l.oid == r.oid && l.snap == r.snap && l.hash == r.hash && l.max == r.max;
 }
@@ -350,26 +360,26 @@ inline bool operator!=(const hobject_t &l, const hobject_t &r) {
 }
 inline bool operator>(const hobject_t &l, const hobject_t &r) {
   return l.max > r.max ||
-    (l.max == r.max && (l.hash > r.hash ||
-                       (l.hash == r.hash && (l.oid > r.oid || 
+    (l.max == r.max && (l.get_filestore_key() > r.get_filestore_key() ||
+                       (l.get_filestore_key() == r.get_filestore_key() && (l.oid > r.oid || 
                                              (l.oid == r.oid && l.snap > r.snap)))));
 }
 inline bool operator<(const hobject_t &l, const hobject_t &r) {
   return l.max < r.max ||
-    (l.max == r.max && (l.hash < r.hash ||
-                       (l.hash == r.hash && (l.oid < r.oid ||
+    (l.max == r.max && (l.get_filestore_key() < r.get_filestore_key() ||
+                       (l.get_filestore_key() == r.get_filestore_key() && (l.oid < r.oid ||
                                              (l.oid == r.oid && l.snap < r.snap)))));
 }
 inline bool operator>=(const hobject_t &l, const hobject_t &r) {
   return l.max > r.max ||
-    (l.max == r.max && (l.hash > r.hash ||
-                       (l.hash == r.hash && (l.oid > r.oid ||
+    (l.max == r.max && (l.get_filestore_key() > r.get_filestore_key() ||
+                       (l.get_filestore_key() == r.get_filestore_key() && (l.oid > r.oid ||
                                              (l.oid == r.oid && l.snap >= r.snap)))));
 }
 inline bool operator<=(const hobject_t &l, const hobject_t &r) {
   return l.max < r.max ||
-    (l.max == r.max && (l.hash < r.hash ||
-                       (l.hash == r.hash && (l.oid < r.oid ||
+    (l.max == r.max && (l.get_filestore_key() < r.get_filestore_key() ||
+                       (l.get_filestore_key() == r.get_filestore_key() && (l.oid < r.oid ||
                                              (l.oid == r.oid && l.snap <= r.snap)))));
 }