gossiper: add num_endpoints

Return the number of endpoints tracked by gossiper.
This is useful when the caller doesn't need
access to the endpoint states map.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
This commit is contained in:
Benny Halevy
2023-08-27 11:00:47 +03:00
parent b82c77ed9c
commit 3208af1880
3 changed files with 7 additions and 3 deletions

View File

@@ -4469,7 +4469,7 @@ future<executor::request_return_type> executor::describe_continuous_backups(clie
// manually create the keyspace to override this predefined behavior.
static future<std::vector<mutation>> create_keyspace(std::string_view keyspace_name, service::storage_proxy& sp, gms::gossiper& gossiper, api::timestamp_type ts) {
sstring keyspace_name_str(keyspace_name);
int endpoint_count = gossiper.get_endpoint_states().size();
int endpoint_count = gossiper.num_endpoints();
int rf = 3;
if (endpoint_count < rf) {
rf = 1;

View File

@@ -428,6 +428,10 @@ public:
std::vector<inet_address> get_endpoints() const;
size_t num_endpoints() const noexcept {
return _endpoint_state_map.size();
}
bool uses_host_id(inet_address endpoint) const;
locator::host_id get_host_id(inet_address endpoint) const;

View File

@@ -222,11 +222,11 @@ void migration_manager::schedule_schema_pull(const gms::inet_address& endpoint,
}
bool migration_manager::have_schema_agreement() {
const auto known_endpoints = _gossiper.get_endpoint_states();
if (known_endpoints.size() == 1) {
if (_gossiper.num_endpoints() == 1) {
// Us.
return true;
}
const auto known_endpoints = _gossiper.get_endpoint_states();
auto our_version = _storage_proxy.get_db().local().get_version();
bool match = false;
for (auto& x : known_endpoints) {