]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/crimson/seastore/test_omap_manager: test omap_iterate()
authorchunmei liu <chunmei.liu@ibm.com>
Thu, 20 Mar 2025 01:48:59 +0000 (18:48 -0700)
committerchunmei liu <chunmei.liu@ibm.com>
Tue, 15 Jul 2025 02:58:30 +0000 (19:58 -0700)
Signed-off-by: chunmei liu <chunmei.liu@ibm.com>
src/test/crimson/seastore/test_omap_manager.cc

index b2c7307f09a8edb73d4abac06485777b49810661..a0e679a3d31f9c13f100980b87ae87f9fae06627 100644 (file)
@@ -232,6 +232,65 @@ struct omap_manager_test_t :
     }
   }
 
+  ObjectStore::omap_iter_ret_t  check_iterate(std::string_view key,
+                                              std::string_view val,
+                                              ObjectStore::omap_iter_seek_t &start_from)
+  {
+    static uint32_t current_index = 0;
+    static uint32_t last_index = 0;
+    static bool check_start = true;
+
+    if (check_start && start_from.seek_position != "") {
+      if (start_from.seek_type == ObjectStore::omap_iter_seek_t::LOWER_BOUND) {
+        EXPECT_TRUE(start_from.seek_position == key);
+      } else {
+        EXPECT_TRUE(start_from.seek_position < key);
+      }
+      check_start = false;
+    }
+
+    auto iter = test_omap_mappings.find(std::string(key));
+    EXPECT_TRUE(iter != test_omap_mappings.end());
+    ceph::bufferlist bl = iter->second;
+    std::string result(bl.c_str(), bl.length());
+    EXPECT_TRUE(result == val);
+    current_index = std::distance(test_omap_mappings.begin(), iter);
+    if (last_index != 0) {
+      EXPECT_EQ(last_index + 1, current_index);
+    }
+    last_index = current_index;
+
+    if (current_index > test_omap_mappings.size() - 10) {
+      current_index = 0;
+      last_index = 0;
+      check_start = true;
+      return ObjectStore::omap_iter_ret_t::STOP;
+    } else {
+      return ObjectStore::omap_iter_ret_t::NEXT;
+    }
+ }
+
+  void iterate(
+    const omap_root_t &omap_root,
+    Transaction &t,
+    ObjectStore::omap_iter_seek_t &start_from,
+    OMapManager::omap_iterate_cb_t callback) {
+
+    if (start_from.seek_type == ObjectStore::omap_iter_seek_t::LOWER_BOUND) {
+      logger().debug("iterate lower bound on {}", start_from.seek_position);
+    } else {
+      logger().debug("iterate upper bound on {}", start_from.seek_position);
+    }
+
+    auto ret = with_trans_intr(
+      t,
+      [&, this](auto &t) {
+        return omap_manager->omap_iterate(omap_root, t, start_from, callback);
+      }).unsafe_get();
+
+    EXPECT_EQ(ret, ObjectStore::omap_iter_ret_t::STOP);
+  }
+
   void clear(
     omap_root_t &omap_root,
     Transaction &t) {
@@ -584,7 +643,6 @@ TEST_P(omap_manager_test_t, force_inner_node_split_list_rmkey_range)
   });
 }
 
-
 TEST_P(omap_manager_test_t, internal_force_split)
 {
   run_async([this] {
@@ -721,6 +779,60 @@ TEST_P(omap_manager_test_t, internal_force_split_to_root)
   });
 }
 
+TEST_P(omap_manager_test_t, omap_iterate)
+{
+  run_async([this] {
+    omap_root_t omap_root = initialize();
+
+    std::string lower_key;
+    std::string upper_key;
+    ObjectStore::omap_iter_seek_t start_from;
+
+    for (unsigned i = 0; i < 40; i++) {
+      auto t = create_mutate_transaction();
+      logger().debug("opened transaction");
+      for (unsigned j = 0; j < 10; ++j) {
+        auto key = set_random_key(omap_root, *t);
+        if (i == 3) {
+          lower_key = key;
+        }
+        if (i == 5) {
+          upper_key = key;
+        }
+      }
+      submit_transaction(std::move(t));
+    }
+    std::function<ObjectStore::omap_iter_ret_t(std::string_view, std::string_view)> callback =
+      [this, &start_from](std::string_view key, std::string_view val) {
+        return this->check_iterate(key, val, start_from);
+    };
+    {
+      start_from.seek_position = lower_key;
+      start_from.seek_type = ObjectStore::omap_iter_seek_t::LOWER_BOUND;
+      auto t = create_read_transaction();
+      iterate(omap_root, *t, start_from, callback);
+    }
+
+    {
+      start_from.seek_position = upper_key;
+      start_from.seek_type = ObjectStore::omap_iter_seek_t::UPPER_BOUND;
+      auto t = create_read_transaction();
+      iterate(omap_root, *t, start_from, callback);
+    }
+
+    {
+      start_from = ObjectStore::omap_iter_seek_t::min_lower_bound();
+      auto t = create_read_transaction();
+      iterate(omap_root, *t, start_from, callback);
+    }
+    {
+      auto t = create_mutate_transaction();
+      clear(omap_root, *t);
+      submit_transaction(std::move(t));
+    }
+  });
+}
+
 INSTANTIATE_TEST_SUITE_P(
   omap_manager_test,
   omap_manager_test_t,