rgw: add json decoders for bucket sync status

Signed-off-by: Casey Bodley <cbodley@redhat.com>
This commit is contained in:
Casey Bodley 2017-09-07 16:17:00 -04:00
parent 403d139c67
commit 28c6ac62b8
3 changed files with 74 additions and 27 deletions

View File

@ -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)

View File

@ -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) {}

View File

@ -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