From: Shilpa Jagannath Date: Tue, 4 Aug 2020 12:00:41 +0000 (+0530) Subject: rgw: add bucket index log layout structure X-Git-Tag: v16.1.0~545^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=077760563f4eb0624d4e26da7bb0c1b3a7b508c5;p=ceph.git rgw: add bucket index log layout structure Signed-off-by: Shilpa Jagannath Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_bucket_layout.cc b/src/rgw/rgw_bucket_layout.cc index 942d113c35b..85002ba9cb7 100644 --- a/src/rgw/rgw_bucket_layout.cc +++ b/src/rgw/rgw_bucket_layout.cc @@ -74,20 +74,85 @@ void decode(bucket_index_layout_generation& l, bufferlist::const_iterator& bl) DECODE_FINISH(bl); } -void encode(const BucketLayout& l, bufferlist& bl, uint64_t f) +void encode(const bucket_index_log_layout& l, bufferlist& bl, uint64_t f) +{ + ENCODE_START(1, 1, bl); + encode(l.gen, bl); + encode(l.layout, bl); + ENCODE_FINISH(bl); +} +void decode(bucket_index_log_layout& l, bufferlist::const_iterator& bl) +{ + DECODE_START(1, bl); + decode(l.gen, bl); + decode(l.layout, bl); + DECODE_FINISH(bl); +} + +void encode(const bucket_log_layout& l, bufferlist& bl, uint64_t f) +{ + ENCODE_START(1, 1, bl); + encode(l.type, bl); + switch (l.type) { + case BucketLogType::InIndex: + encode(l.in_index, bl); + break; + } + ENCODE_FINISH(bl); +} +void decode(bucket_log_layout& l, bufferlist::const_iterator& bl) +{ + DECODE_START(1, bl); + decode(l.type, bl); + switch (l.type) { + case BucketLogType::InIndex: + decode(l.in_index, bl); + break; + } + DECODE_FINISH(bl); +} + +void encode(const bucket_log_layout_generation& l, bufferlist& bl, uint64_t f) { ENCODE_START(1, 1, bl); + encode(l.gen, bl); + encode(l.layout, bl); + ENCODE_FINISH(bl); +} +void decode(bucket_log_layout_generation& l, bufferlist::const_iterator& bl) +{ + DECODE_START(1, bl); + decode(l.gen, bl); + decode(l.layout, bl); + DECODE_FINISH(bl); +} + +void encode(const BucketLayout& l, bufferlist& bl, uint64_t f) +{ + ENCODE_START(2, 1, bl); encode(l.resharding, bl); encode(l.current_index, bl); encode(l.target_index, bl); + encode(l.logs, bl); ENCODE_FINISH(bl); } void decode(BucketLayout& l, bufferlist::const_iterator& bl) { - DECODE_START(1, bl); + DECODE_START(2, bl); decode(l.resharding, bl); decode(l.current_index, bl); decode(l.target_index, bl); + if (struct_v < 2) { + l.logs.clear(); + // initialize the log layout to match the current index layout + if (l.current_index.layout.type == BucketIndexType::Normal) { + const auto gen = l.current_index.gen; + const auto& index = l.current_index.layout.normal; + l.logs.push_back(log_layout_from_index(gen, index)); + } + } else { + decode(l.logs, bl); + } DECODE_FINISH(bl); } diff --git a/src/rgw/rgw_bucket_layout.h b/src/rgw/rgw_bucket_layout.h index cb84bd18442..a09215abc88 100644 --- a/src/rgw/rgw_bucket_layout.h +++ b/src/rgw/rgw_bucket_layout.h @@ -72,6 +72,54 @@ void encode(const bucket_index_layout_generation& l, bufferlist& bl, uint64_t f= void decode(bucket_index_layout_generation& l, bufferlist::const_iterator& bl); +enum class BucketLogType : uint8_t { + // colocated with bucket index, so the log layout matches the index layout + InIndex, +}; + +inline std::ostream& operator<<(std::ostream& out, const BucketLogType &log_type) +{ + switch (log_type) { + case BucketLogType::InIndex: + return out << "InIndex"; + default: + return out << "Unknown"; + } +} + +struct bucket_index_log_layout { + uint64_t gen = 0; + bucket_index_normal_layout layout; +}; + +void encode(const bucket_index_log_layout& l, bufferlist& bl, uint64_t f=0); +void decode(bucket_index_log_layout& l, bufferlist::const_iterator& bl); + +struct bucket_log_layout { + BucketLogType type = BucketLogType::InIndex; + + bucket_index_log_layout in_index; +}; + +void encode(const bucket_log_layout& l, bufferlist& bl, uint64_t f=0); +void decode(bucket_log_layout& l, bufferlist::const_iterator& bl); + + +struct bucket_log_layout_generation { + uint64_t gen = 0; + bucket_log_layout layout; +}; + +void encode(const bucket_log_layout_generation& l, bufferlist& bl, uint64_t f=0); +void decode(bucket_log_layout_generation& l, bufferlist::const_iterator& bl); + +// return a log layout that shares its layout with the index +inline bucket_log_layout_generation log_layout_from_index( + uint64_t gen, const bucket_index_normal_layout& index) +{ + return {gen, {BucketLogType::InIndex, {gen, index}}}; +} + enum class BucketReshardState : uint8_t { None, InProgress, @@ -86,6 +134,10 @@ struct BucketLayout { // target index layout of a resharding operation std::optional target_index; + + // history of untrimmed bucket log layout generations, with the current + // generation at the back() + std::vector logs; }; void encode(const BucketLayout& l, bufferlist& bl, uint64_t f=0); diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index dcef286757c..0d68608ecb6 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -2242,7 +2242,15 @@ int RGWRados::create_bucket(const RGWUserInfo& owner, rgw_bucket& bucket, // TODO: remove this once sync doesn't require the same shard count info.layout.current_index.layout.normal.num_shards = *pmaster_num_shards; } + info.layout.current_index.layout.normal.hash_type = rgw::BucketHashType::Mod; info.layout.current_index.layout.type = rule_info.index_type; + if (info.layout.current_index.layout.type == rgw::BucketIndexType::Normal) { + // use the same index layout for the bilog + const auto gen = info.layout.current_index.gen; + const auto& index = info.layout.current_index.layout.normal; + info.layout.logs.push_back(rgw::log_layout_from_index(gen, index)); + } + info.requester_pays = false; if (real_clock::is_zero(creation_time)) { info.creation_time = ceph::real_clock::now();