diff options
author | Sage Weil <sage@inktank.com> | 2013-10-11 15:33:45 -0700 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-10-22 13:45:39 -0700 |
commit | b2ae146af183849a80601429255359a95229fc9a (patch) | |
tree | 95b9da9694911ac88234b4e8379952109d043265 | |
parent | fc3706e0f4279e2512d14776fcab3e089cd8e27a (diff) | |
download | ceph-b2ae146af183849a80601429255359a95229fc9a.tar.gz |
osd: capture hashing of objects to hash positions/pgs in pg_pool_t
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>
-rw-r--r-- | src/osd/OSDMap.cc | 14 | ||||
-rw-r--r-- | src/osd/osd_types.cc | 18 | ||||
-rw-r--r-- | src/osd/osd_types.h | 6 |
3 files changed, 26 insertions, 12 deletions
diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index e9befa7582f..0204c121132 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -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; diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 715fc70def1..fc22b068649 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -820,6 +820,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 */ diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 99b7e6f0d37..cf46e3915b1 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -930,6 +930,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 */ |