From d692da34abe1d369405ebd8a33ac2c20e3e880cc Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Fri, 15 Nov 2013 11:12:03 -0800 Subject: [PATCH] osd/osd_types: add explicit hash to object_locator_t Instead of hashing the object name or key, we allow the hash position to be provided explicitly. Signed-off-by: Sage Weil Signed-off-by: Greg Farnum --- src/osd/osd_types.cc | 20 +++++++++++++++++--- src/osd/osd_types.h | 25 ++++++++++++++++--------- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 05b83c4af21bd..d8458f812946c 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -56,18 +56,24 @@ void osd_reqid_t::generate_test_instances(list& o) void object_locator_t::encode(bufferlist& bl) const { - ENCODE_START(5, 3, bl); + // verify that nobody's corrupted the locator + assert(hash == -1 || key.empty()); + __u8 encode_compat = 3; + ENCODE_START(6, encode_compat, bl); ::encode(pool, bl); int32_t preferred = -1; // tell old code there is no preferred osd (-1). ::encode(preferred, bl); ::encode(key, bl); ::encode(nspace, bl); - ENCODE_FINISH(bl); + ::encode(hash, bl); + if (hash != -1) + encode_compat = MAX(encode_compat, 6); // need to interpret the hash + ENCODE_FINISH_NEW_COMPAT(bl, encode_compat); } void object_locator_t::decode(bufferlist::iterator& p) { - DECODE_START_LEGACY_COMPAT_LEN(5, 3, 3, p); + DECODE_START_LEGACY_COMPAT_LEN(6, 3, 3, p); if (struct_v < 2) { int32_t op; ::decode(op, p); @@ -82,7 +88,13 @@ void object_locator_t::decode(bufferlist::iterator& p) ::decode(key, p); if (struct_v >= 5) ::decode(nspace, p); + if (struct_v >= 6) + ::decode(hash, p); + else + hash = -1; DECODE_FINISH(p); + // verify that nobody's corrupted the locator + assert(hash == -1 || key.empty()); } void object_locator_t::dump(Formatter *f) const @@ -90,12 +102,14 @@ void object_locator_t::dump(Formatter *f) const f->dump_int("pool", pool); f->dump_string("key", key); f->dump_string("namespace", nspace); + f->dump_int("hash", hash); } void object_locator_t::generate_test_instances(list& o) { o.push_back(new object_locator_t); o.push_back(new object_locator_t(123)); + o.push_back(new object_locator_t(123, 876)); o.push_back(new object_locator_t(1, "n2")); o.push_back(new object_locator_t(1234, "", "key")); o.push_back(new object_locator_t(12, "n1", "key2")); diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 982ec6d3cc00f..a284ed6160cea 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -87,20 +87,26 @@ namespace __gnu_cxx { // a locator constrains the placement of an object. mainly, which pool // does it go in. struct object_locator_t { - int64_t pool; - string key; - string nspace; + // You specify either the hash or the key -- not both + int64_t pool; ///< pool id + string key; ///< key string (if non-empty) + string nspace; ///< namespace + int64_t hash; ///< hash position (if >= 0) explicit object_locator_t() - : pool(-1) {} + : pool(-1), hash(-1) {} explicit object_locator_t(int64_t po) - : pool(po) {} + : pool(po), hash(-1) {} + explicit object_locator_t(int64_t po, int64_t ps) + : pool(po), hash(ps) {} explicit object_locator_t(int64_t po, string ns) - : pool(po), nspace(ns) {} + : pool(po), nspace(ns), hash(-1) {} + explicit object_locator_t(int64_t po, string ns, int64_t ps) + : pool(po), nspace(ns), hash(ps) {} explicit object_locator_t(int64_t po, string ns, string s) - : pool(po), key(s), nspace(ns) {} + : pool(po), key(s), nspace(ns), hash(-1) {} explicit object_locator_t(const hobject_t& soid) - : pool(soid.pool), key(soid.get_key()), nspace(soid.nspace) {} + : pool(soid.pool), key(soid.get_key()), nspace(soid.nspace), hash(-1) {} int64_t get_pool() const { return pool; @@ -110,6 +116,7 @@ struct object_locator_t { pool = -1; key = ""; nspace = ""; + hash = -1; } bool empty() const { @@ -124,7 +131,7 @@ struct object_locator_t { WRITE_CLASS_ENCODER(object_locator_t) inline bool operator==(const object_locator_t& l, const object_locator_t& r) { - return l.pool == r.pool && l.key == r.key && l.nspace == r.nspace; + return l.pool == r.pool && l.key == r.key && l.nspace == r.nspace && l.hash == r.hash; } inline bool operator!=(const object_locator_t& l, const object_locator_t& r) { return !(l == r); -- 2.39.5