Skip to content

Commit

Permalink
Add swap_node to driver to enable new scenarios (#5953)
Browse files Browse the repository at this point in the history
  • Loading branch information
achamayou authored Jan 24, 2024
1 parent 2d66dfe commit 8c6886f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/consensus/aft/test/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ int main(int argc, char** argv)
driver->trust_nodes(
items[0], {std::next(items.begin()), items.end()}, lineno);
break;
case shash("swap_node"):
assert(items.size() == 4);
driver->swap_node(items[1], items[2], items[3], lineno);
break;
case shash("nodes"):
assert(items.size() >= 2);
items.erase(items.begin());
Expand Down
39 changes: 37 additions & 2 deletions src/consensus/aft/test/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ class RaftDriver
public:
RaftDriver() = default;

// Note: deprecated, to be removed when the last scenario using it is removed
void create_new_nodes(std::vector<std::string> node_ids)
{
// Opinionated way to create network. Initial configuration is automatically
// Unrealistic way to create network. Initial configuration is automatically
// added to all nodes.
kv::Configuration::Nodes configuration;
for (auto const& n : node_ids)
Expand All @@ -210,6 +211,7 @@ class RaftDriver
}
}

// Note: deprecated, to be removed when the last scenario using it is removed
void create_new_node(std::string node_id_s)
{
ccf::NodeId node_id(node_id_s);
Expand All @@ -219,6 +221,7 @@ class RaftDriver
<< std::endl;
}

// Note: deprecated, to be removed when the last scenario using it is removed
void create_start_node(const std::string& start_node_id, const size_t lineno)
{
if (!_nodes.empty())
Expand Down Expand Up @@ -246,7 +249,7 @@ class RaftDriver
{
add_node(node_id);
RAFT_DRIVER_OUT << fmt::format(
" Note over {}: Node {} created", node_id, node_id)
" Note over {}: Node {} trusted", node_id, node_id)
<< std::endl;
}
kv::Configuration::Nodes configuration;
Expand All @@ -267,6 +270,38 @@ class RaftDriver
_replicate(term, {}, lineno, false, configuration);
}

void swap_node(
const std::string& term,
const std::string& node_out,
const std::string& node_in,
const size_t lineno)
{
add_node(node_in);
RAFT_DRIVER_OUT << fmt::format(
" Note over {}: Node {} trusted", node_in, node_in)
<< std::endl;
RAFT_DRIVER_OUT << fmt::format(
" Note over {}: Node {} retired", node_out, node_out)
<< std::endl;
kv::Configuration::Nodes configuration;
for (const auto& [id, node] : _nodes)
{
if (id != node_out)
{
configuration.try_emplace(id);
}
}
for (const auto& [id, node] : _nodes)
{
if (id != node_in)
{
connect(id, node_in);
}
}
_replicate(term, {}, lineno, false, configuration);
}

// Note: deprecated, to be removed when the last scenario using it is removed
void replicate_new_configuration(
const std::string& term_s,
std::vector<std::string> node_ids,
Expand Down

0 comments on commit 8c6886f

Please sign in to comment.