config: Place timeout_config() into own .cc file

It's a generic helper that's used by transport, thrift and
redis (this guy has own copy of the code).

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
Message-Id: <20200306114022.8070-1-xemul@scylladb.com>
This commit is contained in:
Pavel Emelyanov
2020-03-06 14:40:22 +03:00
committed by Avi Kivity
parent de1b20ff7c
commit 7f2fc837cb
5 changed files with 43 additions and 26 deletions

View File

@@ -490,6 +490,7 @@ scylla_core = (['database.cc',
'frozen_schema.cc',
'schema_registry.cc',
'bytes.cc',
'timeout_config.cc',
'mutation.cc',
'mutation_fragment.cc',
'partition_version.cc',

View File

@@ -19,6 +19,7 @@
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
*/
#include "timeout_config.hh"
#include "redis/service.hh"
#include "redis/keyspace_utils.hh"
#include "redis/server.hh"
@@ -45,18 +46,6 @@ future<> redis_service::listen(distributed<auth::service>& auth_service, db::con
auto server = make_shared<distributed<redis_transport::redis_server>>();
_server = server;
auto make_timeout_config = [] (db::config& cfg) {
timeout_config tc;
tc.read_timeout = cfg.read_request_timeout_in_ms() * 1ms;
tc.write_timeout = cfg.write_request_timeout_in_ms() * 1ms;
tc.range_read_timeout = cfg.range_request_timeout_in_ms() * 1ms;
tc.counter_write_timeout = cfg.counter_write_request_timeout_in_ms() * 1ms;
tc.truncate_timeout = cfg.truncate_request_timeout_in_ms() * 1ms;
tc.cas_timeout = cfg.cas_contention_timeout_in_ms() * 1ms;
tc.other_timeout = cfg.request_timeout_in_ms() * 1ms;
return tc;
};
auto addr = cfg.rpc_address();
auto preferred = cfg.rpc_interface_prefer_ipv6() ? std::make_optional(net::inet_address::family::INET6) : std::nullopt;
auto family = cfg.enable_ipv6_dns_lookup() || preferred ? std::nullopt : std::make_optional(net::inet_address::family::INET);

View File

@@ -86,8 +86,6 @@ using token = dht::token;
using UUID = utils::UUID;
using inet_address = gms::inet_address;
using namespace std::chrono_literals;
extern logging::logger cdc_log;
namespace service {
@@ -99,18 +97,6 @@ static const sstring SSTABLE_FORMAT_PARAM_NAME = "sstable_format";
distributed<storage_service> _the_storage_service;
timeout_config make_timeout_config(const db::config& cfg) {
timeout_config tc;
tc.read_timeout = cfg.read_request_timeout_in_ms() * 1ms;
tc.write_timeout = cfg.write_request_timeout_in_ms() * 1ms;
tc.range_read_timeout = cfg.range_request_timeout_in_ms() * 1ms;
tc.counter_write_timeout = cfg.counter_write_request_timeout_in_ms() * 1ms;
tc.truncate_timeout = cfg.truncate_request_timeout_in_ms() * 1ms;
tc.cas_timeout = cfg.cas_contention_timeout_in_ms() * 1ms;
tc.other_timeout = cfg.request_timeout_in_ms() * 1ms;
return tc;
}
int get_generation_number() {
using namespace std::chrono;
auto now = high_resolution_clock::now().time_since_epoch();

38
timeout_config.cc Normal file
View File

@@ -0,0 +1,38 @@
/*
* Copyright (C) 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 "timeout_config.hh"
#include "db/config.hh"
using namespace std::chrono_literals;
timeout_config make_timeout_config(const db::config& cfg) {
timeout_config tc;
tc.read_timeout = cfg.read_request_timeout_in_ms() * 1ms;
tc.write_timeout = cfg.write_request_timeout_in_ms() * 1ms;
tc.range_read_timeout = cfg.range_request_timeout_in_ms() * 1ms;
tc.counter_write_timeout = cfg.counter_write_request_timeout_in_ms() * 1ms;
tc.truncate_timeout = cfg.truncate_request_timeout_in_ms() * 1ms;
tc.cas_timeout = cfg.cas_contention_timeout_in_ms() * 1ms;
tc.other_timeout = cfg.request_timeout_in_ms() * 1ms;
return tc;
}

View File

@@ -37,3 +37,6 @@ struct timeout_config {
using timeout_config_selector = db::timeout_clock::duration (timeout_config::*);
extern const timeout_config infinite_timeout_config;
namespace db { class config; }
timeout_config make_timeout_config(const db::config& cfg);