]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: cluster watcher should periodically poll local site name
authorJason Dillaman <dillaman@redhat.com>
Wed, 25 Sep 2019 16:25:47 +0000 (12:25 -0400)
committerJason Dillaman <dillaman@redhat.com>
Tue, 8 Oct 2019 15:16:46 +0000 (11:16 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/rbd_mirror/test_ClusterWatcher.cc
src/tools/rbd_mirror/ClusterWatcher.cc
src/tools/rbd_mirror/ClusterWatcher.h

index 7ac01d5f71e9c35e5303e2515986ab2e802ba7a1..436ab008e228f2b23b11d7b8d58892fba801040b 100644 (file)
@@ -251,3 +251,16 @@ TEST_F(TestClusterWatcher, ConfigKey) {
 
   check_peers();
 }
+
+TEST_F(TestClusterWatcher, SiteName) {
+  REQUIRE(!is_librados_test_stub(*m_cluster));
+
+  std::string site_name;
+  librbd::RBD rbd;
+  ASSERT_EQ(0, rbd.mirror_site_name_get(*m_cluster, &site_name));
+
+  m_cluster_watcher->refresh_pools();
+
+  std::lock_guard l{m_lock};
+  ASSERT_EQ(site_name, m_cluster_watcher->get_site_name());
+}
index b9dd659659d9319d3e3eeb4a0f419804271e7a1b..3d381f3c9b182f63c58643402835b61eef9155c2 100644 (file)
@@ -43,6 +43,11 @@ const ClusterWatcher::PoolPeers& ClusterWatcher::get_pool_peers() const
   return m_pool_peers;
 }
 
+std::string ClusterWatcher::get_site_name() const {
+  ceph_assert(ceph_mutex_is_locked(m_lock));
+  return m_site_name;
+}
+
 void ClusterWatcher::refresh_pools()
 {
   dout(20) << "enter" << dendl;
@@ -50,8 +55,16 @@ void ClusterWatcher::refresh_pools()
   PoolPeers pool_peers;
   read_pool_peers(&pool_peers);
 
+  std::string site_name;
+  int r = read_site_name(&site_name);
+
   std::lock_guard l{m_lock};
   m_pool_peers = pool_peers;
+
+  if (r >= 0) {
+    m_site_name = site_name;
+  }
+
   // TODO: perhaps use a workqueue instead, once we get notifications
   // about config changes for existing pools
 }
@@ -163,6 +176,13 @@ void ClusterWatcher::read_pool_peers(PoolPeers *pool_peers)
   }
 }
 
+int ClusterWatcher::read_site_name(std::string* site_name) {
+  dout(10) << dendl;
+
+  librbd::RBD rbd;
+  return rbd.mirror_site_name_get(*m_cluster, site_name);
+}
+
 int ClusterWatcher::resolve_peer_config_keys(int64_t pool_id,
                                              const std::string& pool_name,
                                              PeerSpec* peer) {
index a5105e637b6f69ae8a00d916d3dbf8849937e0ec..ae3f210e07f7f59e6d50bdfc5dcba3743e332ff0 100644 (file)
@@ -46,6 +46,7 @@ public:
   // Caller controls frequency of calls
   void refresh_pools();
   const PoolPeers& get_pool_peers() const;
+  std::string get_site_name() const;
 
 private:
   typedef std::unordered_map<int64_t, service_daemon::CalloutId> ServicePools;
@@ -56,9 +57,12 @@ private:
 
   ServicePools m_service_pools;
   PoolPeers m_pool_peers;
+  std::string m_site_name;
 
   void read_pool_peers(PoolPeers *pool_peers);
 
+  int read_site_name(std::string* site_name);
+
   int resolve_peer_config_keys(int64_t pool_id, const std::string& pool_name,
                                PeerSpec* peer);
 };