Files
scylladb/gms/endpoint_state.cc
Avi Kivity fcb8d040e8 treewide: use Software Package Data Exchange (SPDX) license identifiers
Instead of lengthy blurbs, switch to single-line, machine-readable
standardized (https://spdx.dev) license identifiers. The Linux kernel
switched long ago, so there is strong precedent.

Three cases are handled: AGPL-only, Apache-only, and dual licensed.
For the latter case, I chose (AGPL-3.0-or-later and Apache-2.0),
reasoning that our changes are extensive enough to apply our license.

The changes we applied mechanically with a script, except to
licenses/README.md.

Closes #9937
2022-01-18 12:15:18 +01:00

58 lines
1.7 KiB
C++

/*
*
* Modified by ScyllaDB
* Copyright (C) 2015-present ScyllaDB
*/
/*
* SPDX-License-Identifier: (AGPL-3.0-or-later and Apache-2.0)
*/
#include "gms/endpoint_state.hh"
#include <optional>
#include <ostream>
namespace gms {
static_assert(!std::is_default_constructible_v<heart_beat_state>);
static_assert(std::is_nothrow_copy_constructible_v<heart_beat_state>);
static_assert(std::is_nothrow_move_constructible_v<heart_beat_state>);
static_assert(std::is_nothrow_default_constructible_v<std::map<application_state, versioned_value>>);
// Note: although std::map::find is not guaranteed to be noexcept
// it depends on the comperator used and in this case comparing application_state
// is noexcept. Therefore, we can safely mark this method noexcept.
const versioned_value* endpoint_state::get_application_state_ptr(application_state key) const noexcept {
auto it = _application_state.find(key);
if (it == _application_state.end()) {
return nullptr;
} else {
return &it->second;
}
}
std::ostream& operator<<(std::ostream& os, const endpoint_state& x) {
os << "HeartBeatState = " << x._heart_beat_state << ", AppStateMap =";
for (auto&entry : x._application_state) {
const application_state& state = entry.first;
const versioned_value& value = entry.second;
os << " { " << state << " : " << value << " } ";
}
return os;
}
bool endpoint_state::is_cql_ready() const noexcept {
auto* app_state = get_application_state_ptr(application_state::RPC_READY);
if (!app_state) {
return false;
}
try {
return boost::lexical_cast<int>(app_state->value);
} catch (...) {
return false;
}
}
}