]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/librados: increase pgp_num along with pg_num
authorKefu Chai <kchai@redhat.com>
Fri, 20 Apr 2018 11:06:10 +0000 (19:06 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 24 Apr 2018 02:16:12 +0000 (10:16 +0800)
Fixes: http://tracker.ceph.com/issues/23763
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/test/librados/list.cc
src/test/librados/test_common.cc
src/test/librados/test_common.h

index 860ccb5b663ab7576ae111e6ffd8e869608e1a6c..74000ac2da5dda39fcb0a37d1aa7195dd06b6360 100644 (file)
@@ -1002,8 +1002,8 @@ TEST_F(LibRadosList, EnumerateObjects) {
 
   // Ensure a non-power-of-two PG count to avoid only
   // touching the easy path.
-  std::string err_str = set_pg_num(&s_cluster, pool_name, 11);
-  ASSERT_TRUE(err_str.empty());
+  ASSERT_TRUE(set_pg_num(&s_cluster, pool_name, 11).empty());
+  ASSERT_TRUE(set_pgp_num(&s_cluster, pool_name, 11).empty());
 
   std::set<std::string> saw_obj;
   rados_object_list_cursor c = rados_object_list_begin(ioctx);
@@ -1050,8 +1050,8 @@ TEST_F(LibRadosList, EnumerateObjectsSplit) {
 
   // Ensure a non-power-of-two PG count to avoid only
   // touching the easy path.
-  std::string err_str = set_pg_num(&s_cluster, pool_name, 11);
-  ASSERT_TRUE(err_str.empty());
+  ASSERT_TRUE(set_pg_num(&s_cluster, pool_name, 11).empty());
+  ASSERT_TRUE(set_pgp_num(&s_cluster, pool_name, 11).empty());
 
   rados_object_list_cursor begin = rados_object_list_begin(ioctx);
   rados_object_list_cursor end = rados_object_list_end(ioctx);
index c276d33ff7973688b97daeff0485ec39e8e8e9a2..f617fa6bca7e034826c2ef9e6f2b84425ff2dff0 100644 (file)
@@ -101,34 +101,65 @@ int rados_pool_set(
   return ret;
 }
 
-}
-
-std::string set_pg_num(
-    rados_t *cluster, const std::string &pool_name, uint32_t pg_num)
-{
-  // Wait for 'creating' to clear
-  int r = wait_for_healthy(cluster);
-  if (r != 0) {
-    goto err;
+struct pool_op_error : std::exception {
+  string msg;
+  pool_op_error(const std::string& pool_name,
+               const std::string& func_name,
+               int err) {
+    std::ostringstream oss;
+    oss << func_name << "(" << pool_name << ") failed with error " << err;
+    msg = oss.str();
   }
-
-  // Adjust pg_num
-  r = rados_pool_set(cluster, pool_name, "pg_num", stringify(pg_num));
-  if (r != 0) {
-    goto err;
+  const char* what() const noexcept override {
+    return msg.c_str();
   }
+};
 
-  // Wait for 'creating' to clear
-  r = wait_for_healthy(cluster);
-  if (r != 0) {
-    goto err;
+template<typename Func>
+std::string with_healthy_cluster(rados_t* cluster,
+                                const std::string& pool_name,
+                                Func&& func)
+{
+  try {
+    // Wait for 'creating/backfilling' to clear
+    if (int r = wait_for_healthy(cluster); r != 0) {
+      throw pool_op_error{pool_name, "wait_for_healthy", r};
+    }
+    func();
+    // Wait for 'creating/backfilling' to clear
+    if (int r = wait_for_healthy(cluster); r != 0) {
+      throw pool_op_error{pool_name, "wait_for_healthy", r};
+    }
+  } catch (const pool_op_error& e) {
+    rados_shutdown(*cluster);
+    return e.what();
   }
-
   return "";
+}
+}
+
+std::string set_pg_num(
+    rados_t *cluster, const std::string &pool_name, uint32_t pg_num)
+{
+  return with_healthy_cluster(cluster, pool_name, [&] {
+    // Adjust pg_num
+      if (int r = rados_pool_set(cluster, pool_name, "pg_num",
+                                stringify(pg_num));
+         r != 0) {
+       throw pool_op_error{pool_name, "set_pg_num", r};
+      }
+  });
+}
 
-err:
-  rados_shutdown(*cluster);
-  std::ostringstream oss;
-  oss << __func__ << "(" << pool_name << ") failed with error " << r;
-  return oss.str();
+std::string set_pgp_num(
+    rados_t *cluster, const std::string &pool_name, uint32_t pgp_num)
+{
+  return with_healthy_cluster(cluster, pool_name, [&] {
+    // Adjust pgp_num
+    if (int r = rados_pool_set(cluster, pool_name, "pgp_num",
+                              stringify(pgp_num));
+       r != 0) {
+      throw pool_op_error{pool_name, "set_pgp_num", r};
+    }
+  });
 }
index f3f1bdc494f10b55136e917c19be3ae0fb30afd7..71ef9de2cf5fc28d33e1dbba23d26b55e6b4f570 100644 (file)
@@ -5,3 +5,5 @@
 
 std::string set_pg_num(
     rados_t *cluster, const std::string &pool_name, uint32_t pg_num);
+std::string set_pgp_num(
+    rados_t *cluster, const std::string &pool_name, uint32_t pgp_num);