rgw: Initialize logs on layout initialization

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
This commit is contained in:
Adam C. Emerson 2021-01-15 18:41:37 -05:00
parent 78ece45796
commit 340a2836a3
3 changed files with 42 additions and 23 deletions

View File

@ -43,6 +43,7 @@
#include "rgw_common.h"
#include "rgw_reshard.h"
#include "rgw_lc.h"
#include "rgw_bucket_layout.h"
// stolen from src/cls/version/cls_version.cc
#define VERSION_ATTR "ceph.objclass.version"
@ -2530,14 +2531,31 @@ int RGWBucketInstanceMetadataHandler::do_put(RGWSI_MetaBackend_Handler::Op *op,
return do_put_operate(&put_op);
}
void init_default_bucket_layout(CephContext *cct, RGWBucketInfo& info, const RGWZone& zone) {
info.layout.current_index.gen = 0;
info.layout.current_index.layout.normal.hash_type = rgw::BucketHashType::Mod;
info.layout.current_index.layout.type = rgw::BucketIndexType::Normal;
void init_default_bucket_layout(CephContext *cct, rgw::BucketLayout& layout,
const RGWZone& zone,
std::optional<uint32_t> shards,
std::optional<rgw::BucketIndexType> type) {
layout.current_index.gen = 0;
layout.current_index.layout.normal.hash_type = rgw::BucketHashType::Mod;
info.layout.current_index.layout.normal.num_shards = (
cct->_conf->rgw_override_bucket_index_max_shards > 0 ?
cct->_conf->rgw_override_bucket_index_max_shards : zone.bucket_index_max_shards);
layout.current_index.layout.type =
type.value_or(rgw::BucketIndexType::Normal);
if (shards) {
layout.current_index.layout.normal.num_shards = *shards;
} else if (cct->_conf->rgw_override_bucket_index_max_shards > 0) {
layout.current_index.layout.normal.num_shards =
cct->_conf->rgw_override_bucket_index_max_shards;
} else {
layout.current_index.layout.normal.num_shards =
zone.bucket_index_max_shards;
}
if (layout.current_index.layout.type == rgw::BucketIndexType::Normal) {
layout.logs.push_back(log_layout_from_index(
layout.current_index.gen,
layout.current_index.layout.normal));
}
}
int RGWMetadataHandlerPut_BucketInstance::put_check()
@ -2550,12 +2568,17 @@ int RGWMetadataHandlerPut_BucketInstance::put_check()
RGWBucketCompleteInfo *old_bci = (orig_obj ? &orig_obj->get_bci() : nullptr);
bool exists = (!!orig_obj);
const bool exists = (!!orig_obj);
if (from_remote_zone) {
// don't sync bucket layout changes
if (!exists) {
init_default_bucket_layout(cct, bci.info, bihandler->svc.zone->get_zone());
auto& bci_index = bci.info.layout.current_index.layout;
auto index_type = bci_index.type;
auto num_shards = bci_index.normal.num_shards;
init_default_bucket_layout(cct, bci.info.layout,
bihandler->svc.zone->get_zone(),
num_shards, index_type);
} else {
bci.info.layout = old_bci->info.layout;
}

View File

@ -57,7 +57,10 @@ extern void rgw_parse_url_bucket(const string& bucket,
// conforms to the type declaration of RGWRados::check_filter_t.
extern bool rgw_bucket_object_check_filter(const string& oid);
extern void init_default_bucket_layout(CephContext *cct, RGWBucketInfo& info, const RGWZone& zone);
void init_default_bucket_layout(CephContext *cct, rgw::BucketLayout& layout,
const RGWZone& zone,
std::optional<uint32_t> shards,
std::optional<rgw::BucketIndexType> type);
struct RGWBucketCompleteInfo {
RGWBucketInfo info;

View File

@ -2238,19 +2238,12 @@ int RGWRados::create_bucket(const RGWUserInfo& owner, rgw_bucket& bucket,
info.placement_rule = selected_placement_rule;
info.swift_ver_location = swift_ver_location;
info.swift_versioning = (!swift_ver_location.empty());
init_default_bucket_layout(cct, info, svc.zone->get_zone());
if (pmaster_num_shards) {
// 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));
}
init_default_bucket_layout(cct, info.layout, svc.zone->get_zone(),
pmaster_num_shards ?
std::optional{*pmaster_num_shards} :
std::nullopt,
rule_info.index_type);
info.requester_pays = false;
if (real_clock::is_zero(creation_time)) {