From e4d4aa8b869b3b0c8b5b08c793a00731808475f9 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Wed, 10 May 2017 09:39:55 -0700 Subject: [PATCH] rgw: a few fixes Signed-off-by: Yehuda Sadeh --- src/common/config_opts.h | 1 + src/rgw/rgw_admin.cc | 23 ++++++++++++++++------- src/rgw/rgw_reshard.cc | 14 +++++++++++--- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 9c0c626ba05..ac95b1540d4 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -1734,3 +1734,4 @@ OPTION(rgw_swift_custom_header, OPT_STR, "") // option to enable swift custom he /* resharding tunables */ OPTION(rgw_reshard_max_jobs, OPT_INT, 1024) +OPTION(rgw_reshard_bucket_lock_duration, OPT_INT, 120) // duration of lock on bucket obj during resharding diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index a5692985dbd..a7abc56142a 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -517,7 +517,6 @@ static int get_cmd(const char *cmd, const char *prev_cmd, const char *prev_prev_ strcmp(cmd, "quota") == 0 || strcmp(cmd, "realm") == 0 || strcmp(cmd, "replicalog") == 0 || - strcmp(cmd, "reshard") == 0 || strcmp(cmd, "role") == 0 || strcmp(cmd, "role-policy") == 0 || strcmp(cmd, "subuser") == 0 || @@ -526,8 +525,13 @@ static int get_cmd(const char *cmd, const char *prev_cmd, const char *prev_prev_ strcmp(cmd, "user") == 0 || strcmp(cmd, "zone") == 0 || strcmp(cmd, "zonegroup") == 0 || - strcmp(cmd, "zonegroups") == 0) -{ + strcmp(cmd, "zonegroups") == 0) { + *need_more = true; + return 0; + } + + if (strcmp(cmd, "reshard") == 0 && + !(prev_cmd && strcmp(prev_cmd, "bucket") == 0)) { *need_more = true; return 0; } @@ -2228,17 +2232,17 @@ int check_reshard_bucket_params(RGWRados *store, { if (bucket_name.empty()) { cerr << "ERROR: bucket not specified" << std::endl; - return EINVAL; + return -EINVAL; } if (!num_shards_specified) { cerr << "ERROR: --num-shards not specified" << std::endl; - return EINVAL; + return -EINVAL; } if (num_shards > (int)store->get_max_bucket_shards()) { cerr << "ERROR: num_shards too high, max value: " << store->get_max_bucket_shards() << std::endl; - return EINVAL; + return -EINVAL; } int ret = init_bucket(tenant, bucket_name, bucket_id, bucket_info, bucket, &attrs); @@ -2252,7 +2256,7 @@ int check_reshard_bucket_params(RGWRados *store, if (num_shards <= num_source_shards && !yes_i_really_mean_it) { cerr << "num shards is less or equal to current shards count" << std::endl << "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl; - return EINVAL; + return -EINVAL; } return 0; } @@ -5546,6 +5550,11 @@ next: RGWBucketReshard br(store, bucket_info, attrs); +#define DEFAULT_RESHARD_MAX_ENTRIES 1000 + if (max_entries < 1) { + max_entries = DEFAULT_RESHARD_MAX_ENTRIES; + } + return br.execute(num_shards, max_entries, verbose, &cout, formatter); } diff --git a/src/rgw/rgw_reshard.cc b/src/rgw/rgw_reshard.cc index 94ef05adf37..6033591bff4 100644 --- a/src/rgw/rgw_reshard.cc +++ b/src/rgw/rgw_reshard.cc @@ -192,12 +192,18 @@ RGWBucketReshard::RGWBucketReshard(RGWRados *_store, const RGWBucketInfo& _bucke reshard_lock(reshard_lock_name) { const rgw_bucket& b = bucket_info.bucket; reshard_oid = b.tenant + (b.tenant.empty() ? "" : ":") + b.name + ":" + b.bucket_id; + + utime_t lock_duration(store->ctx()->_conf->rgw_reshard_bucket_lock_duration, 0); +#define COOKIE_LEN 16 + char cookie_buf[COOKIE_LEN + 1]; + gen_rand_alphanumeric(store->ctx(), cookie_buf, sizeof(cookie_buf) - 1); + + reshard_lock.set_cookie(cookie_buf); + reshard_lock.set_duration(lock_duration); } int RGWBucketReshard::lock_bucket() { -#warning set timeout for guard lock - int ret = reshard_lock.lock_exclusive(&store->reshard_pool_ctx, reshard_oid); if (ret < 0) { ldout(store->ctx(), 0) << "RGWReshard::add failed to acquire lock on " << reshard_oid << " ret=" << ret << dendl; @@ -249,6 +255,8 @@ int RGWBucketReshard::clear_resharding() int RGWBucketReshard::create_new_bucket_instance(int new_num_shards, RGWBucketInfo& new_bucket_info) { + new_bucket_info = bucket_info; + store->create_bucket_id(&new_bucket_info.bucket.bucket_id); new_bucket_info.bucket.oid.clear(); @@ -389,7 +397,7 @@ int RGWBucketReshard::do_reshard( string err; int r = RGWBucketAdminOp::link(store, bucket_op, &err); if (r < 0) { - lderr(store->ctx()) << "failed to link new bucket instance (bucket_id=" << new_bucket_info.bucket.bucket_id << ": " << err << "; " << cpp_strerror(-r) << dendl; + lderr(store->ctx()) << "failed to link new bucket instance (bucket_id=" << new_bucket_info.bucket.bucket_id << ": " << err << "; " << cpp_strerror(-r) << ")" << dendl; return -r; } return 0; -- 2.39.5