1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
6 #include "crimson/common/log.h"
8 #include "include/buffer.h"
9 #include "include/stringify.h"
10 #include "crimson/os/seastore/collection_manager/flat_collection_manager.h"
11 #include "crimson/os/seastore/collection_manager/collection_flat_node.h"
14 seastar::logger
& logger() {
15 return crimson::get_logger(ceph_subsys_seastore
);
19 namespace crimson::os::seastore::collection_manager
{
21 constexpr static extent_len_t MIN_FLAT_BLOCK_SIZE
= 4<<10;
22 [[maybe_unused
]] constexpr static extent_len_t MAX_FLAT_BLOCK_SIZE
= 4<<20;
24 FlatCollectionManager::FlatCollectionManager(
25 TransactionManager
&tm
)
28 FlatCollectionManager::mkfs_ret
29 FlatCollectionManager::mkfs(Transaction
&t
)
32 logger().debug("FlatCollectionManager: {}", __func__
);
33 return tm
.alloc_extent
<CollectionNode
>(
34 t
, L_ADDR_MIN
, MIN_FLAT_BLOCK_SIZE
35 ).si_then([](auto&& root_extent
) {
36 coll_root_t coll_root
= coll_root_t(
37 root_extent
->get_laddr(),
40 return mkfs_iertr::make_ready_future
<coll_root_t
>(coll_root
);
44 FlatCollectionManager::get_root_ret
45 FlatCollectionManager::get_coll_root(const coll_root_t
&coll_root
, Transaction
&t
)
47 logger().debug("FlatCollectionManager: {}", __func__
);
48 assert(coll_root
.get_location() != L_ADDR_NULL
);
49 auto cc
= get_coll_context(t
);
50 return cc
.tm
.read_extent
<CollectionNode
>(
52 coll_root
.get_location(),
54 ).si_then([](auto&& e
) {
55 return get_root_iertr::make_ready_future
<CollectionNodeRef
>(std::move(e
));
59 FlatCollectionManager::create_ret
60 FlatCollectionManager::create(coll_root_t
&coll_root
, Transaction
&t
,
61 coll_t cid
, coll_info_t info
)
63 logger().debug("FlatCollectionManager: {}", __func__
);
64 return get_coll_root(coll_root
, t
65 ).si_then([=, this, &coll_root
, &t
] (auto &&extent
) {
66 return extent
->create(
67 get_coll_context(t
), cid
, info
.split_bits
68 ).si_then([=, this, &coll_root
, &t
] (auto ret
) {
70 case CollectionNode::create_result_t::OVERFLOW
: {
71 logger().debug("FlatCollectionManager: {} overflow!", __func__
);
72 auto new_size
= coll_root
.get_size() * 2; // double each time
74 // TODO return error probably, but such a nonsensically large number of
75 // collections would create a ton of other problems as well
76 assert(new_size
< MAX_FLAT_BLOCK_SIZE
);
77 return tm
.alloc_extent
<CollectionNode
>(
78 t
, L_ADDR_MIN
, new_size
79 ).si_then([=, this, &coll_root
, &t
] (auto &&root_extent
) {
80 coll_root
.update(root_extent
->get_laddr(), root_extent
->get_length());
82 root_extent
->decoded
= extent
->decoded
;
83 return root_extent
->create(
84 get_coll_context(t
), cid
, info
.split_bits
85 ).si_then([=, this, &t
](auto result
) {
86 assert(result
== CollectionNode::create_result_t::SUCCESS
);
87 return tm
.dec_ref(t
, extent
->get_laddr());
88 }).si_then([] (auto) {
89 return create_iertr::make_ready_future
<>();
93 case CollectionNode::create_result_t::SUCCESS
: {
94 return create_iertr::make_ready_future
<>();
97 __builtin_unreachable();
102 FlatCollectionManager::list_ret
103 FlatCollectionManager::list(const coll_root_t
&coll_root
, Transaction
&t
)
105 logger().debug("FlatCollectionManager: {}", __func__
);
106 return get_coll_root(coll_root
, t
)
107 .si_then([] (auto extent
) {
108 return extent
->list();
112 FlatCollectionManager::update_ret
113 FlatCollectionManager::update(const coll_root_t
&coll_root
, Transaction
&t
,
114 coll_t cid
, coll_info_t info
)
116 logger().debug("FlatCollectionManager: {}", __func__
);
117 return get_coll_root(coll_root
, t
)
118 .si_then([this, &t
, cid
, info
] (auto extent
) {
119 return extent
->update(get_coll_context(t
), cid
, info
.split_bits
);
123 FlatCollectionManager::remove_ret
124 FlatCollectionManager::remove(const coll_root_t
&coll_root
, Transaction
&t
,
127 logger().debug("FlatCollectionManager: {}", __func__
);
128 return get_coll_root(coll_root
, t
).si_then([this, &t
, cid
] (auto extent
) {
129 return extent
->remove(get_coll_context(t
), cid
);