]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/neorados/list_pool.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2019 Red Hat <contact@redhat.com>
7 * Author: Adam C. Emerson <aemerson@redhat.com>
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
17 #include <initializer_list>
21 #include <string_view>
24 #include <sys/param.h>
28 #include <boost/system/system_error.hpp>
30 #include <fmt/format.h>
32 #include "include/neorados/RADOS.hpp"
34 #include "include/scope_guard.h"
36 #include "common/async/context_pool.h"
37 #include "common/ceph_time.h"
38 #include "common/ceph_argparse.h"
39 #include "common/async/blocked_completion.h"
41 #include "global/global_init.h"
43 #include "test/neorados/common_tests.h"
46 namespace ba
= boost::asio
;
47 namespace bs
= boost::system
;
48 namespace ca
= ceph::async
;
49 namespace R
= neorados
;
51 std::string_view
hostname() {
52 static char hostname
[MAXHOSTNAMELEN
] = { 0 };
53 static size_t len
= 0;
55 auto r
= gethostname(hostname
, sizeof(hostname
));
57 throw bs::system_error(
58 errno
, bs::system_category());
60 len
= std::strlen(hostname
);
62 return {hostname
, len
};
65 std::string
temp_pool_name(const std::string_view prefix
)
67 using namespace std::chrono
;
68 static std::uint64_t num
= 1;
74 duration_cast
<milliseconds
>(ceph::coarse_real_clock::now()
75 .time_since_epoch()).count(),
79 bs::error_code
noisy_list(R::RADOS
& r
, int64_t p
)
81 auto b
= R::Cursor::begin();
82 auto e
= R::Cursor::end();
84 std::cout
<< "begin = " << b
.to_str() << std::endl
;
85 std::cout
<< "end = " << e
.to_str() << std::endl
;
87 auto [v
, next
] = r
.enumerate_objects(p
, b
, e
, 1000, {}, ca::use_blocked
,
90 std::cout
<< "Got " << v
.size() << " entries." << std::endl
;
91 std::cout
<< "next cursor = " << next
.to_str() << std::endl
;
92 std::cout
<< "next == end: " << (next
== e
) << std::endl
;
93 std::cout
<< "Returned Objects: ";
96 while (o
!= v
.cend()) {
101 std::cout
<< "]" << std::endl
;
102 } catch (const bs::system_error
& e
) {
103 std::cerr
<< "RADOS::enumerate_objects: " << e
.what() << std::endl
;
109 bs::error_code
create_several(R::RADOS
& r
, const R::IOContext
& i
,
110 std::initializer_list
<std::string
> l
)
112 for (const auto& o
: l
) try {
114 std::cout
<< "Creating " << o
<< std::endl
;
116 bl
.append("My bologna has no name.");
117 op
.write_full(std::move(bl
));
118 r
.execute(o
, i
, std::move(op
), ca::use_blocked
);
119 } catch (const bs::system_error
& e
) {
120 std::cerr
<< "RADOS::execute: " << e
.what() << std::endl
;
126 int main(int argc
, char** argv
)
128 using namespace std::literals
;
130 std::vector
<const char*> args
;
131 argv_to_vec(argc
, const_cast<const char**>(argv
), args
);
134 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
135 CODE_ENVIRONMENT_UTILITY
, 0);
136 common_init_finish(cct
.get());
139 ca::io_context_pool
p(1);
140 auto r
= R::RADOS::make_with_cct(cct
.get(), p
, ca::use_blocked
);
142 auto pool_name
= get_temp_pool_name("ceph_test_RADOS_list_pool"sv
);
143 r
.create_pool(pool_name
, std::nullopt
, ca::use_blocked
);
144 auto pd
= make_scope_guard(
146 r
.delete_pool(pool_name
, ca::use_blocked
);
148 auto pool
= r
.lookup_pool(pool_name
, ca::use_blocked
);
149 R::IOContext
i(pool
);
151 if (noisy_list(r
, pool
)) {
154 if (create_several(r
, i
, {"meow", "woof", "squeak"})) {
157 if (noisy_list(r
, pool
)) {
161 } catch (const bs::system_error
& e
) {
162 std::cerr
<< "Error: " << e
.what() << std::endl
;