]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: ImageReplayer: pass registered client ID as external param
authorMykola Golub <mgolub@mirantis.com>
Sun, 21 Feb 2016 11:16:04 +0000 (13:16 +0200)
committerMykola Golub <mgolub@mirantis.com>
Tue, 23 Feb 2016 07:25:20 +0000 (09:25 +0200)
Signed-off-by: Mykola Golub <mgolub@mirantis.com>
qa/workunits/rbd/rbd_mirror_image_replay.sh
src/test/rbd_mirror/image_replay.cc
src/test/rbd_mirror/test_ImageReplayer.cc
src/tools/rbd_mirror/ImageReplayer.cc
src/tools/rbd_mirror/ImageReplayer.h
src/tools/rbd_mirror/Replayer.cc
src/tools/rbd_mirror/Replayer.h

index 1bc8dd53bd7d946cc5db3d45227c91a73bf77656..bf496f4c01c29d65bf37d094180a815ca51e1304 100755 (executable)
@@ -3,7 +3,7 @@
 LOC_POOL=rbd_mirror_local$$
 RMT_POOL=rbd_mirror_remote$$
 IMAGE=rbdimagereplay$$
-CLUSTER_ID=
+CLIENT_ID=rbd_mirror_image_replay
 RBD_IMAGE_REPLAY_PID_FILE=
 TEMPDIR=
 
@@ -17,8 +17,6 @@ setup()
 
     TEMPDIR=`mktemp -d`
 
-    CLUSTER_ID=`ceph-conf fsid`
-
     ceph osd pool create ${LOC_POOL} 128 128 || :
     ceph osd pool create ${RMT_POOL} 128 128 || :
 
@@ -72,7 +70,7 @@ start_replay()
        --debug-rbd=30 --debug-journaler=30 \
        --debug-rbd_mirror=30 \
        --daemonize=true \
-       ${LOC_POOL} ${RMT_POOL} ${IMAGE}
+       ${CLIENT_ID} ${LOC_POOL} ${RMT_POOL} ${IMAGE}
 }
 
 stop_replay()
@@ -105,7 +103,7 @@ wait_for_replay_complete()
        local status_log=${TEMPDIR}/${RMT_POOL}-${IMAGE}.status
        rbd -p ${RMT_POOL} journal status --image ${IMAGE} | tee ${status_log}
        local master_pos=`sed -nEe 's/^.*id=,.*entry_tid=([0-9]+).*$/\1/p' ${status_log}`
-       local mirror_pos=`sed -nEe 's/^.*id='${CLUSTER_ID}',.*entry_tid=([0-9]+).*$/\1/p' ${status_log}`
+       local mirror_pos=`sed -nEe 's/^.*id='${CLIENT_ID}',.*entry_tid=([0-9]+).*$/\1/p' ${status_log}`
        test -n "${master_pos}" -a "${master_pos}" = "${mirror_pos}" && return 0
     done
     return 1
index 8044c139e5fef91b83f51ba25fd935a07a7bdc7e..cb175f8394b396258030952dac507b1bf6ec51f7 100644 (file)
@@ -22,8 +22,9 @@ rbd::mirror::ImageReplayer *replayer = nullptr;
 
 void usage() {
   std::cout << "usage: ceph_test_rbd_mirror_image_replay [options...] \\" << std::endl;
-  std::cout << "           <local-pool> <remote-pool> <image>" << std::endl;
+  std::cout << "           <client-id> <local-pool> <remote-pool> <image>" << std::endl;
   std::cout << std::endl;
+  std::cout << "  client-id     client ID to register in remote journal" << std::endl;
   std::cout << "  local-pool    local (secondary, destination) pool" << std::endl;
   std::cout << "  remote-pool   remote (primary, source) pool" << std::endl;
   std::cout << "  image         image to replay (mirror)" << std::endl;
@@ -87,17 +88,19 @@ int main(int argc, const char **argv)
     }
   }
 
-  if (args.size() < 3) {
+  if (args.size() < 4) {
     usage();
     return EXIT_FAILURE;
   }
 
-  std::string local_pool_name = args[0];
-  std::string remote_pool_name = args[1];
-  std::string image_name = args[2];
+  std::string client_id = args[0];
+  std::string local_pool_name = args[1];
+  std::string remote_pool_name = args[2];
+  std::string image_name = args[3];
 
-  dout(1) << "local_pool_name=" << local_pool_name << ", remote_pool_name="
-         << remote_pool_name << ", image_name=" << image_name << dendl;
+  dout(1) << "client_id=" << client_id << ", local_pool_name="
+         << local_pool_name << ", remote_pool_name=" << remote_pool_name
+         << ", image_name=" << image_name << dendl;
 
   rbd::mirror::ImageReplayer::BootstrapParams bootstap_params(local_pool_name,
                                                              image_name);
@@ -167,8 +170,8 @@ int main(int argc, const char **argv)
 
   dout(5) << "starting replay" << dendl;
 
-  replayer = new rbd::mirror::ImageReplayer(local, remote, remote_pool_id,
-                                           remote_image_id);
+  replayer = new rbd::mirror::ImageReplayer(local, remote, client_id,
+                                           remote_pool_id, remote_image_id);
 
   r = replayer->start(&bootstap_params);
   if (r < 0) {
index c76972d1981e3d718ed3241e362eff5af7f962a2..a22db52c45654671e8f99ed32ced619f5ad039a1 100644 (file)
@@ -70,10 +70,9 @@ public:
     }
   };
 
-  TestImageReplayer() : m_watch_handle(0)
+  TestImageReplayer() : m_client_id("TestImageReplayer"), m_watch_handle(0)
   {
     EXPECT_EQ("", connect_cluster_pp(m_local_cluster));
-    EXPECT_EQ(0, m_local_cluster.cluster_fsid(&m_local_cluster_id));
 
     m_local_pool_name = get_temp_pool_name();
     EXPECT_EQ("", create_one_pool_pp(m_local_pool_name, m_local_cluster));
@@ -102,7 +101,7 @@ public:
     m_replayer = new rbd::mirror::ImageReplayer(
       rbd::mirror::RadosRef(new librados::Rados(m_local_ioctx)),
       rbd::mirror::RadosRef(new librados::Rados(m_remote_ioctx)),
-      remote_pool_id, m_remote_image_id);
+      m_client_id, remote_pool_id, m_remote_image_id);
 
     bootstrap();
   }
@@ -187,7 +186,7 @@ public:
   void get_commit_positions(int64_t *master_tid_p, int64_t *mirror_tid_p)
   {
     std::string master_client_id = "";
-    std::string mirror_client_id = m_local_cluster_id;
+    std::string mirror_client_id = m_client_id;
 
     C_SaferCond cond;
     uint64_t minimum_set;
@@ -311,7 +310,7 @@ public:
   static int _image_number;
 
   librados::Rados m_local_cluster, m_remote_cluster;
-  std::string m_local_cluster_id;
+  std::string m_client_id;
   std::string m_local_pool_name, m_remote_pool_name;
   librados::IoCtx m_local_ioctx, m_remote_ioctx;
   std::string m_image_name;
index 70c8e2c605f812dffbfc83bcd7a397dc1e758bed..d2a3077b9a31aa2bcbd284dad305d3c611b7f87a 100644 (file)
@@ -64,10 +64,12 @@ struct C_ReplayCommitted : public Context {
 } // anonymous namespace
 
 ImageReplayer::ImageReplayer(RadosRef local, RadosRef remote,
+                            const std::string &client_id,
                             int64_t remote_pool_id,
                             const std::string &remote_image_id) :
   m_local(local),
   m_remote(remote),
+  m_client_id(client_id),
   m_remote_pool_id(remote_pool_id),
   m_local_pool_id(-1),
   m_remote_image_id(remote_image_id),
@@ -109,15 +111,6 @@ int ImageReplayer::start(const BootstrapParams *bootstrap_params)
   bool registered;
   int r = 0;
 
-  r = m_local->cluster_fsid(&m_local_cluster_id);
-  if (r < 0) {
-    derr << "error retrieving local cluster id: " << cpp_strerror(r)
-        << dendl;
-    return r;
-  }
-
-  m_client_id = m_local_cluster_id;
-
   r = m_remote->ioctx_create2(m_remote_pool_id, m_remote_ioctx);
   if (r < 0) {
     derr << "error opening ioctx for remote pool " << m_remote_pool_id
@@ -448,12 +441,20 @@ int ImageReplayer::register_client()
 {
   int r;
 
-  dout(20) << "m_cluster_id=" << m_local_cluster_id << ", pool_id="
+  std::string local_cluster_id;
+  r = m_local->cluster_fsid(&local_cluster_id);
+  if (r < 0) {
+    derr << "error retrieving local cluster id: " << cpp_strerror(r)
+        << dendl;
+    return r;
+  }
+
+  dout(20) << "m_cluster_id=" << local_cluster_id << ", pool_id="
           << m_local_pool_id << ", image_id=" << m_local_image_id << dendl;
 
   bufferlist client_data;
   ::encode(librbd::journal::ClientData{librbd::journal::MirrorPeerClientMeta{
-       m_local_cluster_id, m_local_pool_id, m_local_image_id}}, client_data);
+       local_cluster_id, m_local_pool_id, m_local_image_id}}, client_data);
 
   r = m_remote_journaler->register_client(client_data);
   if (r < 0) {
@@ -611,7 +612,7 @@ int ImageReplayer::copy()
           << m_local_pool_id << "/" << m_local_image_id << dendl;
 
   // TODO: use internal snapshots
-  std::string snap_name = ".rbd-mirror." + m_local_cluster_id;
+  std::string snap_name = ".rbd-mirror." + m_client_id;
   librados::IoCtx local_ioctx;
   librbd::ImageCtx *remote_image_ctx, *local_image_ctx;
   librbd::NoOpProgressContext prog_ctx;
index c80e403db7051a614ff78a794c53fa88ed26ac1d..71f659fbf90954ba99c76fc59514eddb4d56ca41 100644 (file)
@@ -62,8 +62,8 @@ public:
   };
 
 public:
-  ImageReplayer(RadosRef local, RadosRef remote, int64_t remote_pool_id,
-               const std::string &remote_image_id);
+  ImageReplayer(RadosRef local, RadosRef remote, const std::string &client_id,
+               int64_t remote_pool_id, const std::string &remote_image_id);
   virtual ~ImageReplayer();
   ImageReplayer(const ImageReplayer&) = delete;
   ImageReplayer& operator=(const ImageReplayer&) = delete;
@@ -95,10 +95,9 @@ private:
                                  const ImageReplayer &replayer);
 private:
   RadosRef m_local, m_remote;
+  std::string m_client_id;
   int64_t m_remote_pool_id, m_local_pool_id;
-  std::string m_local_cluster_id;
   std::string m_remote_image_id, m_local_image_id;
-  std::string m_client_id;
   Mutex m_lock;
   State m_state;
   std::string m_local_pool_name, m_remote_pool_name;
index dd92b99ee398c6526fa7b6912d50280f84216ba4..0d8e3f329fe4a4a1a70aeadc282c5e2dd31c4711 100644 (file)
@@ -68,6 +68,15 @@ int Replayer::init()
 
   dout(20) << __func__ << "connected to " << m_peer << dendl;
 
+  std::string uuid;
+  r = m_local->cluster_fsid(&uuid);
+  if (r < 0) {
+    derr << "error retrieving local cluster uuid: " << cpp_strerror(r)
+        << dendl;
+    return r;
+  }
+  m_client_id = uuid;
+
   // TODO: make interval configurable
   m_pool_watcher.reset(new PoolWatcher(m_remote, 30, m_lock, m_cond));
   m_pool_watcher->refresh_images();
@@ -115,6 +124,7 @@ void Replayer::set_sources(const map<int64_t, set<string> > &images)
       if (pool_replayers.find(image_id) == pool_replayers.end()) {
        unique_ptr<ImageReplayer> image_replayer(new ImageReplayer(m_local,
                                                                   m_remote,
+                                                                  m_client_id,
                                                                   pool_id,
                                                                   image_id));
        int r = image_replayer->start();
index ca4d3e7fc66544c87cdb3157762056581ab2d818..373cddf34db2b0c54edbcc9a1a703a6170878e2c 100644 (file)
@@ -45,6 +45,7 @@ private:
   atomic_t m_stopping;
 
   peer_t m_peer;
+  std::string m_client_id;
   RadosRef m_local, m_remote;
   std::unique_ptr<PoolWatcher> m_pool_watcher;
   // index by pool so it's easy to tell what is affected