From a736c25a7071389563e77704f41d0c4ae2b08b13 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 3 Aug 2015 16:01:22 -0700 Subject: [PATCH] rgw: retrieve a specific sync shard info Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_admin.cc | 12 ++++++++++ src/rgw/rgw_sync.cc | 57 ++++++++++++++++++++++++++++++++++++++++++-- src/rgw/rgw_sync.h | 23 ++++++++++++++++-- 3 files changed, 88 insertions(+), 4 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index a17a2faf8c5e4..a6e402ff5eb75 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -2935,7 +2935,19 @@ next: return -ret; } + formatter->open_object_section("result"); encode_json("sync_status", sync_status, formatter); + + if (shard_id >= 0) { + rgw_sync_marker marker; + ret = sync.get_shard_sync_marker(shard_id, &marker); + if (ret < 0) { + cerr << "ERROR: cannot read shard status for shard_id=" << shard_id << std::endl; + } else { + ::encode_json("shard_marker", marker, formatter); + } + } + formatter->close_section(); formatter->flush(cout); } diff --git a/src/rgw/rgw_sync.cc b/src/rgw/rgw_sync.cc index 93d101f5a20a9..12448811e2b36 100644 --- a/src/rgw/rgw_sync.cc +++ b/src/rgw/rgw_sync.cc @@ -80,7 +80,7 @@ int RGWRemoteMetaLog::init() return ret; } - ret = status_manager.init(); + ret = status_manager.init(log_info.num_shards); if (ret < 0) { ldout(store->ctx(), 0) << "failed in status_manager.init() ret=" << ret << dendl; return ret; @@ -190,8 +190,10 @@ static void _aio_completion_notifier_cb(librados::completion_t cb, void *arg) #define CLONE_OPS_WINDOW 16 -int RGWMetaSyncStatusManager::init() +int RGWMetaSyncStatusManager::init(int _num_shards) { + num_shards = _num_shards; + const char *log_pool = store->get_zone_params().log_pool.name.c_str(); librados::Rados *rados = store->get_rados_handle(); int r = rados->ioctx_create(log_pool, ioctx); @@ -201,8 +203,13 @@ int RGWMetaSyncStatusManager::init() } global_status_oid = "mdlog.state.global"; + shard_status_oid_prefix = "mdlog.state.shard"; global_status_obj = rgw_obj(store->get_zone_params().log_pool, global_status_oid); + for (int i = 0; i < num_shards; i++) { + shard_objs[i] = rgw_obj(store->get_zone_params().log_pool, shard_obj_name(i)); + } + return 0; } @@ -231,6 +238,39 @@ int RGWMetaSyncStatusManager::read_global_status() return 0; } +string RGWMetaSyncStatusManager::shard_obj_name(int shard_id) +{ + char buf[shard_status_oid_prefix.size() + 16]; + snprintf(buf, sizeof(buf), "%s.%d", shard_status_oid_prefix.c_str(), shard_id); + + return string(buf); +} + +int RGWMetaSyncStatusManager::read_shard_status(int shard_id) +{ + RGWObjectCtx obj_ctx(store, NULL); + + RGWRados::SystemObject src(store, obj_ctx, shard_objs[shard_id]); + RGWRados::SystemObject::Read rop(&src); + + bufferlist bl; + + int ret = rop.read(0, -1, bl, NULL); + if (ret < 0 && ret != -ENOENT) { + return ret; + } + + if (ret != -ENOENT) { + bufferlist::iterator iter = bl.begin(); + try { + ::decode(shard_markers[shard_id], iter); + } catch (buffer::error& err) { + ldout(store->ctx(), 0) << "ERROR: failed to decode global mdlog status" << dendl; + } + } + return 0; +} + int RGWMetaSyncStatusManager::set_state(RGWMetaSyncGlobalStatus::SyncState state) { global_status.state = state; @@ -652,6 +692,19 @@ int RGWRemoteMetaLog::get_sync_status(RGWMetaSyncGlobalStatus *sync_status) return 0; } +int RGWRemoteMetaLog::get_shard_sync_marker(int shard_id, rgw_sync_marker *shard_status) +{ + int ret = status_manager.read_shard_status(shard_id); + if (ret < 0) { + ldout(store->ctx(), 0) << "ERROR: status_manager.read_global_status() returned ret=" << ret << dendl; + return ret; + } + + *shard_status = status_manager.get_shard_status(shard_id); + + return 0; +} + int RGWCloneMetaLogOp::operate() { switch (state) { diff --git a/src/rgw/rgw_sync.h b/src/rgw/rgw_sync.h index 94e84941e9f4d..7993a0731ae11 100644 --- a/src/rgw/rgw_sync.h +++ b/src/rgw/rgw_sync.h @@ -185,6 +185,11 @@ struct rgw_sync_marker { ::decode(marker, bl); DECODE_FINISH(bl); } + + void dump(Formatter *f) const { + encode_json("state", (int)state, f); + encode_json("marker", marker, f); + } }; WRITE_CLASS_ENCODER(rgw_sync_marker) @@ -194,16 +199,26 @@ class RGWMetaSyncStatusManager { librados::IoCtx ioctx; string global_status_oid; + string shard_status_oid_prefix; rgw_obj global_status_obj; RGWMetaSyncGlobalStatus global_status; map shard_markers; + map shard_objs; + + string shard_obj_name(int shard_id); + + int num_shards; public: - RGWMetaSyncStatusManager(RGWRados *_store) : store(_store) {} + RGWMetaSyncStatusManager(RGWRados *_store) : store(_store), num_shards(0) {} - int init(); + int init(int _num_shards); int read_global_status(); + int read_shard_status(int shard_id); + rgw_sync_marker& get_shard_status(int shard_id) { + return shard_markers[shard_id]; + } int set_state(RGWMetaSyncGlobalStatus::SyncState state); RGWMetaSyncGlobalStatus& get_global_status() { return global_status; } @@ -250,6 +265,7 @@ public: int clone_shards(); int fetch(); int get_sync_status(RGWMetaSyncGlobalStatus *sync_status); + int get_shard_sync_marker(int shard_id, rgw_sync_marker *shard_status); }; class RGWMetadataSync { @@ -262,6 +278,9 @@ public: int init(); int get_sync_status(RGWMetaSyncGlobalStatus *sync_status) { return master_log.get_sync_status(sync_status); } + int get_shard_sync_marker(int shard_id, rgw_sync_marker *shard_status) { + return master_log.get_shard_sync_marker(shard_id, shard_status); + } int fetch() { return master_log.fetch(); } int clone_shards() { return master_log.clone_shards(); } }; -- 2.39.5