From 84bea65d3e3b4c5bf04591700f8da8e99e7a1bc2 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 5 Jun 2019 16:53:25 -0500 Subject: [PATCH] osd/SnapMapper: include poolid in snap index We want to sort starting with (pool, snapid, ...) so that we align with the structure of the purged_snaps. Simply flattening all snaps across pools is less than ideal because the purge records are intervals (with the snap in the key the last snap for the interval); flattening means we'd have to look at many records (across pools) to conclude anything. Putting these in the form we really want them simplifies things going forward. Signed-off-by: Sage Weil --- src/osd/SnapMapper.cc | 34 ++++++++++++++++++++++++++++------ src/osd/SnapMapper.h | 6 ++++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/osd/SnapMapper.cc b/src/osd/SnapMapper.cc index 1510c5f9a42..e745fff23f6 100644 --- a/src/osd/SnapMapper.cc +++ b/src/osd/SnapMapper.cc @@ -21,7 +21,8 @@ using std::string; -const string SnapMapper::MAPPING_PREFIX = "MAP_"; +const string SnapMapper::LEGACY_MAPPING_PREFIX = "MAP_"; +const string SnapMapper::MAPPING_PREFIX = "SNA_"; const string SnapMapper::OBJECT_PREFIX = "OBJ_"; /* @@ -40,6 +41,16 @@ const string SnapMapper::OBJECT_PREFIX = "OBJ_"; + hobject_t::to_str() ("%llx.%8x.%lx.name...." % pool, hash, snap) -> SnapMapping::Mapping { snap, hoid } + "SNA_" + + ("%lld" % poolid) + + "_" + + ("%016x" % snapid) + + "_" + + (".%x" % shard_id) + + "_" + + hobject_t::to_str() ("%llx.%8x.%lx.name...." % pool, hash, snap) + -> SnapMapping::Mapping { snap, hoid } + "OBJ_" + + (".%x" % shard_id) + hobject_t::to_str() @@ -95,20 +106,31 @@ struct Mapping { }; WRITE_CLASS_ENCODER(Mapping) -string SnapMapper::get_prefix(snapid_t snap) +string SnapMapper::get_legacy_prefix(snapid_t snap) +{ + char buf[100]; + int len = snprintf( + buf, sizeof(buf), + "%.*X_", + (int)(sizeof(snap)*2), static_cast(snap)); + return LEGACY_MAPPING_PREFIX + string(buf, len); +} + +string SnapMapper::get_prefix(int64_t pool, snapid_t snap) { char buf[100]; int len = snprintf( buf, sizeof(buf), - "%.*X_", (int)(sizeof(snap)*2), - static_cast(snap)); + "%lld_%.*X_", + (long long)pool, + (int)(sizeof(snap)*2), static_cast(snap)); return MAPPING_PREFIX + string(buf, len); } string SnapMapper::to_raw_key( const pair &in) { - return get_prefix(in.first) + shard_prefix + in.second.to_str(); + return get_prefix(pool, in.first) + shard_prefix + in.second.to_str(); } pair SnapMapper::to_raw( @@ -322,7 +344,7 @@ int SnapMapper::get_next_objects_to_trim( for (set::iterator i = prefixes.begin(); i != prefixes.end() && out->size() < max && r == 0; ++i) { - string prefix(get_prefix(snap) + *i); + string prefix(get_prefix(pool, snap) + *i); string pos = prefix; while (out->size() < max) { pair next; diff --git a/src/osd/SnapMapper.h b/src/osd/SnapMapper.h index 21157ef2ae1..2a9236c1f90 100644 --- a/src/osd/SnapMapper.h +++ b/src/osd/SnapMapper.h @@ -85,7 +85,7 @@ public: * * We accomplish this using two sets of keys: * 1) OBJECT_PREFIX + obj.str() -> encoding of object_snaps - * 2) MAPPING_PREFIX + snapid_t + obj.str() -> encoding of pair + * 2) MAPPING_PREFIX + poolid + snapid_t + obj.str() -> encoding of pair * * The on disk strings and encodings are implemented in to_raw, to_raw_key, * from_raw, to_object_key. @@ -114,10 +114,12 @@ public: private: MapCacher::MapCacher backend; + static const std::string LEGACY_MAPPING_PREFIX; static const std::string MAPPING_PREFIX; static const std::string OBJECT_PREFIX; - static std::string get_prefix(snapid_t snap); + static std::string get_legacy_prefix(snapid_t snap); + static std::string get_prefix(int64_t pool, snapid_t snap); std::string to_raw_key( const std::pair &to_map); -- 2.39.5