]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/crimson/seastore/test_collection_manager.cc
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / test / crimson / seastore / test_collection_manager.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "os/ObjectStore.h"
5 #include "test/crimson/gtest_seastar.h"
6 #include "test/crimson/seastore/transaction_manager_test_state.h"
7
8 #include "crimson/os/seastore/cache.h"
9 #include "crimson/os/seastore/transaction_manager.h"
10 #include "crimson/os/seastore/segment_manager.h"
11 #include "crimson/os/seastore/collection_manager.h"
12
13 #include "test/crimson/seastore/test_block.h"
14
15 using namespace crimson;
16 using namespace crimson::os;
17 using namespace crimson::os::seastore;
18
19 namespace {
20 [[maybe_unused]] seastar::logger& logger() {
21 return crimson::get_logger(ceph_subsys_test);
22 }
23 }
24
25
26 #define TEST_COLL_FORWARD(METHOD) \
27 template <typename... Args> \
28 auto METHOD(coll_root_t &root, Transaction &t, Args&&... args) const { \
29 return with_trans_intr( \
30 t, \
31 [this](auto &t, auto &root, auto&&... args) { \
32 return collection_manager->METHOD( \
33 root, \
34 t, \
35 std::forward<decltype(args)>(args)...); \
36 }, \
37 root, \
38 std::forward<Args>(args)...).unsafe_get0(); \
39 }
40
41 struct collection_manager_test_t :
42 public seastar_test_suite_t,
43 TMTestState {
44
45 CollectionManagerRef collection_manager;
46
47 collection_manager_test_t() {}
48
49 seastar::future<> set_up_fut() final {
50 return tm_setup().then([this] {
51 collection_manager = collection_manager::create_coll_manager(*tm);
52 return seastar::now();
53 });
54 }
55
56 seastar::future<> tear_down_fut() final {
57 return tm_teardown().then([this] {
58 collection_manager.reset();
59 return seastar::now();
60 });
61 }
62
63 using test_collection_t = std::map<coll_t, coll_info_t>;
64 test_collection_t test_coll_mappings;
65
66 void replay() {
67 restart();
68 collection_manager = collection_manager::create_coll_manager(*tm);
69 }
70
71 auto get_root() {
72 auto tref = create_mutate_transaction();
73 auto coll_root = with_trans_intr(
74 *tref,
75 [this](auto &t) {
76 return collection_manager->mkfs(t);
77 }).unsafe_get0();
78 submit_transaction(std::move(tref));
79 return coll_root;
80 }
81
82 TEST_COLL_FORWARD(remove)
83 TEST_COLL_FORWARD(list)
84 TEST_COLL_FORWARD(create)
85 TEST_COLL_FORWARD(update)
86
87 void checking_mappings(coll_root_t &coll_root, Transaction &t) {
88 auto coll_list = list(coll_root, t);
89 EXPECT_EQ(test_coll_mappings.size(), coll_list.size());
90 for (std::pair<coll_t, coll_info_t> p : test_coll_mappings) {
91 EXPECT_NE(
92 std::find(coll_list.begin(), coll_list.end(), p),
93 coll_list.end());
94 }
95 }
96
97 void checking_mappings(coll_root_t &coll_root) {
98 auto t = create_read_transaction();
99 checking_mappings(coll_root, *t);
100 }
101 };
102
103 TEST_P(collection_manager_test_t, basic)
104 {
105 run_async([this] {
106 coll_root_t coll_root = get_root();
107 {
108 auto t = create_mutate_transaction();
109 for (int i = 0; i < 20; i++) {
110 coll_t cid(spg_t(pg_t(i+1,i+2), shard_id_t::NO_SHARD));
111 create(coll_root, *t, cid, coll_info_t(i));
112 test_coll_mappings.emplace(cid, coll_info_t(i));
113 }
114 checking_mappings(coll_root, *t);
115 submit_transaction(std::move(t));
116 EXPECT_EQ(test_coll_mappings.size(), 20);
117 }
118
119 replay();
120 checking_mappings(coll_root);
121 {
122 auto t = create_mutate_transaction();
123 for (auto iter = test_coll_mappings.begin();
124 iter != test_coll_mappings.end();) {
125 remove(coll_root, *t, iter->first);
126 iter = test_coll_mappings.erase(iter);
127 }
128 submit_transaction(std::move(t));
129 }
130 replay();
131 {
132 auto t = create_mutate_transaction();
133 auto list_ret = list(coll_root, *t);
134 submit_transaction(std::move(t));
135 EXPECT_EQ(list_ret.size(), test_coll_mappings.size());
136 }
137 });
138 }
139
140 TEST_P(collection_manager_test_t, overflow)
141 {
142 run_async([this] {
143 coll_root_t coll_root = get_root();
144 auto old_location = coll_root.get_location();
145
146 auto t = create_mutate_transaction();
147 for (int i = 0; i < 412; i++) {
148 coll_t cid(spg_t(pg_t(i+1,i+2), shard_id_t::NO_SHARD));
149 create(coll_root, *t, cid, coll_info_t(i));
150 test_coll_mappings.emplace(cid, coll_info_t(i));
151 }
152 submit_transaction(std::move(t));
153 EXPECT_NE(old_location, coll_root.get_location());
154 checking_mappings(coll_root);
155
156 replay();
157 checking_mappings(coll_root);
158 });
159 }
160
161 TEST_P(collection_manager_test_t, update)
162 {
163 run_async([this] {
164 coll_root_t coll_root = get_root();
165 {
166 auto t = create_mutate_transaction();
167 for (int i = 0; i < 2; i++) {
168 coll_t cid(spg_t(pg_t(1,i+1), shard_id_t::NO_SHARD));
169 create(coll_root, *t, cid, coll_info_t(i));
170 test_coll_mappings.emplace(cid, coll_info_t(i));
171 }
172 submit_transaction(std::move(t));
173 }
174 {
175 auto iter1= test_coll_mappings.begin();
176 auto iter2 = std::next(test_coll_mappings.begin(), 1);
177 EXPECT_NE(iter1->second.split_bits, iter2->second.split_bits);
178 auto t = create_mutate_transaction();
179 update(coll_root, *t, iter1->first, iter2->second);
180 submit_transaction(std::move(t));
181 iter1->second.split_bits = iter2->second.split_bits;
182 }
183 replay();
184 checking_mappings(coll_root);
185 });
186 }
187
188 INSTANTIATE_TEST_SUITE_P(
189 collection_manager_test,
190 collection_manager_test_t,
191 ::testing::Values (
192 "segmented",
193 "circularbounded"
194 )
195 );