Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v23.3.x] storage/kvstore: remove oversized alloc #16390

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -347,3 +347,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 @@ -483,7 +483,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 @@ -26,7 +26,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 @@ -164,7 +164,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
Loading