From: Jason Dillaman Date: Thu, 2 Apr 2020 17:43:09 +0000 (-0400) Subject: rbd-mirror: switch to json_spirit formatter for snapshot image status X-Git-Tag: v15.2.2~44^2~28 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=24a43b68fa5d41c1212ceee01e17f9fa4da359d2;p=ceph.git rbd-mirror: switch to json_spirit formatter for snapshot image status This will make it cleaner and easier to add additional data fields to the existing JSON replaying status. Signed-off-by: Jason Dillaman (cherry picked from commit de445810e97b345f647ffc5f5792dfc2ad589f06) --- diff --git a/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc b/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc index 2982f86a2b2e..b92d8ae58fc7 100644 --- a/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc +++ b/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc @@ -8,6 +8,7 @@ #include "common/Timer.h" #include "common/WorkQueue.h" #include "cls/rbd/cls_rbd_client.h" +#include "json_spirit/json_spirit.h" #include "librbd/ImageCtx.h" #include "librbd/ImageState.h" #include "librbd/Utils.h" @@ -240,11 +241,9 @@ bool Replayer::get_replay_status(std::string* description, replay_state = "syncing"; } - *description = - "{" - "\"replay_state\": \"" + replay_state + "\", " + - "\"remote_snapshot_timestamp\": " + - stringify(remote_snap_info->timestamp.sec()); + json_spirit::mObject root_obj; + root_obj["replay_state"] = replay_state; + root_obj["remote_snapshot_timestamp"] = remote_snap_info->timestamp.sec(); auto matching_remote_snap_id = util::compute_remote_snap_id( m_state_builder->local_image_ctx->image_lock, @@ -258,9 +257,8 @@ bool Replayer::get_replay_status(std::string* description, // use the timestamp from the matching remote image since // the local snapshot would just be the time the snapshot was // synced and not the consistency point in time. - *description += ", " - "\"local_snapshot_timestamp\": " + - stringify(matching_remote_snap_it->second.timestamp.sec()); + root_obj["local_snapshot_timestamp"] = + matching_remote_snap_it->second.timestamp.sec(); } matching_remote_snap_it = m_state_builder->remote_image_ctx->snap_info.find( @@ -268,16 +266,14 @@ bool Replayer::get_replay_status(std::string* description, if (m_remote_snap_id_end != CEPH_NOSNAP && matching_remote_snap_it != m_state_builder->remote_image_ctx->snap_info.end()) { - *description += ", " - "\"syncing_snapshot_timestamp\": " + - stringify(remote_snap_info->timestamp.sec()) + ", " + - "\"syncing_percent\": " + stringify(static_cast( + root_obj["syncing_snapshot_timestamp"] = remote_snap_info->timestamp.sec(); + root_obj["syncing_percent"] = static_cast( 100 * m_local_mirror_snap_ns.last_copied_object_number / - static_cast(std::max(1U, m_local_object_count)))); + static_cast(std::max(1U, m_local_object_count))); } - *description += - "}"; + *description = json_spirit::write( + root_obj, json_spirit::remove_trailing_zeros); local_image_locker.unlock(); remote_image_locker.unlock();