Files
scylladb/raft/raft.cc
Kamil Braun daf9c53bb8 raft: split can_vote field from server_address to separate struct
Whether a server can vote in a Raft configuration is not part of the
address. `server_address` was used in many context where `can_vote` is
irrelevant.

Split the struct: `server_address` now contains only `id` and
`server_info` as it did before `can_vote` was introduced. Instead we
have a `config_member` struct that contains a `server_address` and the
`can_vote` field.

Also remove an "unsafe" constructor from `server_address` where `id` was
provided but `server_info` was not. The constructor was used for tests
where `server_info` is irrelevant, but it's important not to forget
about the info in production code. The constructor was used for two
purposes:
- Invoking set operations such as `contains`. To solve this we use C++20
  transparent hash and comparator functions, which allow invoking
  `contains` and similar functions by providing a different key type (in
  this case `raft::server_id` in set of addresses, for example).
- constructing addresses without `info`s in tests. For this we provide
  helper functions in the test helpers module and use them.
2022-07-18 18:22:10 +02:00

31 lines
719 B
C++

/*
* Copyright (C) 2020-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include "raft.hh"
#include "to_string.hh"
namespace raft {
seastar::logger logger("raft");
std::ostream& operator<<(std::ostream& os, const raft::server_address& addr) {
return os << format("{{.id={}}}", addr.id);
}
std::ostream& operator<<(std::ostream& os, const raft::config_member& s) {
return os << format("{{.id={} .can_vote={}}}", s.addr.id, s.can_vote);
}
std::ostream& operator<<(std::ostream& os, const raft::configuration& cfg) {
if (cfg.previous.empty()) {
return os << cfg.current;
}
return os << format("{}->{}", cfg.previous, cfg.current);
}
} // end of namespace raft