diff --git a/src/facade/dragonfly_listener.cc b/src/facade/dragonfly_listener.cc index 05e681de1f2..528461e5ff4 100644 --- a/src/facade/dragonfly_listener.cc +++ b/src/facade/dragonfly_listener.cc @@ -7,7 +7,6 @@ #ifdef DFLY_USE_SSL #include #endif - #include "base/flags.h" #include "base/logging.h" #include "facade/dragonfly_connection.h" @@ -27,6 +26,9 @@ ABSL_FLAG(string, tls_cert_file, "", "cert file for tls connections"); ABSL_FLAG(string, tls_key_file, "", "key file for tls connections"); ABSL_FLAG(string, tls_ca_cert_file, "", "ca signed certificate to validate tls connections"); ABSL_FLAG(string, tls_ca_cert_dir, "", "ca signed certificates directory"); +ABSL_FLAG(uint32_t, tcp_keepalive, 300, + "the period in seconds of inactivity after which keep-alives are triggerred," + "the duration until an inactive connection is terminated is twice the specified time"); #if 0 enum TlsClientAuth { @@ -99,21 +101,19 @@ SSL_CTX* CreateSslServerCntx() { } #endif -bool ConfigureKeepAlive(int fd, unsigned interval_sec) { - DCHECK_GT(interval_sec, 3u); - +bool ConfigureKeepAlive(int fd) { int val = 1; if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) < 0) return false; - val = interval_sec; + val = absl::GetFlag(FLAGS_tcp_keepalive); if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &val, sizeof(val)) < 0) return false; /* Send next probes after the specified interval. Note that we set the * delay as interval / 3, as we send three probes before detecting * an error (see the next setsockopt call). */ - val = interval_sec / 3; + val = std::max(val / 3, 1); if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &val, sizeof(val)) < 0) return false; @@ -153,12 +153,11 @@ util::Connection* Listener::NewConnection(ProactorBase* proactor) { error_code Listener::ConfigureServerSocket(int fd) { int val = 1; - constexpr int kInterval = 300; // 300 seconds is ok to start checking for liveness. if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) { LOG(WARNING) << "Could not set reuse addr on socket " << SafeErrorMessage(errno); } - bool success = ConfigureKeepAlive(fd, kInterval); + bool success = ConfigureKeepAlive(fd); if (!success) { int myerr = errno; diff --git a/src/server/config_registry.cc b/src/server/config_registry.cc index c805614badb..d0622bd5891 100644 --- a/src/server/config_registry.cc +++ b/src/server/config_registry.cc @@ -21,6 +21,10 @@ ConfigRegistry& ConfigRegistry::Register(std::string_view name, WriteCb cb) { return *this; } +ConfigRegistry& ConfigRegistry::Register(std::string_view name) { + return Register(name, [](const absl::CommandLineFlag& flag) { return true; }); +} + // Returns true if the value was updated. bool ConfigRegistry::Set(std::string_view config_name, std::string_view value) { unique_lock lk(mu_); diff --git a/src/server/config_registry.h b/src/server/config_registry.h index 92eb4d1a568..b1ac336a0cf 100644 --- a/src/server/config_registry.h +++ b/src/server/config_registry.h @@ -15,6 +15,7 @@ class ConfigRegistry { using WriteCb = std::function; ConfigRegistry& Register(std::string_view name, WriteCb cb); + ConfigRegistry& Register(std::string_view name); // Returns true if the value was updated. bool Set(std::string_view config_name, std::string_view value); diff --git a/src/server/main_service.cc b/src/server/main_service.cc index 758450bdaf9..23e14cb0d18 100644 --- a/src/server/main_service.cc +++ b/src/server/main_service.cc @@ -622,6 +622,11 @@ void Service::Init(util::AcceptServer* acceptor, std::vector return true; }); + config_registry.Register("dir"); + config_registry.Register("requirepass"); + config_registry.Register("masterauth"); + config_registry.Register("tcp_keepalive"); + pp_.Await([](uint32_t index, ProactorBase* pb) { ServerState::Init(index); }); uint32_t shard_num = GetFlag(FLAGS_num_shards); diff --git a/src/server/server_family.cc b/src/server/server_family.cc index 146b73b6ae7..92dee420fb2 100644 --- a/src/server/server_family.cc +++ b/src/server/server_family.cc @@ -388,7 +388,7 @@ GenericError ValidateFilename(const fs::path& filename, bool new_version) { if (!filename.parent_path().empty() && !is_cloud_path) { return {absl::StrCat("filename may not contain directory separators (Got \"", filename.c_str(), - "\")")}; + "\"). dbfilename should specify the filename without the directory")}; } if (!filename.has_extension()) {