From: Adam C. Emerson Date: Wed, 23 Oct 2019 20:32:07 +0000 (-0400) Subject: RADOS: Test object enumeration X-Git-Tag: v15.1.0~843^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=81c72ba237004c5ae930e1200c8cc1ed8a7ac6e8;p=ceph.git RADOS: Test object enumeration Signed-off-by: Adam C. Emerson --- diff --git a/src/test/RADOS/CMakeLists.txt b/src/test/RADOS/CMakeLists.txt index b8df256fd465..e95fbc47ec33 100644 --- a/src/test/RADOS/CMakeLists.txt +++ b/src/test/RADOS/CMakeLists.txt @@ -9,3 +9,7 @@ target_link_libraries(ceph_test_RADOS_completions Boost::system pthread add_executable(ceph_test_RADOS_op_speed op_speed.cc) target_link_libraries(ceph_test_RADOS_op_speed global libRADOS fmt::fmt ${unittest_libs}) + +add_executable(ceph_test_RADOS_list_pool list_pool.cc) +target_link_libraries(ceph_test_RADOS_list_pool + global libRADOS fmt::fmt ${unittest_libs}) diff --git a/src/test/RADOS/list_pool.cc b/src/test/RADOS/list_pool.cc new file mode 100644 index 000000000000..5d5cb3dfd4ed --- /dev/null +++ b/src/test/RADOS/list_pool.cc @@ -0,0 +1,192 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2019 Red Hat + * Author: Adam C. Emerson + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include + +#include + +#include "include/RADOS/RADOS.hpp" + +#include "include/scope_guard.h" + +#include "common/async/context_pool.h" +#include "common/ceph_time.h" +#include "common/ceph_argparse.h" +#include "common/async/waiter.h" + +#include "global/global_init.h" + +std::string_view hostname() { + static char hostname[MAXHOSTNAMELEN] = { 0 }; + static size_t len = 0; + if (!len) { + auto r = gethostname(hostname, sizeof(hostname)); + if (r != 0) { + throw boost::system::system_error( + errno, boost::system::system_category()); + } + len = std::strlen(hostname); + } + return {hostname, len}; +} + +std::string temp_pool_name(const std::string_view prefix) +{ + using namespace std::chrono; + static std::uint64_t num = 1; + return fmt::format( + "{}-{}-{}-{}-{}", + prefix, + hostname(), + getpid(), + duration_cast(ceph::coarse_real_clock::now() + .time_since_epoch()).count(), + num++); +} + +boost::system::error_code noisy_list(RADOS::RADOS& r, + int64_t p) { + ceph::async::waiter w; + RADOS::Cursor next; + std::vector v; + auto b = RADOS::Cursor::begin(); + auto e = RADOS::Cursor::end(); + + std::cout << "begin = " << b.to_str() << std::endl; + std::cout << "end = " << e.to_str() << std::endl; + r.enumerate_objects(p, b, e, 1000, {}, &v, &next, w, + RADOS::all_nspaces); + auto ec = w.wait(); + if (ec) { + std::cerr << "RADOS::enumerate_objects: " << ec << std::endl; + return ec; + } + + std::cout << "Got " << v.size() << " entries." << std::endl; + + std::cout << "next cursor = " << next.to_str() << std::endl; + std::cout << "next == end: " << (next == e) << std::endl; + std::cout << "Returned Objects: "; + std::cout << "["; + auto o = v.cbegin(); + while (o != v.cend()) { + std::cout << *o; + if (++o != v.cend()) + std::cout << " "; + } + std::cout << "]" << std::endl; + return {}; +} + +boost::system::error_code create_several(RADOS::RADOS& r, + const RADOS::IOContext& i, + std::initializer_list l) { + for (const auto& o : l) { + ceph::async::waiter w; + RADOS::WriteOp op; + std::cout << "Creating " << o << std::endl; + ceph::bufferlist bl; + bl.append("My bologna has no name."); + op.write_full(std::move(bl)); + r.execute(o, i, std::move(op), w); + auto ec = w.wait(); + if (ec) { + std::cerr << "RADOS::execute: " << ec << std::endl; + return ec; + } + } + return {}; +} + +int main(int argc, char** argv) +{ + using namespace std::literals; + + std::vector args; + argv_to_vec(argc, const_cast(argv), args); + env_to_vec(args); + + auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, + CODE_ENVIRONMENT_UTILITY, 0); + common_init_finish(cct.get()); + + ceph::async::io_context_pool p(1); + auto r = RADOS::RADOS::make_with_cct(cct.get(), p, + boost::asio::use_future).get(); + + auto pool_name = temp_pool_name("ceph_test_RADOS_list_pool"); + + { + ceph::async::waiter w; + r.create_pool(pool_name, std::nullopt, w); + auto ec = w.wait(); + if (ec) { + std::cerr << "RADOS::create_pool: " << ec << std::endl; + return 1; + } + } + + auto pd = make_scope_guard( + [&pool_name, &r]() { + ceph::async::waiter w; + r.delete_pool(pool_name, w); + auto ec = w.wait(); + if (ec) + std::cerr << "RADOS::delete_pool: " << ec << std::endl; + }); + + std::int64_t pool; + + { + ceph::async::waiter w; + r.lookup_pool(pool_name, w); + boost::system::error_code ec; + std::tie(ec, pool) = w.wait(); + if (ec) { + std::cerr << "RADOS::lookup_pool: " << ec << std::endl; + return 1; + } + } + + RADOS::IOContext i(pool); + + if (noisy_list(r, pool)) { + return 1; + } + + if (create_several(r, i, {"meow", "woof", "squeak"})) { + return 1; + } + + std::this_thread::sleep_for(5s); + + if (noisy_list(r, pool)) { + return 1; + } + + return 0; +}