From 8dded956b314d2c71a355ffb35637f1e9e8b92fd Mon Sep 17 00:00:00 2001 From: N Balachandran Date: Fri, 7 Mar 2025 12:56:35 +0530 Subject: [PATCH] rbd-mirror: fix image map notifications for groups The Group replayer Bootstrap now sends mirroring notifications when creating or deleting the local group. The ImageMap will only send the acquire_group notifications once for each group. Signed-off-by: N Balachandran --- qa/workunits/rbd/rbd_mirror_group_simple.sh | 4 +-- src/tools/rbd_mirror/ImageMap.cc | 2 +- .../group_replayer/BootstrapRequest.cc | 28 ++++++++++++++++++- .../group_replayer/BootstrapRequest.h | 3 ++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/qa/workunits/rbd/rbd_mirror_group_simple.sh b/qa/workunits/rbd/rbd_mirror_group_simple.sh index 1a05189056967..5c1f1dfba6d0e 100755 --- a/qa/workunits/rbd/rbd_mirror_group_simple.sh +++ b/qa/workunits/rbd/rbd_mirror_group_simple.sh @@ -395,7 +395,7 @@ test_create_group_stop_daemon_then_recreate() wait_for_group_status_in_pool_dir "${secondary_cluster}" "${pool}"/"${group}" 'up+replaying' 0 count_omap_keys_with_filter "${secondary_cluster}" "${pool}" "rbd_mirror_leader" "image_map" key_count - test "${key_count}" = 2 || fail "unexpected key count:${key_count}" + test "${key_count}" = 1 || fail "unexpected key count:${key_count}" elif [ "${scenario}" = 'stop_restart_after_recreate' ]; then echo "stopping daemon on secondary" stop_mirrors "${secondary_cluster}" @@ -413,7 +413,7 @@ test_create_group_stop_daemon_then_recreate() wait_for_group_status_in_pool_dir "${secondary_cluster}" "${pool}"/"${group}" 'up+replaying' 0 count_omap_keys_with_filter "${secondary_cluster}" "${pool}" "rbd_mirror_leader" "image_map" key_count - test "${key_count}" = 2 || fail "unexpected key count:${key_count}" + test "${key_count}" = 1 || fail "unexpected key count:${key_count}" fi mirror_group_disable "${primary_cluster}" "${pool}/${group}" diff --git a/src/tools/rbd_mirror/ImageMap.cc b/src/tools/rbd_mirror/ImageMap.cc index db76bceeab0f7..3131cbf91b786 100644 --- a/src/tools/rbd_mirror/ImageMap.cc +++ b/src/tools/rbd_mirror/ImageMap.cc @@ -430,7 +430,7 @@ void ImageMap::update_images_added( for (auto &entity : entities) { auto global_id = GlobalId(entity.type, entity.global_id); auto result = m_peer_map[global_id].insert(mirror_uuid); - if ((result.second && m_peer_map[global_id].size() == 1) || entity.type == MIRROR_ENTITY_TYPE_GROUP) { + if ((result.second && m_peer_map[global_id].size() == 1)) { if (m_policy->add_entity(global_id, entity.count)) { schedule_action(global_id); } diff --git a/src/tools/rbd_mirror/group_replayer/BootstrapRequest.cc b/src/tools/rbd_mirror/group_replayer/BootstrapRequest.cc index 28b6756bab3c0..23ade4c5ff0cb 100644 --- a/src/tools/rbd_mirror/group_replayer/BootstrapRequest.cc +++ b/src/tools/rbd_mirror/group_replayer/BootstrapRequest.cc @@ -10,6 +10,7 @@ #include "librbd/internal.h" #include "librbd/group/ListSnapshotsRequest.h" #include "librbd/group/RemoveImageRequest.h" +#include "librbd/MirroringWatcher.h" #include "librbd/Utils.h" #include "tools/rbd_mirror/ImageReplayer.h" #include "tools/rbd_mirror/PoolMetaCache.h" @@ -1162,7 +1163,7 @@ void BootstrapRequest::handle_remove_local_group_id(int r) { return; } - finish(0); + notify_mirroring_watcher(); } template @@ -1309,6 +1310,31 @@ void BootstrapRequest::handle_create_local_non_primary_group_snapshot(int r) return; } + notify_mirroring_watcher(); +} + +template +void BootstrapRequest::notify_mirroring_watcher() { + dout(10) << dendl; + + auto ctx = create_context_callback< + BootstrapRequest, + &BootstrapRequest::handle_notify_mirroring_watcher>(this); + + librbd::MirroringWatcher::notify_group_updated( + m_local_io_ctx, m_local_mirror_group.state, *m_local_group_id, + m_global_group_id, m_local_images.size(), ctx); +} + +template +void BootstrapRequest::handle_notify_mirroring_watcher(int r) { + dout(10) << "r=" << r << dendl; + + if (r < 0) { + derr << "failed to notify mirror group update: " << cpp_strerror(r) + << dendl; + } + finish(0); } diff --git a/src/tools/rbd_mirror/group_replayer/BootstrapRequest.h b/src/tools/rbd_mirror/group_replayer/BootstrapRequest.h index 514ecb38084f4..0f6fcc6f64bd9 100644 --- a/src/tools/rbd_mirror/group_replayer/BootstrapRequest.h +++ b/src/tools/rbd_mirror/group_replayer/BootstrapRequest.h @@ -272,6 +272,9 @@ private: void create_local_non_primary_group_snapshot(); void handle_create_local_non_primary_group_snapshot(int r); + void notify_mirroring_watcher(); + void handle_notify_mirroring_watcher(int r); + void finish(int r); int create_replayers(); -- 2.39.5