From 149bfc4337d4c3c8d4bf47cfd54bc0454fc7d73c Mon Sep 17 00:00:00 2001 From: Orit Wasserman Date: Thu, 27 Apr 2017 23:13:52 +0300 Subject: [PATCH] rgw: store resharding information in bucket header Signed-off-by: Orit Wasserman --- src/cls/rgw/cls_rgw.cc | 58 ++++++++++++++---------------------- src/cls/rgw/cls_rgw_types.cc | 2 ++ src/cls/rgw/cls_rgw_types.h | 14 +++++++-- 3 files changed, 36 insertions(+), 38 deletions(-) diff --git a/src/cls/rgw/cls_rgw.cc b/src/cls/rgw/cls_rgw.cc index 6149f688cf7e8..ddca884f12521 100644 --- a/src/cls/rgw/cls_rgw.cc +++ b/src/cls/rgw/cls_rgw.cc @@ -3628,21 +3628,17 @@ static int rgw_set_bucket_resharding(cls_method_context_t hctx, bufferlist *in, return -EINVAL; } - bufferlist bl; - ::encode(true, bl); - int ret = cls_cxx_setxattr(hctx, resharding_attr.c_str(), &bl); - if (ret < 0) { - CLS_LOG(0, "ERROR: %s(): cls_cxx_setxattr (attr=%s) returned %d", __func__, resharding_attr.c_str(), ret); - return ret; + struct rgw_bucket_dir_header header; + int rc = read_bucket_header(hctx, &header); + if (rc < 0) { + CLS_LOG(1, "ERROR: %s(): failed to read header\n", __func__); + return rc; } - ret = cls_cxx_write(hctx, 0, op.entry.data.length(), &op.entry.data); - if (ret < 0) { - CLS_LOG(0, "ERROR: %s(): cls_cxx_write returned %d", __func__, ret); - return ret; - } + header.is_resharding = true; + header.new_bucket_instance_id = op.entry.new_bucket_instance_id; - return 0; + return write_bucket_header(hctx, &header); } static int rgw_clear_bucket_resharding(cls_method_context_t hctx, bufferlist *in, bufferlist *out) @@ -3657,21 +3653,16 @@ static int rgw_clear_bucket_resharding(cls_method_context_t hctx, bufferlist *in return -EINVAL; } - bufferlist bl; - ::encode(false, bl); - int ret = cls_cxx_setxattr(hctx, resharding_attr.c_str(), &bl); - if (ret < 0) { - CLS_LOG(0, "ERROR: %s(): cls_cxx_setxattr (attr=%s) returned %d", __func__, resharding_attr.c_str(), ret); - return ret; - } - - ret = cls_cxx_write(hctx, 0, op.entry.data.length(), &op.entry.data); - if (ret < 0) { - CLS_LOG(0, "ERROR: %s(): cls_cxx_write returned %d", __func__, ret); - return ret; + struct rgw_bucket_dir_header header; + int rc = read_bucket_header(hctx, &header); + if (rc < 0) { + CLS_LOG(1, "ERROR: %s(): failed to read header\n", __func__); + return rc; } + header.is_resharding = false; + header.new_bucket_instance_id.clear(); - return 0; + return write_bucket_header(hctx, &header); } static int rgw_get_bucket_resharding(cls_method_context_t hctx, bufferlist *in, bufferlist *out) @@ -3686,20 +3677,15 @@ static int rgw_get_bucket_resharding(cls_method_context_t hctx, bufferlist *in, return -EINVAL; } - bufferlist bl; - int ret = cls_cxx_getxattr(hctx, resharding_attr.c_str(), &bl); - if (ret < 0) { - CLS_LOG(0, "ERROR: %s(): cls_cxx_getxattr (attr=%s) returned %d", __func__, resharding_attr.c_str(), ret); - return ret; + struct rgw_bucket_dir_header header; + int rc = read_bucket_header(hctx, &header); + if (rc < 0) { + CLS_LOG(1, "ERROR: %s(): failed to read header\n", __func__); + return rc; } cls_rgw_get_bucket_resharding_ret op_ret; - try { - ::decode(op_ret.resharding, bl); - } catch (buffer::error& err) { - CLS_LOG(1, "ERROR: cls_rgw_get_bucket_resharding: failed to decode entry\n"); - return -EINVAL; - } + op_ret.resharding = header.is_resharding; ::encode(op_ret, *out); diff --git a/src/cls/rgw/cls_rgw_types.cc b/src/cls/rgw/cls_rgw_types.cc index a1c3524406b9d..c0af4c06a7759 100644 --- a/src/cls/rgw/cls_rgw_types.cc +++ b/src/cls/rgw/cls_rgw_types.cc @@ -517,6 +517,8 @@ void rgw_bucket_dir_header::dump(Formatter *f) const iter->second.dump(f); f->close_section(); } + f->dump_bool("is_resharding", is_resharding); + f->dump_string("new_bucket_instance_id",new_bucket_instance_id); f->close_section(); } diff --git a/src/cls/rgw/cls_rgw_types.h b/src/cls/rgw/cls_rgw_types.h index 090b5ec6228e5..a6eb2ef8e8c12 100644 --- a/src/cls/rgw/cls_rgw_types.h +++ b/src/cls/rgw/cls_rgw_types.h @@ -610,20 +610,24 @@ struct rgw_bucket_dir_header { uint64_t ver; uint64_t master_ver; string max_marker; + bool is_resharding; + string new_bucket_instance_id; rgw_bucket_dir_header() : tag_timeout(0), ver(0), master_ver(0) {} void encode(bufferlist &bl) const { - ENCODE_START(5, 2, bl); + ENCODE_START(6, 2, bl); ::encode(stats, bl); ::encode(tag_timeout, bl); ::encode(ver, bl); ::encode(master_ver, bl); ::encode(max_marker, bl); + ::encode(is_resharding, bl); + ::encode(new_bucket_instance_id, bl); ENCODE_FINISH(bl); } void decode(bufferlist::iterator &bl) { - DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl); + DECODE_START_LEGACY_COMPAT_LEN(6, 2, 2, bl); ::decode(stats, bl); if (struct_v > 2) { ::decode(tag_timeout, bl); @@ -639,6 +643,12 @@ struct rgw_bucket_dir_header { if (struct_v >= 5) { ::decode(max_marker, bl); } + if (struct_v >= 6) { + ::decode(is_resharding, bl); + ::decode(new_bucket_instance_id, bl); + } else { + is_resharding = false; + } DECODE_FINISH(bl); } void dump(Formatter *f) const; -- 2.39.5