storage_service: Move get_generation_number to util/
This is purely utility helper routine. As a nice side effect the inclusion of storage_service.hh is removed from several unrelated places. Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
This commit is contained in:
@@ -517,6 +517,7 @@ scylla_core = (['database.cc',
|
||||
'utils/limiting_data_source.cc',
|
||||
'utils/updateable_value.cc',
|
||||
'utils/directories.cc',
|
||||
'utils/generation-number.cc',
|
||||
'mutation_partition.cc',
|
||||
'mutation_partition_view.cc',
|
||||
'mutation_partition_serializer.cc',
|
||||
|
||||
@@ -45,7 +45,6 @@
|
||||
|
||||
#include "system_keyspace.hh"
|
||||
#include "types.hh"
|
||||
#include "service/storage_service.hh"
|
||||
#include "service/storage_proxy.hh"
|
||||
#include "service/client_state.hh"
|
||||
#include "service/query_state.hh"
|
||||
@@ -80,6 +79,7 @@
|
||||
#include "db/view/build_progress_virtual_reader.hh"
|
||||
#include "db/schema_tables.hh"
|
||||
#include "index/built_indexes_virtual_reader.hh"
|
||||
#include "utils/generation-number.hh"
|
||||
|
||||
#include "idl/frozen_mutation.dist.hh"
|
||||
#include "serializer_impl.hh"
|
||||
@@ -2080,11 +2080,11 @@ future<int> increment_and_get_generation() {
|
||||
// seconds-since-epoch isn't a foolproof new generation
|
||||
// (where foolproof is "guaranteed to be larger than the last one seen at this ip address"),
|
||||
// but it's as close as sanely possible
|
||||
generation = service::get_generation_number();
|
||||
generation = utils::get_generation_number();
|
||||
} else {
|
||||
// Other nodes will ignore gossip messages about a node that have a lower generation than previously seen.
|
||||
int stored_generation = rs->one().template get_as<int>("gossip_generation") + 1;
|
||||
int now = service::get_generation_number();
|
||||
int now = utils::get_generation_number();
|
||||
if (stored_generation >= now) {
|
||||
slogger.warn("Using stored Gossip Generation {} as it is greater than current system time {}."
|
||||
"See CASSANDRA-3654 if you experience problems", stored_generation, now);
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
#include "gms/failure_detector.hh"
|
||||
#include "gms/i_failure_detection_event_listener.hh"
|
||||
#include "gms/i_endpoint_state_change_subscriber.hh"
|
||||
#include "service/storage_service.hh"
|
||||
#include "message/messaging_service.hh"
|
||||
#include "database.hh"
|
||||
#include "log.hh"
|
||||
@@ -62,6 +61,7 @@
|
||||
#include "db/config.hh"
|
||||
#include <boost/range/algorithm/set_algorithm.hpp>
|
||||
#include <boost/range/adaptors.hpp>
|
||||
#include "utils/generation-number.hh"
|
||||
|
||||
namespace gms {
|
||||
|
||||
@@ -589,7 +589,7 @@ future<> gossiper::apply_state_locally(std::map<inet_address, endpoint_state> ma
|
||||
int local_generation = local_ep_state_ptr.get_heart_beat_state().get_generation();
|
||||
int remote_generation = remote_state.get_heart_beat_state().get_generation();
|
||||
logger.trace("{} local generation {}, remote generation {}", ep, local_generation, remote_generation);
|
||||
if (remote_generation > service::get_generation_number() + MAX_GENERATION_DIFFERENCE) {
|
||||
if (remote_generation > utils::get_generation_number() + MAX_GENERATION_DIFFERENCE) {
|
||||
// assume some peer has corrupted memory and is broadcasting an unbelievable generation about another peer (or itself)
|
||||
logger.warn("received an invalid gossip generation for peer {}; local generation = {}, received generation = {}",
|
||||
ep, local_generation, remote_generation);
|
||||
|
||||
@@ -82,6 +82,7 @@
|
||||
#include "cdc/generation.hh"
|
||||
#include "repair/repair.hh"
|
||||
#include "service/priority_manager.hh"
|
||||
#include "utils/generation-number.hh"
|
||||
|
||||
using token = dht::token;
|
||||
using UUID = utils::UUID;
|
||||
@@ -95,14 +96,6 @@ static logging::logger slogger("storage_service");
|
||||
|
||||
distributed<storage_service> _the_storage_service;
|
||||
|
||||
|
||||
int get_generation_number() {
|
||||
using namespace std::chrono;
|
||||
auto now = high_resolution_clock::now().time_since_epoch();
|
||||
int generation_number = duration_cast<seconds>(now).count();
|
||||
return generation_number;
|
||||
}
|
||||
|
||||
storage_service::storage_service(abort_source& abort_source, distributed<database>& db, gms::gossiper& gossiper, sharded<auth::service>& auth_service, sharded<db::system_distributed_keyspace>& sys_dist_ks,
|
||||
sharded<db::view::view_update_generator>& view_update_generator, gms::feature_service& feature_service, storage_service_config config, sharded<service::migration_notifier>& mn, locator::token_metadata& tm, bool for_testing)
|
||||
: _abort_source(abort_source)
|
||||
@@ -1949,7 +1942,7 @@ future<> storage_service::start_gossiping(bind_messaging_port do_bind) {
|
||||
ss.set_gossip_tokens(db::system_keyspace::get_local_tokens().get0(),
|
||||
cdc_enabled ? std::make_optional(cdc::get_local_streams_timestamp().get0()) : std::nullopt);
|
||||
ss._gossiper.force_newer_generation();
|
||||
ss._gossiper.start_gossiping(get_generation_number(), gms::bind_messaging_port(bool(do_bind))).then([&ss] {
|
||||
ss._gossiper.start_gossiping(utils::get_generation_number(), gms::bind_messaging_port(bool(do_bind))).then([&ss] {
|
||||
ss._initialized = true;
|
||||
}).get();
|
||||
}
|
||||
|
||||
@@ -99,8 +99,6 @@ inline storage_service& get_local_storage_service() {
|
||||
return _the_storage_service.local();
|
||||
}
|
||||
|
||||
int get_generation_number();
|
||||
|
||||
enum class disk_error { regular, commit };
|
||||
|
||||
struct bind_messaging_port_tag {};
|
||||
|
||||
34
utils/generation-number.cc
Normal file
34
utils/generation-number.cc
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2020 ScyllaDB
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is part of Scylla.
|
||||
*
|
||||
* Scylla is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Scylla is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <chrono>
|
||||
#include "generation-number.hh"
|
||||
|
||||
namespace utils {
|
||||
|
||||
int get_generation_number() {
|
||||
using namespace std::chrono;
|
||||
auto now = high_resolution_clock::now().time_since_epoch();
|
||||
int generation_number = duration_cast<seconds>(now).count();
|
||||
return generation_number;
|
||||
}
|
||||
|
||||
}
|
||||
28
utils/generation-number.hh
Normal file
28
utils/generation-number.hh
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2020 ScyllaDB
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is part of Scylla.
|
||||
*
|
||||
* Scylla is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Scylla is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace utils {
|
||||
|
||||
int get_generation_number();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user