From 49bf8ba1bfa9c56671ac8dbac760ad0896fc5f1d Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Thu, 5 Nov 2015 14:50:04 -0800 Subject: [PATCH] rgw: show data full sync stats Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_admin.cc | 40 ++++++++++++++++++++++++++++++++++++++++ src/rgw/rgw_data_sync.cc | 35 +++++++++++++++++++++++++++-------- src/rgw/rgw_data_sync.h | 6 +++++- src/rgw/rgw_sync.cc | 2 +- 4 files changed, 73 insertions(+), 10 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 96cb8aef04ffa..c5da69b7fe49b 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -4278,7 +4278,27 @@ next: rgw_meta_sync_status& sync_status = sync.get_sync_status(); + formatter->open_object_section("summary"); encode_json("sync_status", sync_status, formatter); + + uint64_t full_total = 0; + uint64_t full_complete = 0; + + for (auto marker_iter : sync_status.sync_markers) { + full_total += marker_iter.second.total_entries; + if (marker_iter.second.state == rgw_meta_sync_marker::SyncState::FullSync) { + full_complete += marker_iter.second.pos; + } else { + full_complete += marker_iter.second.total_entries; + } + } + + formatter->open_object_section("full_sync"); + encode_json("total", full_total, formatter); + encode_json("complete", full_complete, formatter); + formatter->close_section(); + formatter->close_section(); + formatter->flush(cout); } @@ -4337,7 +4357,27 @@ next: rgw_data_sync_status& sync_status = sync.get_sync_status(); + formatter->open_object_section("summary"); encode_json("sync_status", sync_status, formatter); + + uint64_t full_total = 0; + uint64_t full_complete = 0; + + for (auto marker_iter : sync_status.sync_markers) { + full_total += marker_iter.second.total_entries; + if (marker_iter.second.state == rgw_meta_sync_marker::SyncState::FullSync) { + full_complete += marker_iter.second.pos; + } else { + full_complete += marker_iter.second.total_entries; + } + } + + formatter->open_object_section("full_sync"); + encode_json("total", full_total, formatter); + encode_json("complete", full_complete, formatter); + formatter->close_section(); + formatter->close_section(); + formatter->flush(cout); } diff --git a/src/rgw/rgw_data_sync.cc b/src/rgw/rgw_data_sync.cc index 2fdd11f5004d2..32d411a6e9eef 100644 --- a/src/rgw/rgw_data_sync.cc +++ b/src/rgw/rgw_data_sync.cc @@ -494,6 +494,7 @@ class RGWListBucketIndexesCR : public RGWCoroutine { RGWRESTConn *conn; string source_zone; + rgw_data_sync_status *sync_status; int num_shards; int req_ret; @@ -511,16 +512,21 @@ class RGWListBucketIndexesCR : public RGWCoroutine { string s; int i; + bool failed; + public: RGWListBucketIndexesCR(RGWRados *_store, RGWHTTPManager *_mgr, RGWAsyncRadosProcessor *_async_rados, RGWRESTConn *_conn, - const string& _source_zone, int _num_shards) : RGWCoroutine(_store->ctx()), store(_store), + const string& _source_zone, + rgw_data_sync_status *_sync_status) : RGWCoroutine(_store->ctx()), store(_store), http_manager(_mgr), async_rados(_async_rados), - conn(_conn), source_zone(_source_zone), num_shards(_num_shards), - req_ret(0), entries_index(NULL), i(0) { + conn(_conn), source_zone(_source_zone), + sync_status(_sync_status), + req_ret(0), entries_index(NULL), i(0), failed(false) { oid_prefix = datalog_sync_full_sync_index_prefix + "." + source_zone; path = "/admin/metadata/bucket.instance"; + num_shards = sync_status->sync_info.num_shards; } ~RGWListBucketIndexesCR() { delete entries_index; @@ -570,8 +576,20 @@ public: yield entries_index->append(key, store->data_log->get_log_shard_id(meta_info.data.get_bucket_info().bucket, -1)); } } - - yield entries_index->finish(); + yield { + if (!entries_index->finish()) { + failed = true; + } + } + if (!failed) { + for (map::iterator iter = sync_status->sync_markers.begin(); iter != sync_status->sync_markers.end(); ++iter) { + int shard_id = (int)iter->first; + rgw_data_sync_marker& marker = iter->second; + marker.total_entries = entries_index->get_total_entries(shard_id); + spawn(new RGWSimpleRadosWriteCR(async_rados, store, store->get_zone_params().log_pool, + RGWDataSyncStatusManager::shard_obj_name(source_zone, shard_id), marker), true); + } + } int ret; while (collect(&ret)) { if (ret < 0) { @@ -619,6 +637,7 @@ public: RGWCoroutine *store_marker(const string& new_marker, uint64_t index_pos) { sync_marker.marker = new_marker; + sync_marker.pos = index_pos; ldout(store->ctx(), 20) << __func__ << "(): updating marker marker_oid=" << marker_oid << " marker=" << new_marker << dendl; return new RGWSimpleRadosWriteCR(async_rados, store, store->get_zone_params().log_pool, @@ -882,8 +901,8 @@ public: iter = entries.begin(); for (; iter != entries.end(); ++iter) { ldout(store->ctx(), 20) << __func__ << ": full sync: " << iter->first << dendl; - marker_tracker->start(iter->first, total_entries); total_entries++; + marker_tracker->start(iter->first, total_entries); // fetch remote and write locally yield spawn(new RGWDataSyncSingleEntryCR(store, http_manager, async_rados, conn, source_zone, iter->first, iter->first, marker_tracker), false); if (retcode < 0) { @@ -1047,7 +1066,7 @@ public: /* state: building full sync maps */ yield { ldout(store->ctx(), 20) << __func__ << "(): building full sync maps" << dendl; - r = call(new RGWListBucketIndexesCR(store, http_manager, async_rados, conn, source_zone, sync_status.sync_info.num_shards)); + r = call(new RGWListBucketIndexesCR(store, http_manager, async_rados, conn, source_zone, &sync_status)); if (r < 0) { ldout(store->ctx(), 0) << "ERROR: failed to call RGWListBucketIndexesCR r=" << r << dendl; return set_cr_error(r); @@ -1899,8 +1918,8 @@ int RGWBucketShardFullSyncCR::operate() ldout(store->ctx(), 20) << "[full sync] syncing object: " << bucket_name << ":" << bucket_id << ":" << shard_id << "/" << entries_iter->key << dendl; yield { bucket_list_entry& entry = *entries_iter; - marker_tracker->start(entry.key, total_entries); total_entries++; + marker_tracker->start(entry.key, total_entries); list_marker = entry.key; spawn(new RGWBucketSyncSingleEntryCR(store, async_rados, source_zone, bucket_info, shard_id, entry.key, entry.versioned_epoch, entry.mtime, CLS_RGW_OP_ADD, entry.key, marker_tracker), false); diff --git a/src/rgw/rgw_data_sync.h b/src/rgw/rgw_data_sync.h index fd649860c5287..0e63df3fd2ec1 100644 --- a/src/rgw/rgw_data_sync.h +++ b/src/rgw/rgw_data_sync.h @@ -71,15 +71,17 @@ struct rgw_data_sync_marker { uint16_t state; string marker; string next_step_marker; + uint64_t total_entries; uint64_t pos; - rgw_data_sync_marker() : state(FullSync) {} + rgw_data_sync_marker() : state(FullSync), total_entries(0), pos(0) {} void encode(bufferlist& bl) const { ENCODE_START(1, 1, bl); ::encode(state, bl); ::encode(marker, bl); ::encode(next_step_marker, bl); + ::encode(total_entries, bl); ::encode(pos, bl); ENCODE_FINISH(bl); } @@ -89,6 +91,7 @@ struct rgw_data_sync_marker { ::decode(state, bl); ::decode(marker, bl); ::decode(next_step_marker, bl); + ::decode(total_entries, bl); ::decode(pos, bl); DECODE_FINISH(bl); } @@ -97,6 +100,7 @@ struct rgw_data_sync_marker { encode_json("state", (int)state, f); encode_json("marker", marker, f); encode_json("next_step_marker", next_step_marker, f); + encode_json("total_entries", total_entries, f); encode_json("pos", pos, f); } }; diff --git a/src/rgw/rgw_sync.cc b/src/rgw/rgw_sync.cc index 5893085dee557..a304124cc5327 100644 --- a/src/rgw/rgw_sync.cc +++ b/src/rgw/rgw_sync.cc @@ -1183,9 +1183,9 @@ public: iter = entries.begin(); for (; iter != entries.end(); ++iter) { ldout(sync_env->cct, 20) << __func__ << ": full sync: " << iter->first << dendl; + total_entries++; marker_tracker->start(iter->first, total_entries); - total_entries++; // fetch remote and write locally yield { RGWCoroutinesStack *stack = spawn(new RGWMetaSyncSingleEntryCR(sync_env, iter->first, iter->first, marker_tracker), false); -- 2.39.5