Skip to content

Commit

Permalink
Merge pull request #17115 from mmaslankaprv/vbotbuildovich/backport-1…
Browse files Browse the repository at this point in the history
…7092-v23.3.x-663-2

[v23.3.x] Using `contiguous_range_map` in `partition_leaders_table`
  • Loading branch information
mmaslankaprv authored Mar 15, 2024
2 parents c96a7ae + 16076c0 commit 9bef072
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/v/cluster/partition_leaders_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ partition_leaders_table::get_leaders() const {
for (const auto& [p_id, leader_info] : partition_leaders) {
leader_info_t info{
.tp_ns = tp_ns,
.pid = p_id,
.pid = model::partition_id(p_id),
.current_leader = leader_info.current_leader,
.previous_leader = leader_info.previous_leader,
.last_stable_leader_term = leader_info.last_stable_leader_term,
Expand Down
8 changes: 4 additions & 4 deletions src/v/cluster/partition_leaders_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "model/fundamental.h"
#include "model/metadata.h"
#include "ssx/async_algorithm.h"
#include "utils/expiring_promise.h"
#include "utils/contiguous_range_map.h"
#include "utils/named_type.h"

#include <seastar/core/abort_source.hh>
Expand All @@ -30,7 +30,6 @@

#include <cstdint>
#include <optional>
#include <utility>

namespace cluster {

Expand Down Expand Up @@ -112,7 +111,7 @@ class partition_leaders_table {
*/
throw_if_modified(version_snapshot);
f(tp_ns,
p.first,
model::partition_id(p.first),
p.second.current_leader,
p.second.update_term);
});
Expand Down Expand Up @@ -195,7 +194,8 @@ class partition_leaders_table {
model::revision_id partition_revision;
};

using partition_leaders = absl::btree_map<model::partition_id, leader_meta>;
using partition_leaders
= contiguous_range_map<model::partition_id::type, leader_meta>;
using topics_t = absl::node_hash_map<
model::topic_namespace,
partition_leaders,
Expand Down
5 changes: 5 additions & 0 deletions src/v/utils/contiguous_range_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ class contiguous_range_map {
*/
size_t capacity() const { return _values.size(); }

/**
* Returns true when map has no elements
*/
bool empty() const { return _size == 0; }

iterator begin() { return iter<false>(this, _values.begin()); }
iterator end() { return iter<false>(this, _values.end()); }

Expand Down

0 comments on commit 9bef072

Please sign in to comment.