Skip to content

Commit

Permalink
Merge pull request redpanda-data#16388 from vbotbuildovich/backport-p…
Browse files Browse the repository at this point in the history
…r-16381-v23.2.x-271

[v23.2.x] storage/kvstore: remove oversized alloc
  • Loading branch information
rockwotj authored Jan 31, 2024
2 parents 29f51b6 + 438ae59 commit 29a4b77
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/v/bytes/bytes.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,9 @@ operator^(const std::array<char, Size>& a, const std::array<char, Size>& b) {
a.begin(), a.end(), b.begin(), out.begin(), std::bit_xor<>());
return out;
}

struct bytes_type_cmp {
using is_transparent = std::true_type;
bool operator()(const bytes& lhs, const bytes_view& rhs) const;
bool operator()(const bytes& lhs, const bytes& rhs) const;
};
8 changes: 8 additions & 0 deletions src/v/bytes/iobuf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,11 @@ std::ostream& operator<<(std::ostream& os, const bytes_view& b) {
return os;
}
} // namespace std

bool bytes_type_cmp::operator()(const bytes& lhs, const bytes_view& rhs) const {
return lhs < rhs;
}

bool bytes_type_cmp::operator()(const bytes& lhs, const bytes& rhs) const {
return lhs < rhs;
}
1 change: 0 additions & 1 deletion src/v/storage/kvstore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ ss::future<> kvstore::load_snapshot_from_reader(snapshot_reader& reader) {
}

auto lock = co_await _db_mut.get_units();
_db.reserve(batch.header().record_count);
co_await batch.for_each_record_async([this](model::record r) {
auto key = iobuf_to_bytes(r.release_key());
_probe.add_cached_bytes(key.size() + r.value().size_bytes());
Expand Down
4 changes: 2 additions & 2 deletions src/v/storage/kvstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <seastar/core/gate.hh>
#include <seastar/core/timer.hh>

#include <absl/container/node_hash_map.h>
#include <absl/container/btree_map.h>

namespace storage {

Expand Down Expand Up @@ -162,7 +162,7 @@ class kvstore {
// Protect _db and _next_offset across asynchronous mutations.
mutex _db_mut;
model::offset _next_offset;
absl::node_hash_map<bytes, iobuf, bytes_type_hash, bytes_type_eq> _db;
absl::btree_map<bytes, iobuf, bytes_type_cmp> _db;
std::optional<ntp_sanitizer_config> _ntp_sanitizer_config;

ss::future<> put(key_space ks, bytes key, std::optional<iobuf> value);
Expand Down

0 comments on commit 29a4b77

Please sign in to comment.