Skip to content

Commit

Permalink
Check that sentinel endpoints are defined
Browse files Browse the repository at this point in the history
Previously, the init() method of the 2PC sentinel controller would
exhibit a non-existent element access if no sentinel endpoints were
defined.  With this commit, the code now checks that at least one
endpoint is defined and logs an error if it's not.

Signed-off-by: Michael L. Szulczewski <[email protected]>
  • Loading branch information
mszulcz-mitre authored and HalosGhost committed Sep 27, 2022
1 parent 33292cc commit 46771a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/uhs/twophase/sentinel_2pc/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ namespace cbdc::sentinel_2pc {
.size())]) {}

auto controller::init() -> bool {
if(m_opts.m_sentinel_endpoints.empty()) {
m_logger->error("No sentinel endpoints are defined.");
return false;
}

if(m_sentinel_id >= m_opts.m_sentinel_endpoints.size()) {
m_logger->error(
"The sentinel ID is too large for the number of sentinels.");
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/sentinel_2pc/controller_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,14 @@ TEST_F(sentinel_2pc_test, out_of_range_sentinel_id) {
m_logger);
ASSERT_FALSE(ctl->init());
}

TEST_F(sentinel_2pc_test, no_sentinel_endpoints) {
m_opts.m_sentinel_endpoints.clear();
auto ctl = std::make_unique<cbdc::sentinel_2pc::controller>(0,
m_opts,
m_logger);

// Check that the controller fails to initialize if no sentinel endpoints
// are defined.
ASSERT_FALSE(ctl->init());
}

0 comments on commit 46771a9

Please sign in to comment.