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

Using chunked_fifo in heartbeat_manager #10915

Merged
merged 2 commits into from
May 25, 2023
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
19 changes: 11 additions & 8 deletions src/v/raft/heartbeat_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
#include "rpc/types.h"
#include "vlog.h"

#include <seastar/core/chunked_fifo.hh>
#include <seastar/core/coroutine.hh>
#include <seastar/core/future-util.hh>
#include <seastar/core/timed_out_error.hh>
#include <seastar/core/with_timeout.hh>

#include <absl/container/flat_hash_set.h>
#include <absl/container/node_hash_map.h>
#include <bits/stdint-uintn.h>
#include <boost/range/iterator_range.hpp>

Expand Down Expand Up @@ -72,9 +74,9 @@ heartbeat_manager::follower_request_meta::~follower_request_meta() noexcept {

static heartbeat_requests requests_for_range(
const consensus_set& c, clock_type::duration heartbeat_interval) {
absl::btree_map<
absl::node_hash_map<
model::node_id,
std::vector<std::pair<
ss::chunked_fifo<std::pair<
heartbeat_metadata,
heartbeat_manager::follower_request_meta>>>
pending_beats;
Expand Down Expand Up @@ -154,9 +156,10 @@ static heartbeat_requests requests_for_range(
reqs.reserve(pending_beats.size());
for (auto& p : pending_beats) {
std::vector<heartbeat_metadata> requests;
absl::
btree_map<raft::group_id, heartbeat_manager::follower_request_meta>
meta_map;
absl::node_hash_map<
raft::group_id,
heartbeat_manager::follower_request_meta>
meta_map;
requests.reserve(p.second.size());
for (auto& [hb, follower_meta] : p.second) {
meta_map.emplace(hb.meta.group, std::move(follower_meta));
Expand Down Expand Up @@ -228,7 +231,7 @@ ss::future<> heartbeat_manager::do_self_heartbeat(node_heartbeat&& r) {
.group = hb.meta.group,
.result = append_entries_reply::status::success};
});
process_reply(r.target, std::move(r.meta_map), std::move(reply));
process_reply(r.target, r.meta_map, std::move(reply));
return ss::now();
}

Expand All @@ -254,7 +257,7 @@ ss::future<> heartbeat_manager::do_heartbeat(node_heartbeat&& r) {
this](result<heartbeat_reply> ret) mutable {
// this will happen after RPC client will return and resume
// sending heartbeats to follower
process_reply(node, std::move(groups), std::move(ret));
process_reply(node, groups, std::move(ret));
});
// fail fast to make sure that not lagging nodes will be able to receive
// hearteats
Expand All @@ -272,7 +275,7 @@ ss::future<> heartbeat_manager::do_heartbeat(node_heartbeat&& r) {

void heartbeat_manager::process_reply(
model::node_id n,
absl::btree_map<raft::group_id, follower_request_meta> groups,
const absl::node_hash_map<raft::group_id, follower_request_meta>& groups,
Comment on lines -275 to +278
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats this change for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i just wanted to accommodate to what we agreed previously in slack that the node_hash_map is better suited in the cases when we do not need ordering as it provides enough prevention from memory fragmentation.

result<heartbeat_reply> r) {
if (!r) {
vlog(
Expand Down
7 changes: 4 additions & 3 deletions src/v/raft/heartbeat_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <seastar/util/log.hh>

#include <absl/container/btree_map.h>
#include <absl/container/node_hash_map.h>
#include <boost/container/flat_set.hpp>

namespace raft::details {
Expand Down Expand Up @@ -108,7 +109,7 @@ class heartbeat_manager {
node_heartbeat(
model::node_id t,
heartbeat_request req,
absl::btree_map<raft::group_id, follower_request_meta> seqs)
absl::node_hash_map<raft::group_id, follower_request_meta> seqs)
: target(t)
, request(std::move(req))
, meta_map(std::move(seqs)) {}
Expand All @@ -117,7 +118,7 @@ class heartbeat_manager {
heartbeat_request request;
// each raft group has its own follower metadata hence we need map to
// track a sequence per group
absl::btree_map<raft::group_id, follower_request_meta> meta_map;
absl::node_hash_map<raft::group_id, follower_request_meta> meta_map;
};

heartbeat_manager(
Expand Down Expand Up @@ -155,7 +156,7 @@ class heartbeat_manager {
/// \param result if the node return successful heartbeats
void process_reply(
model::node_id n,
absl::btree_map<raft::group_id, follower_request_meta> groups,
const absl::node_hash_map<raft::group_id, follower_request_meta>& groups,
result<heartbeat_reply> result);

// private members
Expand Down