From 3d2e5449f1a26046db964fbf67be3465dbf85042 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 20 Apr 2018 19:06:10 +0800 Subject: [PATCH] test/librados: increase pgp_num along with pg_num Fixes: http://tracker.ceph.com/issues/23763 Signed-off-by: Kefu Chai --- src/test/librados/list.cc | 8 ++-- src/test/librados/test_common.cc | 79 ++++++++++++++++++++++---------- src/test/librados/test_common.h | 2 + 3 files changed, 61 insertions(+), 28 deletions(-) diff --git a/src/test/librados/list.cc b/src/test/librados/list.cc index 860ccb5b663ab..74000ac2da5dd 100644 --- a/src/test/librados/list.cc +++ b/src/test/librados/list.cc @@ -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 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); diff --git a/src/test/librados/test_common.cc b/src/test/librados/test_common.cc index c276d33ff7973..f617fa6bca7e0 100644 --- a/src/test/librados/test_common.cc +++ b/src/test/librados/test_common.cc @@ -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 +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}; + } + }); } diff --git a/src/test/librados/test_common.h b/src/test/librados/test_common.h index f3f1bdc494f10..71ef9de2cf5fc 100644 --- a/src/test/librados/test_common.h +++ b/src/test/librados/test_common.h @@ -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); -- 2.39.5