Skip to content

Commit

Permalink
c/m_dissemination: use chunked vector in update_leaders_request
Browse files Browse the repository at this point in the history
The `update_leader_request` may only contain few of ntp leader updates.
In this case using a `fragmented_vector` with large chunk size is a
memory waste

Signed-off-by: Michał Maślanka <michal@redpanda.com>
  • Loading branch information
mmaslankaprv committed Aug 21, 2024
1 parent 5e3d995 commit e1be74a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/v/cluster/metadata_dissemination_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ metadata_dissemination_handler::update_leadership_v2(

ss::future<update_leadership_reply>
metadata_dissemination_handler::do_update_leadership(
fragmented_vector<ntp_leader_revision> leaders) {
chunked_vector<ntp_leader_revision> leaders) {
vlog(clusterlog.trace, "Received a metadata update");
co_await ss::parallel_for_each(
boost::irange<ss::shard_id>(0, ss::smp::count),
[this, leaders = std::move(leaders)](ss::shard_id shard) {
fragmented_vector<ntp_leader_revision> local_leaders;
chunked_vector<ntp_leader_revision> local_leaders;
local_leaders.reserve(leaders.size());
std::copy(
leaders.begin(), leaders.end(), std::back_inserter(local_leaders));
Expand Down
2 changes: 1 addition & 1 deletion src/v/cluster/metadata_dissemination_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class metadata_dissemination_handler

private:
ss::future<update_leadership_reply>
do_update_leadership(fragmented_vector<ntp_leader_revision>);
do_update_leadership(chunked_vector<ntp_leader_revision>);

ss::sharded<partition_leaders_table>& _leaders;
}; // namespace cluster
Expand Down
2 changes: 1 addition & 1 deletion src/v/cluster/metadata_dissemination_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ ss::future<> metadata_dissemination_service::update_leaders_with_health_report(
ss::future<> metadata_dissemination_service::dispatch_one_update(
model::node_id target_id, update_retry_meta& meta) {
// copy updates to make retries possible
fragmented_vector<ntp_leader_revision> updates;
chunked_vector<ntp_leader_revision> updates;
updates.reserve(meta.updates.size());
std::copy(
meta.updates.begin(), meta.updates.end(), std::back_inserter(updates));
Expand Down
6 changes: 3 additions & 3 deletions src/v/cluster/metadata_dissemination_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ struct update_leadership_request_v2
serde::compat_version<0>> {
using rpc_adl_exempt = std::true_type;
static constexpr int8_t version = 0;
fragmented_vector<ntp_leader_revision> leaders;
chunked_vector<ntp_leader_revision> leaders;

update_leadership_request_v2() noexcept = default;

Expand All @@ -119,7 +119,7 @@ struct update_leadership_request_v2
};

update_leadership_request_v2 copy() const {
fragmented_vector<ntp_leader_revision> leaders_cp;
chunked_vector<ntp_leader_revision> leaders_cp;
leaders_cp.reserve(leaders.size());
std::copy(
leaders.begin(), leaders.end(), std::back_inserter(leaders_cp));
Expand All @@ -134,7 +134,7 @@ struct update_leadership_request_v2
}

explicit update_leadership_request_v2(
fragmented_vector<ntp_leader_revision> leaders)
chunked_vector<ntp_leader_revision> leaders)
: leaders(std::move(leaders)) {}

auto serde_fields() { return std::tie(leaders); }
Expand Down
2 changes: 1 addition & 1 deletion src/v/cluster/tests/serialization_rt_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ SEASTAR_THREAD_TEST_CASE(serde_reflection_roundtrip) {
tests::random_named_int<model::term_id>(),
tests::random_named_int<model::node_id>(),
tests::random_named_int<model::revision_id>()));
fragmented_vector<cluster::ntp_leader_revision> l_revs;
chunked_vector<cluster::ntp_leader_revision> l_revs;
l_revs.emplace_back(
model::random_ntp(),
tests::random_named_int<model::term_id>(),
Expand Down
2 changes: 1 addition & 1 deletion src/v/compat/metadata_dissemination_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace compat {
template<>
struct instance_generator<cluster::update_leadership_request_v2> {
static cluster::update_leadership_request_v2 random() {
fragmented_vector<cluster::ntp_leader_revision> values;
chunked_vector<cluster::ntp_leader_revision> values;
values.emplace_back(
model::random_ntp(),
tests::random_named_int<model::term_id>(),
Expand Down

0 comments on commit e1be74a

Please sign in to comment.