]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: strengthen is_local_primary() and is_linked()
authorIlya Dryomov <idryomov@gmail.com>
Sat, 18 Jun 2022 10:35:51 +0000 (12:35 +0200)
committerIlya Dryomov <idryomov@gmail.com>
Wed, 22 Jun 2022 12:33:07 +0000 (14:33 +0200)
Initialize local_promotion_state and remote_promotion_state to UNKNOWN
instead of counterintuitive PRIMARY and NON_PRIMARY -- half the time the
final values are flipped.  Then is_local_primary() and is_linked() can
be strengthened as a non-existent image should stay in UNKNOWN.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit c60f1d5813c7fe248593731bbffb43d12cdd3b62)

src/tools/rbd_mirror/image_replayer/StateBuilder.cc
src/tools/rbd_mirror/image_replayer/StateBuilder.h

index 3c7274ec56e56ce736c87f555dae865ad2bc1e89..c8649ab2fa83e87a0f7427d2dcbab043baa47fea 100644 (file)
@@ -36,16 +36,21 @@ StateBuilder<I>::~StateBuilder() {
 }
 
 template <typename I>
-bool StateBuilder<I>::is_local_primary() const  {
-  return (!local_image_id.empty() &&
-          local_promotion_state == librbd::mirror::PROMOTION_STATE_PRIMARY);
+bool StateBuilder<I>::is_local_primary() const {
+  if (local_promotion_state == librbd::mirror::PROMOTION_STATE_PRIMARY) {
+    ceph_assert(!local_image_id.empty());
+    return true;
+  }
+  return false;
 }
 
 template <typename I>
 bool StateBuilder<I>::is_linked() const {
-  return ((local_promotion_state ==
-             librbd::mirror::PROMOTION_STATE_NON_PRIMARY) &&
-          is_linked_impl());
+  if (local_promotion_state == librbd::mirror::PROMOTION_STATE_NON_PRIMARY) {
+    ceph_assert(!local_image_id.empty());
+    return is_linked_impl();
+  }
+  return false;
 }
 
 template <typename I>
index 99007ba5e21a8b8469075cffe3070e6a7c3538fd..4c839a3efcee2effbeb5be536793b8ecf3f0f5a4 100644 (file)
@@ -81,13 +81,13 @@ public:
 
   std::string local_image_id;
   librbd::mirror::PromotionState local_promotion_state =
-    librbd::mirror::PROMOTION_STATE_PRIMARY;
+    librbd::mirror::PROMOTION_STATE_UNKNOWN;
   ImageCtxT* local_image_ctx = nullptr;
 
   std::string remote_mirror_uuid;
   std::string remote_image_id;
   librbd::mirror::PromotionState remote_promotion_state =
-    librbd::mirror::PROMOTION_STATE_NON_PRIMARY;
+    librbd::mirror::PROMOTION_STATE_UNKNOWN;
   ImageCtxT* remote_image_ctx = nullptr;
 
 protected: