From a07e8eb6af2dcd670f3175cf7e32befec3783924 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Thu, 4 May 2017 15:11:09 -0700 Subject: [PATCH] cls/rgw: adjust types and ops - don't keep data bufferlist in struct cls_rgw_bucket_instance_entry - remove rgw_get_bucket_instance We need to keep the reshard info as part of the bucket index header (for each source bucket shard), and not in a separate object. Otherwise it'll be impossible to have the resharding check atomic as part of the regular bucket index updates. Signed-off-by: Yehuda Sadeh --- src/cls/rgw/cls_rgw.cc | 11 ++---- src/cls/rgw/cls_rgw_client.cc | 9 ++--- src/cls/rgw/cls_rgw_client.h | 5 +-- src/cls/rgw/cls_rgw_ops.cc | 2 - src/cls/rgw/cls_rgw_ops.h | 13 ++---- src/cls/rgw/cls_rgw_types.cc | 4 +- src/cls/rgw/cls_rgw_types.h | 74 +++++++++++++++++++---------------- 7 files changed, 54 insertions(+), 64 deletions(-) diff --git a/src/cls/rgw/cls_rgw.cc b/src/cls/rgw/cls_rgw.cc index e8d59424288..f25bbe5fe1d 100644 --- a/src/cls/rgw/cls_rgw.cc +++ b/src/cls/rgw/cls_rgw.cc @@ -3618,8 +3618,6 @@ static int rgw_reshard_remove(cls_method_context_t hctx, bufferlist *in, bufferl return ret; } -const string resharding_attr = "resharding"; - static int rgw_set_bucket_resharding(cls_method_context_t hctx, bufferlist *in, bufferlist *out) { cls_rgw_set_bucket_resharding_op op; @@ -3639,8 +3637,7 @@ static int rgw_set_bucket_resharding(cls_method_context_t hctx, bufferlist *in, return rc; } - header.is_resharding = true; - header.new_bucket_instance_id = op.entry.new_bucket_instance_id; + header.new_instance.set(op.entry.new_bucket_instance_id); return write_bucket_header(hctx, &header); } @@ -3663,8 +3660,7 @@ static int rgw_clear_bucket_resharding(cls_method_context_t hctx, bufferlist *in CLS_LOG(1, "ERROR: %s(): failed to read header\n", __func__); return rc; } - header.is_resharding = false; - header.new_bucket_instance_id.clear(); + header.new_instance.clear(); return write_bucket_header(hctx, &header); } @@ -3689,7 +3685,7 @@ static int rgw_get_bucket_resharding(cls_method_context_t hctx, bufferlist *in, } cls_rgw_get_bucket_resharding_ret op_ret; - op_ret.resharding = header.is_resharding; + op_ret.new_instance = header.new_instance; ::encode(op_ret, *out); @@ -3802,6 +3798,7 @@ CLS_INIT(rgw) rgw_clear_bucket_resharding, &h_rgw_clear_bucket_resharding); cls_register_cxx_method(h_class, "get_bucket_resharding", CLS_METHOD_RD , rgw_get_bucket_resharding, &h_rgw_get_bucket_resharding); + return; } diff --git a/src/cls/rgw/cls_rgw_client.cc b/src/cls/rgw/cls_rgw_client.cc index da85cbe4175..eed5d5b1d0a 100644 --- a/src/cls/rgw/cls_rgw_client.cc +++ b/src/cls/rgw/cls_rgw_client.cc @@ -855,22 +855,19 @@ int cls_rgw_set_bucket_resharding(librados::IoCtx& io_ctx, const string& oid, return io_ctx.exec(oid, "rgw", "set_bucket_resharding", in, out); } -int cls_rgw_clear_bucket_resharding(librados::IoCtx& io_ctx, const string& oid, - const cls_rgw_bucket_instance_entry& entry) +int cls_rgw_clear_bucket_resharding(librados::IoCtx& io_ctx, const string& oid) { bufferlist in, out; struct cls_rgw_clear_bucket_resharding_op call; - call.entry = entry; ::encode(call, in); return io_ctx.exec(oid, "rgw", "clear_bucket_resharding", in, out); } int cls_rgw_get_bucket_resharding(librados::IoCtx& io_ctx, const string& oid, - const cls_rgw_bucket_instance_entry& entry, bool& resharding) + cls_rgw_bucket_instance_entry *entry) { bufferlist in, out; struct cls_rgw_get_bucket_resharding_op call; - call.entry = entry; ::encode(call, in); int r= io_ctx.exec(oid, "rgw", "get_bucket_resharding", in, out); if (r < 0) @@ -884,7 +881,7 @@ int cls_rgw_get_bucket_resharding(librados::IoCtx& io_ctx, const string& oid, return -EIO; } - resharding = op_ret.resharding; + *entry = op_ret.new_instance; return 0; } diff --git a/src/cls/rgw/cls_rgw_client.h b/src/cls/rgw/cls_rgw_client.h index fa3967ca216..2affa7dc203 100644 --- a/src/cls/rgw/cls_rgw_client.h +++ b/src/cls/rgw/cls_rgw_client.h @@ -504,9 +504,8 @@ void cls_rgw_reshard_remove(librados::ObjectWriteOperation& op, const cls_rgw_re /* resharding attribute */ int cls_rgw_set_bucket_resharding(librados::IoCtx& io_ctx, const string& oid, const cls_rgw_bucket_instance_entry& entry); -int cls_rgw_clear_bucket_resharding(librados::IoCtx& io_ctx, const string& oid, - const cls_rgw_bucket_instance_entry& entry); +int cls_rgw_clear_bucket_resharding(librados::IoCtx& io_ctx, const string& oid); int cls_rgw_get_bucket_resharding(librados::IoCtx& io_ctx, const string& oid, - const cls_rgw_bucket_instance_entry& entry, bool& resharding); + cls_rgw_bucket_instance_entry *entry); #endif diff --git a/src/cls/rgw/cls_rgw_ops.cc b/src/cls/rgw/cls_rgw_ops.cc index 192fec85de7..13121319963 100644 --- a/src/cls/rgw/cls_rgw_ops.cc +++ b/src/cls/rgw/cls_rgw_ops.cc @@ -514,7 +514,6 @@ void cls_rgw_clear_bucket_resharding_op::generate_test_instances( void cls_rgw_clear_bucket_resharding_op::dump(Formatter *f) const { - ::encode_json("entry", entry, f); } void cls_rgw_get_bucket_resharding_op::generate_test_instances( @@ -526,7 +525,6 @@ void cls_rgw_get_bucket_resharding_op::generate_test_instances( void cls_rgw_get_bucket_resharding_op::dump(Formatter *f) const { - ::encode_json("entry", entry, f); } diff --git a/src/cls/rgw/cls_rgw_ops.h b/src/cls/rgw/cls_rgw_ops.h index b182a8b0948..5d9a43f5e68 100644 --- a/src/cls/rgw/cls_rgw_ops.h +++ b/src/cls/rgw/cls_rgw_ops.h @@ -1301,17 +1301,13 @@ struct cls_rgw_set_bucket_resharding_op { WRITE_CLASS_ENCODER(cls_rgw_set_bucket_resharding_op) struct cls_rgw_clear_bucket_resharding_op { - cls_rgw_bucket_instance_entry entry; - void encode(bufferlist& bl) const { ENCODE_START(1, 1, bl); - ::encode(entry, bl); ENCODE_FINISH(bl); } void decode(bufferlist::iterator& bl) { DECODE_START(1, bl); - ::decode(entry, bl); DECODE_FINISH(bl); } static void generate_test_instances(list& o); @@ -1320,17 +1316,14 @@ struct cls_rgw_clear_bucket_resharding_op { WRITE_CLASS_ENCODER(cls_rgw_clear_bucket_resharding_op) struct cls_rgw_get_bucket_resharding_op { - cls_rgw_bucket_instance_entry entry; void encode(bufferlist& bl) const { ENCODE_START(1, 1, bl); - ::encode(entry, bl); ENCODE_FINISH(bl); } void decode(bufferlist::iterator& bl) { DECODE_START(1, bl); - ::decode(entry, bl); DECODE_FINISH(bl); } @@ -1340,17 +1333,17 @@ struct cls_rgw_get_bucket_resharding_op { WRITE_CLASS_ENCODER(cls_rgw_get_bucket_resharding_op) struct cls_rgw_get_bucket_resharding_ret { - bool resharding; + cls_rgw_bucket_instance_entry new_instance; void encode(bufferlist& bl) const { ENCODE_START(1, 1, bl); - ::encode(resharding, bl); + ::encode(new_instance, bl); ENCODE_FINISH(bl); } void decode(bufferlist::iterator& bl) { DECODE_START(1, bl); - ::decode(resharding, bl); + ::decode(new_instance, bl); DECODE_FINISH(bl); } diff --git a/src/cls/rgw/cls_rgw_types.cc b/src/cls/rgw/cls_rgw_types.cc index c0af4c06a77..c3a97c65760 100644 --- a/src/cls/rgw/cls_rgw_types.cc +++ b/src/cls/rgw/cls_rgw_types.cc @@ -517,8 +517,7 @@ 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); + ::encode_json("new_instance", new_instance, f); f->close_section(); } @@ -597,7 +596,6 @@ void cls_rgw_reshard_entry::generate_test_instances(list void cls_rgw_bucket_instance_entry::dump(Formatter *f) const { - encode_json("data", data, f); encode_json("resharding", resharding, f); encode_json("new_bucket_instance_id", new_bucket_instance_id, f); diff --git a/src/cls/rgw/cls_rgw_types.h b/src/cls/rgw/cls_rgw_types.h index a6eb2ef8e8c..dd89e73c2f7 100644 --- a/src/cls/rgw/cls_rgw_types.h +++ b/src/cls/rgw/cls_rgw_types.h @@ -604,14 +604,46 @@ struct rgw_bucket_category_stats { }; WRITE_CLASS_ENCODER(rgw_bucket_category_stats) +struct cls_rgw_bucket_instance_entry { + bool resharding{false}; + string new_bucket_instance_id; + + void encode(bufferlist& bl) const { + ENCODE_START(1, 1, bl); + ::encode(resharding, bl); + ::encode(new_bucket_instance_id, bl); + ENCODE_FINISH(bl); + } + + void decode(bufferlist::iterator& bl) { + DECODE_START(1, bl); + ::decode(resharding, bl); + ::decode(new_bucket_instance_id, bl); + DECODE_FINISH(bl); + } + + void dump(Formatter *f) const; + static void generate_test_instances(list& o); + + void clear() { + resharding = false; + new_bucket_instance_id.clear(); + } + + void set(const string& new_instance_id) { + resharding = true; + new_bucket_instance_id = new_instance_id; + } +}; +WRITE_CLASS_ENCODER(cls_rgw_bucket_instance_entry) + struct rgw_bucket_dir_header { map stats; uint64_t tag_timeout; uint64_t ver; uint64_t master_ver; string max_marker; - bool is_resharding; - string new_bucket_instance_id; + cls_rgw_bucket_instance_entry new_instance; rgw_bucket_dir_header() : tag_timeout(0), ver(0), master_ver(0) {} @@ -622,8 +654,7 @@ struct rgw_bucket_dir_header { ::encode(ver, bl); ::encode(master_ver, bl); ::encode(max_marker, bl); - ::encode(is_resharding, bl); - ::encode(new_bucket_instance_id, bl); + ::encode(new_instance, bl); ENCODE_FINISH(bl); } void decode(bufferlist::iterator &bl) { @@ -644,15 +675,18 @@ struct rgw_bucket_dir_header { ::decode(max_marker, bl); } if (struct_v >= 6) { - ::decode(is_resharding, bl); - ::decode(new_bucket_instance_id, bl); + ::decode(new_instance, bl); } else { - is_resharding = false; + new_instance = cls_rgw_bucket_instance_entry(); } DECODE_FINISH(bl); } void dump(Formatter *f) const; static void generate_test_instances(list& o); + + bool resharding() const { + return new_instance.resharding; + } }; WRITE_CLASS_ENCODER(rgw_bucket_dir_header) @@ -1054,30 +1088,4 @@ struct cls_rgw_reshard_entry }; WRITE_CLASS_ENCODER(cls_rgw_reshard_entry) -struct cls_rgw_bucket_instance_entry { - bool resharding; - string new_bucket_instance_id; - bufferlist data; - - void encode(bufferlist& bl) const { - ENCODE_START(1, 1, bl); - ::encode(resharding, bl); - ::encode(new_bucket_instance_id, bl); - ::encode(data, bl); - ENCODE_FINISH(bl); - } - - void decode(bufferlist::iterator& bl) { - DECODE_START(1, bl); - ::decode(resharding, bl); - ::decode(new_bucket_instance_id, bl); - ::decode(data, bl); - DECODE_FINISH(bl); - } - - void dump(Formatter *f) const; - static void generate_test_instances(list& o); -}; -WRITE_CLASS_ENCODER(cls_rgw_bucket_instance_entry) - #endif -- 2.39.5