From 2c48adec9ffb1a99bf13ff52a39ed75a0adfd4d6 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Thu, 2 Jul 2015 11:43:09 -0700 Subject: [PATCH] rgw: decode number of mdlog shards Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_sync.cc | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_sync.cc b/src/rgw/rgw_sync.cc index 482f5e82c165a..2d1b3b06a63d7 100644 --- a/src/rgw/rgw_sync.cc +++ b/src/rgw/rgw_sync.cc @@ -1,20 +1,51 @@ +#include "common/ceph_json.h" + #include "rgw_common.h" #include "rgw_rados.h" #define dout_subsys ceph_subsys_rgw +struct mdlog_info { + uint32_t num_shards; + + mdlog_info() : num_shards(0) {} + + void decode_json(JSONObj *obj) { + JSONDecoder::decode_json("num_objects", num_shards, obj); + } +}; + +template +static int parse_decode_json(T& t, bufferlist& bl) +{ + JSONParser p; + int ret = p.parse(bl.c_str(), bl.length()); + if (ret < 0) { + cout << "failed to parse JSON" << std::endl; + return ret; + } + + try { + decode_json_obj(t, &p); + } catch (JSONDecoder::err& e) { + cout << "failed to decode JSON input: " << e.message << std::endl; + return -EINVAL; + } + return 0; +} + class RGWRemoteMetaLog { RGWRados *store; - int num_shards; + mdlog_info log_info; vector markers; public: - RGWRemoteMetaLog(RGWRados *_store) : store(_store), num_shards(0) {} + RGWRemoteMetaLog(RGWRados *_store) : store(_store) {} int init(); }; @@ -30,6 +61,16 @@ int RGWRemoteMetaLog::init() return ret; } + ldout(store->ctx(), 20) << __FILE__ << ": read_data=" << string(bl.c_str(), bl.length()) << dendl; + + ret = parse_decode_json(log_info, bl); + if (ret < 0) { + lderr(store->ctx()) << "ERROR: failed to parse mdlog_info, ret=" << ret << dendl; + return ret; + } + + ldout(store->ctx(), 20) << "remote mdlog, num_shards=" << log_info.num_shards << dendl; + return 0; } -- 2.39.5