diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 21a6ec060d4..a9a5549b0b7 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -1728,6 +1728,7 @@ struct rgw_obj_key { DECODE_FINISH(bl); } void dump(Formatter *f) const; + void decode_json(JSONObj *obj); }; WRITE_CLASS_ENCODER(rgw_obj_key) diff --git a/src/rgw/rgw_data_sync.h b/src/rgw/rgw_data_sync.h index f4d3c7e7138..11232202486 100644 --- a/src/rgw/rgw_data_sync.h +++ b/src/rgw/rgw_data_sync.h @@ -356,10 +356,8 @@ struct rgw_bucket_shard_full_sync_marker { DECODE_FINISH(bl); } - void dump(Formatter *f) const { - encode_json("position", position, f); - encode_json("count", count, f); - } + void dump(Formatter *f) const; + void decode_json(JSONObj *obj); }; WRITE_CLASS_ENCODER(rgw_bucket_shard_full_sync_marker) @@ -382,9 +380,8 @@ struct rgw_bucket_shard_inc_sync_marker { DECODE_FINISH(bl); } - void dump(Formatter *f) const { - encode_json("position", position, f); - } + void dump(Formatter *f) const; + void decode_json(JSONObj *obj); bool operator<(const rgw_bucket_shard_inc_sync_marker& m) const { return (position < m.position); @@ -423,26 +420,8 @@ struct rgw_bucket_shard_sync_info { DECODE_FINISH(bl); } - void dump(Formatter *f) const { - string s; - switch ((SyncState)state) { - case StateInit: - s = "init"; - break; - case StateFullSync: - s = "full-sync"; - break; - case StateIncrementalSync: - s = "incremental-sync"; - break; - default: - s = "unknown"; - break; - } - encode_json("status", s, f); - encode_json("full_marker", full_marker, f); - encode_json("inc_marker", inc_marker, f); - } + void dump(Formatter *f) const; + void decode_json(JSONObj *obj); rgw_bucket_shard_sync_info() : state((int)StateInit) {} diff --git a/src/rgw/rgw_json_enc.cc b/src/rgw/rgw_json_enc.cc index ad7b941bf3a..01de71edfd2 100644 --- a/src/rgw/rgw_json_enc.cc +++ b/src/rgw/rgw_json_enc.cc @@ -11,6 +11,7 @@ #include "rgw_keystone.h" #include "rgw_basic_types.h" #include "rgw_op.h" +#include "rgw_data_sync.h" #include "rgw_sync.h" #include "rgw_orphan.h" @@ -790,6 +791,13 @@ void rgw_obj_key::dump(Formatter *f) const encode_json("ns", ns, f); } +void rgw_obj_key::decode_json(JSONObj *obj) +{ + JSONDecoder::decode_json("name", name, obj); + JSONDecoder::decode_json("instance", instance, obj); + JSONDecoder::decode_json("ns", ns, obj); +} + void RGWBucketEnt::dump(Formatter *f) const { encode_json("bucket", bucket, f); @@ -1344,6 +1352,65 @@ void rgw_sync_error_info::dump(Formatter *f) const { encode_json("message", message, f); } +void rgw_bucket_shard_full_sync_marker::decode_json(JSONObj *obj) +{ + JSONDecoder::decode_json("position", position, obj); + JSONDecoder::decode_json("count", count, obj); +} + +void rgw_bucket_shard_full_sync_marker::dump(Formatter *f) const +{ + encode_json("position", position, f); + encode_json("count", count, f); +} + +void rgw_bucket_shard_inc_sync_marker::decode_json(JSONObj *obj) +{ + JSONDecoder::decode_json("position", position, obj); +} + +void rgw_bucket_shard_inc_sync_marker::dump(Formatter *f) const +{ + encode_json("position", position, f); +} + +void rgw_bucket_shard_sync_info::decode_json(JSONObj *obj) +{ + std::string s; + JSONDecoder::decode_json("status", s, obj); + if (s == "full-sync") { + state = StateFullSync; + } else if (s == "incremental-sync") { + state = StateIncrementalSync; + } else { + state = StateInit; + } + JSONDecoder::decode_json("full_marker", full_marker, obj); + JSONDecoder::decode_json("inc_marker", inc_marker, obj); +} + +void rgw_bucket_shard_sync_info::dump(Formatter *f) const +{ + const char *s{nullptr}; + switch ((SyncState)state) { + case StateInit: + s = "init"; + break; + case StateFullSync: + s = "full-sync"; + break; + case StateIncrementalSync: + s = "incremental-sync"; + break; + default: + s = "unknown"; + break; + } + encode_json("status", s, f); + encode_json("full_marker", full_marker, f); + encode_json("inc_marker", inc_marker, f); +} + /* This utility function shouldn't conflict with the overload of std::to_string * provided by string_ref since Boost 1.54 as it's defined outside of the std * namespace. I hope we'll remove it soon - just after merging the Matt's PR