]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: switch to json_spirit formatter for journal image status
authorJason Dillaman <dillaman@redhat.com>
Wed, 1 Apr 2020 19:26:39 +0000 (15:26 -0400)
committerNathan Cutler <ncutler@suse.com>
Tue, 28 Apr 2020 17:52:06 +0000 (19:52 +0200)
The free-form journal replay status description is now JSON-encoded. The
"master"/"mirror" designators have been changed to "primary"/"non_primary"
to better align with RBD terminology.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit e04422f2c60a9ce891da496b71a568264e39233e)

qa/workunits/rbd/rbd_mirror_ha.sh
qa/workunits/rbd/rbd_mirror_journal.sh
src/cls/journal/cls_journal_types.h
src/tools/rbd_mirror/image_replayer/journal/ReplayStatusFormatter.cc
src/tools/rbd_mirror/image_replayer/journal/ReplayStatusFormatter.h

index 171ab56980927fd6b9aea811b574b7c42c04dc6f..37739a83da0245d2b16531b224036604d8e27df4 100755 (executable)
@@ -71,7 +71,7 @@ test_replay()
        wait_for_replay_complete ${CLUSTER1}:${LEADER} ${CLUSTER2} ${POOL} \
                                 ${image}
        wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' \
-                                    'master_position' \
+                                    'primary_position' \
                                     "${MIRROR_USER_ID_PREFIX}${LEADER} on $(hostname -s)"
        if [ -z "${RBD_MIRROR_USE_RBD_MIRROR}" ]; then
            wait_for_status_in_pool_dir ${CLUSTER2} ${POOL} ${image} \
index 426edc42ff7ae7f2778fab749824cb92f1acc796..31b3ba8be27d6ce45838aa38b6c6e49c443010a7 100755 (executable)
@@ -20,7 +20,7 @@ set_image_meta ${CLUSTER2} ${POOL} ${image} "key2" "value2"
 wait_for_image_replay_started ${CLUSTER1} ${POOL} ${image}
 write_image ${CLUSTER2} ${POOL} ${image} 100
 wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL} ${image}
-wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'primary_position'
 if [ -z "${RBD_MIRROR_USE_RBD_MIRROR}" ]; then
   wait_for_status_in_pool_dir ${CLUSTER2} ${POOL} ${image} 'down+unknown'
 fi
@@ -36,7 +36,7 @@ write_image ${CLUSTER2} ${POOL} ${image1} 100
 start_mirrors ${CLUSTER1}
 wait_for_image_replay_started ${CLUSTER1} ${POOL} ${image1}
 wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL} ${image1}
-wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image1} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image1} 'up+replaying' 'primary_position'
 if [ -z "${RBD_MIRROR_USE_RBD_MIRROR}" ]; then
   wait_for_status_in_pool_dir ${CLUSTER2} ${POOL} ${image1} 'down+unknown'
 fi
@@ -46,7 +46,7 @@ testlog "TEST: test the first image is replaying after restart"
 write_image ${CLUSTER2} ${POOL} ${image} 100
 wait_for_image_replay_started ${CLUSTER1} ${POOL} ${image}
 wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL} ${image}
-wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'primary_position'
 compare_images ${POOL} ${image}
 
 if [ -z "${RBD_MIRROR_USE_RBD_MIRROR}" ]; then
@@ -151,7 +151,7 @@ wait_for_image_replay_started ${CLUSTER1} ${POOL} ${image}
 write_image ${CLUSTER2} ${POOL} ${image} 100
 wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL} ${image}
 wait_for_status_in_pool_dir ${CLUSTER2} ${POOL} ${image} 'up+stopped'
-wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'primary_position'
 compare_images ${POOL} ${image}
 
 # failover (unmodified)
@@ -170,7 +170,7 @@ wait_for_status_in_pool_dir ${CLUSTER2} ${POOL} ${image} 'up+unknown'
 promote_image ${CLUSTER2} ${POOL} ${image}
 wait_for_image_replay_started ${CLUSTER1} ${POOL} ${image}
 wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL} ${image}
-wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'primary_position'
 wait_for_status_in_pool_dir ${CLUSTER2} ${POOL} ${image} 'up+stopped'
 compare_images ${POOL} ${image}
 
@@ -184,7 +184,7 @@ wait_for_image_replay_started ${CLUSTER2} ${POOL} ${image}
 write_image ${CLUSTER1} ${POOL} ${image} 100
 wait_for_replay_complete ${CLUSTER2} ${CLUSTER1} ${POOL} ${image}
 wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+stopped'
-wait_for_status_in_pool_dir ${CLUSTER2} ${POOL} ${image} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER2} ${POOL} ${image} 'up+replaying' 'primary_position'
 compare_images ${POOL} ${image}
 
 # failback
@@ -196,7 +196,7 @@ promote_image ${CLUSTER2} ${POOL} ${image}
 wait_for_image_replay_started ${CLUSTER1} ${POOL} ${image}
 write_image ${CLUSTER2} ${POOL} ${image} 100
 wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL} ${image}
-wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'primary_position'
 wait_for_status_in_pool_dir ${CLUSTER2} ${POOL} ${image} 'up+stopped'
 compare_images ${POOL} ${image}
 
@@ -207,7 +207,7 @@ write_image ${CLUSTER2} ${POOL} ${force_promote_image} 100
 wait_for_image_replay_stopped ${CLUSTER2} ${POOL} ${force_promote_image}
 wait_for_image_replay_started ${CLUSTER1} ${POOL} ${force_promote_image}
 wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL} ${force_promote_image}
-wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${force_promote_image} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${force_promote_image} 'up+replaying' 'primary_position'
 wait_for_status_in_pool_dir ${CLUSTER2} ${POOL} ${force_promote_image} 'up+stopped'
 promote_image ${CLUSTER1} ${POOL} ${force_promote_image} '--force'
 wait_for_image_replay_stopped ${CLUSTER1} ${POOL} ${force_promote_image}
@@ -233,12 +233,12 @@ write_image ${CLUSTER2} ${POOL} ${clone_image} 100
 enable_mirror ${CLUSTER2} ${PARENT_POOL} ${parent_image} journal
 wait_for_image_replay_started ${CLUSTER1} ${PARENT_POOL} ${parent_image}
 wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${PARENT_POOL} ${parent_image}
-wait_for_status_in_pool_dir ${CLUSTER1} ${PARENT_POOL} ${parent_image} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${PARENT_POOL} ${parent_image} 'up+replaying' 'primary_position'
 compare_images ${PARENT_POOL} ${parent_image}
 
 wait_for_image_replay_started ${CLUSTER1} ${POOL} ${clone_image}
 wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL} ${clone_image}
-wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${clone_image} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${clone_image} 'up+replaying' 'primary_position'
 compare_images ${POOL} ${clone_image}
 
 testlog " - clone v1"
@@ -291,7 +291,7 @@ write_image ${CLUSTER2} ${POOL} ${dp_image} 100
 create_snapshot ${CLUSTER2} ${POOL} ${dp_image} 'snap2'
 write_image ${CLUSTER2} ${POOL} ${dp_image} 100
 wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL} ${dp_image}
-wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${dp_image} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${dp_image} 'up+replaying' 'primary_position'
 compare_images ${POOL} ${dp_image}@snap1
 compare_images ${POOL} ${dp_image}@snap2
 compare_images ${POOL} ${dp_image}
@@ -357,9 +357,9 @@ create_image ${CLUSTER2} ${POOL} ${rdp_image} 128 --data-pool ${pool}
 write_image ${CLUSTER2} ${pool} ${image} 100
 write_image ${CLUSTER2} ${POOL} ${rdp_image} 100
 wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${pool} ${image}
-wait_for_status_in_pool_dir ${CLUSTER1} ${pool} ${image} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${pool} ${image} 'up+replaying' 'primary_position'
 wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL} ${rdp_image}
-wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${rdp_image} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${rdp_image} 'up+replaying' 'primary_position'
 for cluster in ${CLUSTER1} ${CLUSTER2}; do
     CEPH_ARGS='' ceph --cluster ${cluster} osd pool rm ${pool} ${pool} --yes-i-really-really-mean-it
 done
@@ -405,8 +405,8 @@ write_image ${CLUSTER2} ${POOL}/${NS1} ${image} 100
 write_image ${CLUSTER2} ${POOL}/${NS2} ${image} 100
 wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL}/${NS1} ${image}
 wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL}/${NS2} ${image}
-wait_for_status_in_pool_dir ${CLUSTER1} ${POOL}/${NS1} ${image} 'up+replaying' 'master_position'
-wait_for_status_in_pool_dir ${CLUSTER1} ${POOL}/${NS2} ${image} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${POOL}/${NS1} ${image} 'up+replaying' 'primary_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${POOL}/${NS2} ${image} 'up+replaying' 'primary_position'
 compare_images ${POOL}/${NS1} ${image}
 compare_images ${POOL}/${NS2} ${image}
 
@@ -426,7 +426,7 @@ data_pool=$(get_image_data_pool ${CLUSTER1} ${POOL}/${NS1} ${dp_image})
 test "${data_pool}" = "${PARENT_POOL}"
 write_image ${CLUSTER2} ${POOL}/${NS1} ${dp_image} 100
 wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL}/${NS1} ${dp_image}
-wait_for_status_in_pool_dir ${CLUSTER1} ${POOL}/${NS1} ${dp_image} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${POOL}/${NS1} ${dp_image} 'up+replaying' 'primary_position'
 compare_images ${POOL}/${NS1} ${dp_image}
 
 testlog "TEST: simple image resync"
@@ -434,7 +434,7 @@ request_resync_image ${CLUSTER1} ${POOL} ${image} image_id
 wait_for_image_present ${CLUSTER1} ${POOL} ${image} 'deleted' ${image_id}
 wait_for_image_present ${CLUSTER1} ${POOL} ${image} 'present'
 wait_for_image_replay_started ${CLUSTER1} ${POOL} ${image}
-wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'primary_position'
 compare_images ${POOL} ${image}
 
 testlog "TEST: image resync while replayer is stopped"
@@ -447,7 +447,7 @@ if [ -z "${RBD_MIRROR_USE_RBD_MIRROR}" ]; then
   admin_daemons ${CLUSTER1} rbd mirror start ${POOL}/${image}
   wait_for_image_present ${CLUSTER1} ${POOL} ${image} 'present'
   wait_for_image_replay_started ${CLUSTER1} ${POOL} ${image}
-  wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'master_position'
+  wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'primary_position'
   compare_images ${POOL} ${image}
 fi
 
@@ -458,7 +458,7 @@ start_mirrors ${CLUSTER1}
 wait_for_image_present ${CLUSTER1} ${POOL} ${image} 'deleted' ${image_id}
 wait_for_image_present ${CLUSTER1} ${POOL} ${image} 'present'
 wait_for_image_replay_started ${CLUSTER1} ${POOL} ${image}
-wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'primary_position'
 compare_images ${POOL} ${image}
 
 testlog "TEST: client disconnect"
@@ -535,7 +535,7 @@ wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+error' 'disconnecte
 testlog "TEST: split-brain"
 image=split-brain
 create_image ${CLUSTER2} ${POOL} ${image}
-wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'primary_position'
 promote_image ${CLUSTER1} ${POOL} ${image} --force
 wait_for_image_replay_stopped ${CLUSTER1} ${POOL} ${image}
 wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+stopped'
@@ -543,7 +543,7 @@ write_image ${CLUSTER1} ${POOL} ${image} 10
 demote_image ${CLUSTER1} ${POOL} ${image}
 wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+error' 'split-brain'
 request_resync_image ${CLUSTER1} ${POOL} ${image} image_id
-wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'master_position'
+wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'primary_position'
 
 if [ -z "${RBD_MIRROR_USE_RBD_MIRROR}" ]; then
   # teuthology will trash the daemon
index 705936a06d0457386ba4692dd4badac54996ddc7..f82d30c7e469419a06a00e5e0ef2537b91793caf 100644 (file)
@@ -35,6 +35,9 @@ struct ObjectPosition {
             tag_tid == rhs.tag_tid &&
             entry_tid == rhs.entry_tid);
   }
+  inline bool operator!=(const ObjectPosition& rhs) const {
+    return !(*this == rhs);
+  }
 
   void encode(ceph::buffer::list& bl) const;
   void decode(ceph::buffer::list::const_iterator& iter);
index 79b4b365671665648cc5245a33428a8a2e5074db..8c01e8a72033c285d14eb3f6e254d969192f358a 100644 (file)
@@ -6,6 +6,7 @@
 #include "common/dout.h"
 #include "common/errno.h"
 #include "journal/Journaler.h"
+#include "json_spirit/json_spirit.h"
 #include "librbd/ImageCtx.h"
 #include "librbd/Journal.h"
 #include "librbd/Utils.h"
@@ -24,6 +25,21 @@ namespace journal {
 
 using librbd::util::unique_lock_name;
 
+namespace {
+
+json_spirit::mObject to_json_object(
+    const cls::journal::ObjectPosition& position) {
+  json_spirit::mObject object;
+  if (position != cls::journal::ObjectPosition{}) {
+    object["object_number"] = position.object_number;
+    object["tag_tid"] = position.tag_tid;
+    object["entry_tid"] = position.entry_tid;
+  }
+  return object;
+}
+
+} // anonymous namespace
+
 template <typename I>
 ReplayStatusFormatter<I>::ReplayStatusFormatter(Journaler *journaler,
                                                const std::string &mirror_uuid)
@@ -221,23 +237,12 @@ void ReplayStatusFormatter<I>::format(std::string *description) {
           << ", m_mirror_position=" << m_mirror_position
           << ", m_entries_behind_master=" << m_entries_behind_master << dendl;
 
-  std::stringstream ss;
-  ss << "master_position=";
-  if (m_master_position == cls::journal::ObjectPosition()) {
-    ss << "[]";
-  } else {
-    ss << m_master_position;
-  }
-  ss << ", mirror_position=";
-  if (m_mirror_position == cls::journal::ObjectPosition()) {
-    ss << "[]";
-  } else {
-    ss << m_mirror_position;
-  }
-  ss << ", entries_behind_master="
-     << (m_entries_behind_master > 0 ? m_entries_behind_master : 0);
-
-  *description = ss.str();
+  json_spirit::mObject root_obj;
+  root_obj["primary_position"] = to_json_object(m_master_position);
+  root_obj["non_primary_position"] = to_json_object(m_mirror_position);
+  root_obj["entries_behind_primary"] = (
+    m_entries_behind_master > 0 ? m_entries_behind_master : 0);
+  *description = json_spirit::write(root_obj);
 }
 
 } // namespace journal
index 5ba000a16664c413ce663a88e354c292db31159d..d5d6317c9c96441f2780823595dd9f1f455bc8ff 100644 (file)
@@ -43,7 +43,7 @@ private:
   Context *m_on_finish = nullptr;
   cls::journal::ObjectPosition m_master_position;
   cls::journal::ObjectPosition m_mirror_position;
-  int m_entries_behind_master = 0;
+  int64_t m_entries_behind_master = 0;
   cls::journal::Tag m_tag;
   std::map<uint64_t, librbd::journal::TagData> m_tag_cache;