From: Jason Dillaman Date: Wed, 25 Sep 2019 16:25:47 +0000 (-0400) Subject: rbd-mirror: cluster watcher should periodically poll local site name X-Git-Tag: v15.1.0~1245^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=08cf067b063b5e3d2264c67bf3a7a4badff75041;p=ceph.git rbd-mirror: cluster watcher should periodically poll local site name Signed-off-by: Jason Dillaman --- diff --git a/src/test/rbd_mirror/test_ClusterWatcher.cc b/src/test/rbd_mirror/test_ClusterWatcher.cc index 7ac01d5f71e..436ab008e22 100644 --- a/src/test/rbd_mirror/test_ClusterWatcher.cc +++ b/src/test/rbd_mirror/test_ClusterWatcher.cc @@ -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()); +} diff --git a/src/tools/rbd_mirror/ClusterWatcher.cc b/src/tools/rbd_mirror/ClusterWatcher.cc index b9dd659659d..3d381f3c9b1 100644 --- a/src/tools/rbd_mirror/ClusterWatcher.cc +++ b/src/tools/rbd_mirror/ClusterWatcher.cc @@ -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) { diff --git a/src/tools/rbd_mirror/ClusterWatcher.h b/src/tools/rbd_mirror/ClusterWatcher.h index a5105e637b6..ae3f210e07f 100644 --- a/src/tools/rbd_mirror/ClusterWatcher.h +++ b/src/tools/rbd_mirror/ClusterWatcher.h @@ -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 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); };