]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: capture hashing of objects to hash positions/pgs in pg_pool_t
authorSage Weil <sage@inktank.com>
Fri, 11 Oct 2013 22:33:45 +0000 (15:33 -0700)
committerSage Weil <sage@inktank.com>
Fri, 6 Dec 2013 22:37:25 +0000 (14:37 -0800)
The hashing is dependent on pool properties; capture (more of) it in a
method instead of having it in OSDMap.

Signed-off-by: Sage Weil <sage@inktank.com>
Reviewed-by: Greg Farnum <greg@inktank.com>
src/osd/OSDMap.cc
src/osd/osd_types.cc
src/osd/osd_types.h

index e9befa7582f414996d75866bb2fde541579eac00..0204c1211328e8c332210d46dce214ee3012caf2 100644 (file)
@@ -988,13 +988,6 @@ int OSDMap::apply_incremental(const Incremental &inc)
   return 0;
 }
 
-static string make_hash_str(const string &inkey, const string &nspace)
-{
-  if (nspace.empty())
-    return inkey;
-  return nspace + '\037' + inkey;
-}
-
 // mapping
 int OSDMap::object_locator_to_pg(
        const object_t& oid,
@@ -1009,13 +1002,10 @@ int OSDMap::object_locator_to_pg(
   if (loc.hash >= 0) {
     ps = loc.hash;
   } else {
-    string key;
     if (!loc.key.empty())
-      key = make_hash_str(loc.key, loc.nspace);
+      ps = pool->hash_key(loc.key, loc.nspace);
     else
-      key = make_hash_str(oid.name, loc.nspace);
-
-    ps = ceph_str_hash(pool->object_hash, key.c_str(), key.length());
+      ps = pool->hash_key(oid.name, loc.nspace);
   }
   pg = pg_t(ps, loc.get_pool(), -1);
   return 0;
index d8458f812946c859b60204a936720e8928e9e8f1..5c71b75d8e6d08228dae2f476e90548534cadebb 100644 (file)
@@ -827,6 +827,24 @@ SnapContext pg_pool_t::get_snap_context() const
   return SnapContext(get_snap_seq(), s);
 }
 
+static string make_hash_str(const string &inkey, const string &nspace)
+{
+  if (nspace.empty())
+    return inkey;
+  return nspace + '\037' + inkey;
+}
+
+uint32_t pg_pool_t::hash_key(const string& key, const string& ns) const
+{
+  string n = make_hash_str(key, ns);
+  return ceph_str_hash(object_hash, n.c_str(), n.length());
+}
+
+uint32_t pg_pool_t::raw_hash_to_pg(uint32_t v) const
+{
+  return ceph_stable_mod(v, pg_num, pg_num_mask);
+}
+
 /*
  * map a raw pg (with full precision ps) into an actual pg, for storage
  */
index a284ed6160cead2d3da1559f219837c588421e1c..d549278f5756a980b8d421471ba260ae5914aebe 100644 (file)
@@ -911,6 +911,12 @@ public:
 
   SnapContext get_snap_context() const;
 
+  /// hash a object name+namespace key to a hash position
+  uint32_t hash_key(const string& key, const string& ns) const;
+
+  /// round a hash position down to a pg num
+  uint32_t raw_hash_to_pg(uint32_t v) const;
+
   /*
    * map a raw pg (with full precision ps) into an actual pg, for storage
    */