Skip to content

Commit c7667ea

Browse files
xxhdx1985126cyx1231st
authored andcommitted
crimson/os/seastore/omap_manager: limit the max size of kv inserted to
the omap tree Signed-off-by: Xuehan Xu <[email protected]>
1 parent c90d7ae commit c7667ea

File tree

6 files changed

+45
-10
lines changed

6 files changed

+45
-10
lines changed

src/crimson/os/seastore/omap_manager.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ class OMapManager {
6868
* @param string &key, omap string key
6969
* @param string &value, mapped value corresponding key
7070
*/
71-
using omap_set_key_iertr = base_iertr;
71+
using omap_set_key_iertr = base_iertr::extend<
72+
crimson::ct_error::value_too_large>;
7273
using omap_set_key_ret = omap_set_key_iertr::future<>;
7374
virtual omap_set_key_ret omap_set_key(
7475
omap_root_t &omap_root,
7576
Transaction &t,
7677
const std::string &key,
7778
const ceph::bufferlist &value) = 0;
7879

79-
using omap_set_keys_iertr = base_iertr;
80+
using omap_set_keys_iertr = omap_set_key_iertr;
8081
using omap_set_keys_ret = omap_set_keys_iertr::future<>;
8182
virtual omap_set_keys_ret omap_set_keys(
8283
omap_root_t &omap_root,

src/crimson/os/seastore/omap_manager/btree/omap_btree_node.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ struct OMapNode : LogicalChildNode {
6666
omap_context_t oc,
6767
const std::string &key) = 0;
6868

69-
using insert_iertr = base_iertr;
69+
using insert_iertr = base_iertr::extend<
70+
crimson::ct_error::value_too_large>;
7071
using insert_ret = insert_iertr::future<mutation_result_t>;
7172
virtual insert_ret insert(
7273
omap_context_t oc,
@@ -116,6 +117,10 @@ struct OMapNode : LogicalChildNode {
116117

117118
virtual ~OMapNode() = default;
118119

120+
virtual bool exceeds_max_kv_limit(
121+
const std::string &key,
122+
const ceph::bufferlist &value) const = 0;
123+
119124
void init_range(std::string _begin, std::string _end) {
120125
assert(begin.empty());
121126
assert(end.empty());

src/crimson/os/seastore/omap_manager/btree/omap_btree_node_impl.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,14 @@ OMapInnerNode::insert(
166166
LOG_PREFIX(OMapInnerNode::insert);
167167
DEBUGT("{}->{}, this: {}", oc.t, key, value, *this);
168168
auto child_pt = get_containing_child(key);
169+
if (exceeds_max_kv_limit(key, value)) {
170+
return crimson::ct_error::value_too_large::make();
171+
}
169172
return get_child_node(oc, child_pt).si_then(
170173
[oc, &key, &value] (auto extent) {
171174
ceph_assert(!extent->is_btree_root());
172175
return extent->insert(oc, key, value);
173-
}).si_then([this, oc, child_pt] (auto mresult) {
176+
}).si_then([this, oc, child_pt] (auto mresult) -> insert_ret {
174177
if (mresult.status == mutation_status_t::SUCCESS) {
175178
return insert_iertr::make_ready_future<mutation_result_t>(mresult);
176179
} else if (mresult.status == mutation_status_t::WAS_SPLIT) {
@@ -208,7 +211,11 @@ OMapInnerNode::rm_key(omap_context_t oc, const std::string &key)
208211
std::nullopt, std::nullopt));
209212
}
210213
case mutation_status_t::WAS_SPLIT:
211-
return handle_split(oc, child_pt, mresult);
214+
return handle_split(oc, child_pt, mresult
215+
).handle_error_interruptible(
216+
rm_key_iertr::pass_further{},
217+
crimson::ct_error::assert_all{"unexpected error"}
218+
);
212219
default:
213220
return rm_key_iertr::make_ready_future<mutation_result_t>(mresult);
214221
}
@@ -620,6 +627,9 @@ OMapLeafNode::insert(
620627
{
621628
LOG_PREFIX(OMapLeafNode::insert);
622629
DEBUGT("{} -> {}, this: {}", oc.t, key, value, *this);
630+
if (exceeds_max_kv_limit(key, value)) {
631+
return crimson::ct_error::value_too_large::make();
632+
}
623633
bool overflow = extent_will_overflow(key.size(), value.length());
624634
if (!overflow) {
625635
if (!is_mutable()) {

src/crimson/os/seastore/omap_manager/btree/omap_btree_node_impl.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ struct OMapInnerNode
152152
const std::string &key,
153153
const ceph::bufferlist &value) final;
154154

155+
bool exceeds_max_kv_limit(
156+
const std::string &key,
157+
const ceph::bufferlist &value) const final {
158+
return (key.length() + sizeof(laddr_le_t)) > (capacity() / 4);
159+
}
160+
155161
rm_key_ret rm_key(
156162
omap_context_t oc,
157163
const std::string &key) final;
@@ -187,7 +193,8 @@ struct OMapInnerNode
187193
omap_context_t oc,
188194
internal_const_iterator_t iter, OMapNodeRef entry);
189195

190-
using handle_split_iertr = base_iertr;
196+
using handle_split_iertr = base_iertr::extend<
197+
crimson::ct_error::value_too_large>;
191198
using handle_split_ret = handle_split_iertr::future<mutation_result_t>;
192199
handle_split_ret handle_split(
193200
omap_context_t oc, internal_const_iterator_t iter,
@@ -365,6 +372,12 @@ struct OMapLeafNode
365372
const std::string &key,
366373
const ceph::bufferlist &value) final;
367374

375+
bool exceeds_max_kv_limit(
376+
const std::string &key,
377+
const ceph::bufferlist &value) const final {
378+
return (key.length() + value.length()) > (capacity() / 4);
379+
}
380+
368381
rm_key_ret rm_key(
369382
omap_context_t oc, const std::string &key) final;
370383

src/crimson/os/seastore/seastore.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,13 +2747,16 @@ SeaStore::Shard::omaptree_clone(
27472747
seastar::stop_iteration>(
27482748
seastar::stop_iteration::no);
27492749
}
2750-
});
2750+
}).handle_error_interruptible(
2751+
base_iertr::pass_further{},
2752+
crimson::ct_error::assert_all{"unexpected value_too_large"}
2753+
);
27512754
});
27522755
});
27532756
});
27542757
}
27552758

2756-
SeaStore::base_iertr::future<>
2759+
SeaStore::Shard::omaptree_set_keys_iertr::future<>
27572760
SeaStore::Shard::omaptree_set_keys(
27582761
Transaction& t,
27592762
omap_root_t&& root,

src/crimson/os/seastore/seastore.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ class SeaStore final : public FuturizedStore {
381381
uint64_t off,
382382
uint64_t len) const;
383383

384-
using tm_iertr = base_iertr;
384+
using tm_iertr = base_iertr::extend<
385+
crimson::ct_error::value_too_large>;
385386
using tm_ret = tm_iertr::future<>;
386387
tm_ret _do_transaction_step(
387388
internal_context_t &ctx,
@@ -502,7 +503,9 @@ class SeaStore final : public FuturizedStore {
502503
omap_root_t&& root,
503504
const std::optional<std::string>& start) const;
504505

505-
base_iertr::future<> omaptree_set_keys(
506+
using omaptree_set_keys_iertr = base_iertr::extend<
507+
crimson::ct_error::value_too_large>;
508+
omaptree_set_keys_iertr::future<> omaptree_set_keys(
506509
Transaction& t,
507510
omap_root_t&& root,
508511
Onode& onode,

0 commit comments

Comments
 (0)