]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #include "crimson/os/seastore/logging.h" | |
5 | ||
6 | #include "crimson/os/seastore/onode_manager/staged-fltree/fltree_onode_manager.h" | |
7 | ||
8 | SET_SUBSYS(seastore_onode); | |
9 | ||
10 | namespace crimson::os::seastore::onode { | |
11 | ||
12 | FLTreeOnodeManager::contains_onode_ret FLTreeOnodeManager::contains_onode( | |
13 | Transaction &trans, | |
14 | const ghobject_t &hoid) | |
15 | { | |
16 | return tree.contains(trans, hoid); | |
17 | } | |
18 | ||
19 | FLTreeOnodeManager::get_onode_ret FLTreeOnodeManager::get_onode( | |
20 | Transaction &trans, | |
21 | const ghobject_t &hoid) | |
22 | { | |
23 | LOG_PREFIX(FLTreeOnodeManager::get_onode); | |
24 | return tree.find( | |
25 | trans, hoid | |
26 | ).si_then([this, &hoid, &trans, FNAME](auto cursor) | |
27 | -> get_onode_ret { | |
28 | if (cursor == tree.end()) { | |
29 | DEBUGT("no entry for {}", trans, hoid); | |
30 | return crimson::ct_error::enoent::make(); | |
31 | } | |
32 | auto val = OnodeRef(new FLTreeOnode( | |
33 | default_data_reservation, | |
34 | default_metadata_range, | |
35 | cursor.value())); | |
36 | return get_onode_iertr::make_ready_future<OnodeRef>( | |
37 | val | |
38 | ); | |
39 | }); | |
40 | } | |
41 | ||
42 | FLTreeOnodeManager::get_or_create_onode_ret | |
43 | FLTreeOnodeManager::get_or_create_onode( | |
44 | Transaction &trans, | |
45 | const ghobject_t &hoid) | |
46 | { | |
47 | LOG_PREFIX(FLTreeOnodeManager::get_or_create_onode); | |
48 | return tree.insert( | |
49 | trans, hoid, | |
50 | OnodeTree::tree_value_config_t{sizeof(onode_layout_t)} | |
51 | ).si_then([this, &trans, &hoid, FNAME](auto p) | |
52 | -> get_or_create_onode_ret { | |
53 | auto [cursor, created] = std::move(p); | |
54 | auto val = OnodeRef(new FLTreeOnode( | |
55 | default_data_reservation, | |
56 | default_metadata_range, | |
57 | cursor.value())); | |
58 | if (created) { | |
59 | DEBUGT("created onode for entry for {}", trans, hoid); | |
60 | val->get_mutable_layout(trans) = onode_layout_t{}; | |
61 | } | |
62 | return get_or_create_onode_iertr::make_ready_future<OnodeRef>( | |
63 | val | |
64 | ); | |
65 | }); | |
66 | } | |
67 | ||
68 | FLTreeOnodeManager::get_or_create_onodes_ret | |
69 | FLTreeOnodeManager::get_or_create_onodes( | |
70 | Transaction &trans, | |
71 | const std::vector<ghobject_t> &hoids) | |
72 | { | |
73 | return seastar::do_with( | |
74 | std::vector<OnodeRef>(), | |
75 | [this, &hoids, &trans](auto &ret) { | |
76 | ret.reserve(hoids.size()); | |
77 | return trans_intr::do_for_each( | |
78 | hoids, | |
79 | [this, &trans, &ret](auto &hoid) { | |
80 | return get_or_create_onode(trans, hoid | |
81 | ).si_then([&ret](auto &&onoderef) { | |
82 | ret.push_back(std::move(onoderef)); | |
83 | }); | |
84 | }).si_then([&ret] { | |
85 | return std::move(ret); | |
86 | }); | |
87 | }); | |
88 | } | |
89 | ||
90 | FLTreeOnodeManager::write_dirty_ret FLTreeOnodeManager::write_dirty( | |
91 | Transaction &trans, | |
92 | const std::vector<OnodeRef> &onodes) | |
93 | { | |
94 | return trans_intr::do_for_each( | |
95 | onodes, | |
aee94f69 TL |
96 | [&trans](auto &onode) -> eagain_ifuture<> { |
97 | if (!onode) { | |
98 | return eagain_iertr::make_ready_future<>(); | |
99 | } | |
20effc67 | 100 | auto &flonode = static_cast<FLTreeOnode&>(*onode); |
aee94f69 TL |
101 | if (!flonode.is_alive()) { |
102 | return eagain_iertr::make_ready_future<>(); | |
103 | } | |
20effc67 TL |
104 | switch (flonode.status) { |
105 | case FLTreeOnode::status_t::MUTATED: { | |
106 | flonode.populate_recorder(trans); | |
107 | return eagain_iertr::make_ready_future<>(); | |
108 | } | |
20effc67 TL |
109 | case FLTreeOnode::status_t::STABLE: { |
110 | return eagain_iertr::make_ready_future<>(); | |
111 | } | |
112 | default: | |
113 | __builtin_unreachable(); | |
114 | } | |
115 | }); | |
116 | } | |
117 | ||
118 | FLTreeOnodeManager::erase_onode_ret FLTreeOnodeManager::erase_onode( | |
119 | Transaction &trans, | |
120 | OnodeRef &onode) | |
121 | { | |
122 | auto &flonode = static_cast<FLTreeOnode&>(*onode); | |
aee94f69 TL |
123 | assert(flonode.is_alive()); |
124 | if (flonode.status == FLTreeOnode::status_t::MUTATED) { | |
125 | flonode.populate_recorder(trans); | |
126 | } | |
20effc67 | 127 | flonode.mark_delete(); |
aee94f69 | 128 | return tree.erase(trans, flonode); |
20effc67 TL |
129 | } |
130 | ||
131 | FLTreeOnodeManager::list_onodes_ret FLTreeOnodeManager::list_onodes( | |
132 | Transaction &trans, | |
133 | const ghobject_t& start, | |
134 | const ghobject_t& end, | |
135 | uint64_t limit) | |
136 | { | |
137 | return tree.lower_bound(trans, start | |
138 | ).si_then([this, &trans, end, limit] (auto&& cursor) { | |
139 | using crimson::os::seastore::onode::full_key_t; | |
140 | return seastar::do_with( | |
141 | limit, | |
142 | std::move(cursor), | |
143 | list_onodes_bare_ret(), | |
144 | [this, &trans, end] (auto& to_list, auto& current_cursor, auto& ret) { | |
145 | return trans_intr::repeat( | |
146 | [this, &trans, end, &to_list, ¤t_cursor, &ret] () | |
147 | -> eagain_ifuture<seastar::stop_iteration> { | |
1e59de90 TL |
148 | if (current_cursor.is_end()) { |
149 | std::get<1>(ret) = ghobject_t::get_max(); | |
150 | return seastar::make_ready_future<seastar::stop_iteration>( | |
151 | seastar::stop_iteration::yes); | |
152 | } else if (current_cursor.get_ghobj() >= end) { | |
20effc67 TL |
153 | std::get<1>(ret) = end; |
154 | return seastar::make_ready_future<seastar::stop_iteration>( | |
155 | seastar::stop_iteration::yes); | |
156 | } | |
157 | if (to_list == 0) { | |
158 | std::get<1>(ret) = current_cursor.get_ghobj(); | |
159 | return seastar::make_ready_future<seastar::stop_iteration>( | |
160 | seastar::stop_iteration::yes); | |
161 | } | |
162 | std::get<0>(ret).emplace_back(current_cursor.get_ghobj()); | |
163 | return tree.get_next(trans, current_cursor | |
164 | ).si_then([&to_list, ¤t_cursor] (auto&& next_cursor) mutable { | |
165 | // we intentionally hold the current_cursor during get_next() to | |
166 | // accelerate tree lookup. | |
167 | --to_list; | |
168 | current_cursor = next_cursor; | |
169 | return seastar::make_ready_future<seastar::stop_iteration>( | |
170 | seastar::stop_iteration::no); | |
171 | }); | |
172 | }).si_then([&ret] () mutable { | |
173 | return seastar::make_ready_future<list_onodes_bare_ret>( | |
174 | std::move(ret)); | |
175 | // return ret; | |
176 | }); | |
177 | }); | |
178 | }); | |
179 | } | |
180 | ||
181 | FLTreeOnodeManager::~FLTreeOnodeManager() {} | |
182 | ||
183 | } |