fms: extract entry_size to log_entry::get_size
We intend to reuse it in subsequent commit.
This commit is contained in:
23
raft/fsm.cc
23
raft/fsm.cc
@@ -855,27 +855,6 @@ void fsm::request_vote_reply(server_id from, vote_reply&& reply) {
|
||||
}
|
||||
}
|
||||
|
||||
static size_t entry_size(const log_entry& e) {
|
||||
struct overloaded {
|
||||
size_t operator()(const command& c) {
|
||||
return c.size();
|
||||
}
|
||||
size_t operator()(const configuration& c) {
|
||||
size_t size = 0;
|
||||
for (auto& s : c.current) {
|
||||
size += sizeof(s.addr.id);
|
||||
size += s.addr.info.size();
|
||||
size += sizeof(s.can_vote);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
size_t operator()(const log_entry::dummy& d) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
return std::visit(overloaded{}, e.data) + sizeof(e);
|
||||
}
|
||||
|
||||
void fsm::replicate_to(follower_progress& progress, bool allow_empty) {
|
||||
|
||||
logger.trace("replicate_to[{}->{}]: called next={} match={}",
|
||||
@@ -935,7 +914,7 @@ void fsm::replicate_to(follower_progress& progress, bool allow_empty) {
|
||||
req.entries.push_back(entry);
|
||||
logger.trace("replicate_to[{}->{}]: send entry idx={}, term={}",
|
||||
_my_id, progress.id, entry->idx, entry->term);
|
||||
size += entry_size(*entry);
|
||||
size += entry->get_size();
|
||||
next_idx++;
|
||||
if (progress.state == follower_progress::state::PROBE) {
|
||||
break; // in PROBE mode send only one entry
|
||||
|
||||
21
raft/raft.cc
21
raft/raft.cc
@@ -12,6 +12,27 @@ namespace raft {
|
||||
|
||||
seastar::logger logger("raft");
|
||||
|
||||
size_t log_entry::get_size() const {
|
||||
struct overloaded {
|
||||
size_t operator()(const command& c) {
|
||||
return c.size();
|
||||
}
|
||||
size_t operator()(const configuration& c) {
|
||||
size_t size = 0;
|
||||
for (auto& s : c.current) {
|
||||
size += sizeof(s.addr.id);
|
||||
size += s.addr.info.size();
|
||||
size += sizeof(s.can_vote);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
size_t operator()(const log_entry::dummy& d) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
return std::visit(overloaded{}, this->data) + sizeof(*this);
|
||||
}
|
||||
|
||||
} // end of namespace raft
|
||||
|
||||
auto fmt::formatter<raft::server_address>::format(const raft::server_address& addr,
|
||||
|
||||
@@ -239,6 +239,8 @@ struct log_entry {
|
||||
term_t term;
|
||||
index_t idx;
|
||||
std::variant<command, configuration, dummy> data;
|
||||
|
||||
size_t get_size() const;
|
||||
};
|
||||
|
||||
using log_entry_ptr = seastar::lw_shared_ptr<const log_entry>;
|
||||
|
||||
Reference in New Issue
Block a user