Skip to content

Commit

Permalink
Merge pull request #743 from mmaslankaprv/exit-early-on-invariants-ch…
Browse files Browse the repository at this point in the history
…ange

Exit early on invariants change
  • Loading branch information
mmaslankaprv authored Mar 3, 2021
2 parents 35b3a7d + 29eb5ce commit a5ed5d0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/v/cluster/controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ ss::future<> controller::start() {
std::ref(_storage),
std::ref(_as));
})
.then([this] {
// validate configuration invariants to exit early
return _members_manager.local().validate_configuration_invariants();
})
.then([this] {
return _stm.start_single(
std::ref(clusterlog),
Expand Down
14 changes: 6 additions & 8 deletions src/v/cluster/members_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,13 @@ members_manager::members_manager(

ss::future<> members_manager::start() {
vlog(clusterlog.info, "starting cluster::members_manager...");
// validate node id change
return validate_configuration_invariants().then([this] {
// join raft0
if (!is_already_member()) {
join_raft0();
}

return start_config_changes_watcher();
});
// join raft0
if (!is_already_member()) {
join_raft0();
}

return start_config_changes_watcher();
}

ss::future<> members_manager::start_config_changes_watcher() {
Expand Down
4 changes: 2 additions & 2 deletions src/v/cluster/members_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class members_manager {

ss::future<> start();
ss::future<> stop();

ss::future<> validate_configuration_invariants();
ss::future<result<join_reply>> handle_join_request(model::broker);
ss::future<std::error_code> apply_update(model::record_batch);

Expand Down Expand Up @@ -75,7 +75,7 @@ class members_manager {
// Raft 0 config updates
ss::future<> handle_raft0_cfg_update(raft::group_configuration);
ss::future<> update_connections(patch<broker_ptr>);
ss::future<> validate_configuration_invariants();

ss::future<> start_config_changes_watcher();

ss::future<> maybe_update_current_node_configuration();
Expand Down
8 changes: 6 additions & 2 deletions src/v/cluster/partition_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,12 @@ void partition_allocator::update_allocation_state(
[](const model::broker_shard& l, const model::broker_shard& r) {
return l.node_id > r.node_id;
});

auto it = find_node(std::cbegin(shards)->node_id);
auto node_id = std::cbegin(shards)->node_id;
auto it = find_node(node_id);
vassert(
it != _machines.end(),
"node: {} must exists in partition allocator, it currenlty does not",
node_id);
for (auto const& bs : shards) {
// Thanks to shards being sorted we need to do only
// as many lookups as there are brokers
Expand Down

0 comments on commit a5ed5d0

Please sign in to comment.