raft: disallow adding and creating servers with id zero
Id zero has special meaning in the code and cannot be valid server id. Message-Id: <20210407134853.1964226-1-gleb@scylladb.com>
This commit is contained in:
committed by
Tomasz Grabiec
parent
3687757115
commit
fb938a36d4
@@ -28,6 +28,9 @@ fsm::fsm(server_id id, term_t current_term, server_id voted_for, log log,
|
||||
failure_detector& failure_detector, fsm_config config) :
|
||||
_my_id(id), _current_term(current_term), _voted_for(voted_for),
|
||||
_log(std::move(log)), _failure_detector(failure_detector), _config(config) {
|
||||
if (id == raft::server_id{}) {
|
||||
throw std::invalid_argument("raft::fsm: raft instance cannot have id zero");
|
||||
}
|
||||
// The snapshot can not contain uncommitted entries
|
||||
_commit_idx = _log.get_snapshot().idx;
|
||||
_observed.advance(*this);
|
||||
|
||||
@@ -104,12 +104,19 @@ struct configuration {
|
||||
configuration(std::initializer_list<server_id> ids) {
|
||||
current.reserve(ids.size());
|
||||
for (auto&& id : ids) {
|
||||
if (id == server_id{}) {
|
||||
throw std::invalid_argument("raft::configuration: id zero is not supported");
|
||||
}
|
||||
current.emplace(server_address{std::move(id)});
|
||||
}
|
||||
}
|
||||
|
||||
configuration(server_address_set current_arg = {}, server_address_set previous_arg = {})
|
||||
: current(std::move(current_arg)), previous(std::move(previous_arg)) {}
|
||||
: current(std::move(current_arg)), previous(std::move(previous_arg)) {
|
||||
if (current.count(server_address{server_id()}) || previous.count(server_address{server_id()})) {
|
||||
throw std::invalid_argument("raft::configuration: id zero is not supported");
|
||||
}
|
||||
}
|
||||
|
||||
// Return true if the previous configuration is still
|
||||
// in use
|
||||
|
||||
Reference in New Issue
Block a user