Better server

This commit is contained in:
alesapin 2020-12-09 11:58:41 +03:00
parent 758dcd1972
commit 0dd9c720f4

View File

@ -741,7 +741,7 @@ int Server::main(const std::vector<std::string> & /*args*/)
http_params->setTimeout(settings.http_receive_timeout);
http_params->setKeepAliveTimeout(keep_alive_timeout);
std::vector<ProtocolServerAdapter> servers;
std::vector<ProtocolServerAdapter> servers_to_start_before_tables;
std::vector<std::string> listen_hosts = DB::getMultipleValuesFromConfig(config(), "", "listen_host");
@ -762,7 +762,7 @@ int Server::main(const std::vector<std::string> & /*args*/)
auto address = socketBindListen(socket, listen_host, port);
socket.setReceiveTimeout(settings.receive_timeout);
socket.setSendTimeout(settings.send_timeout);
servers.emplace_back(std::make_unique<Poco::Net::TCPServer>(
servers_to_start_before_tables.emplace_back(std::make_unique<Poco::Net::TCPServer>(
new TestKeeperTCPHandlerFactory(*this),
server_pool,
socket,
@ -772,11 +772,9 @@ int Server::main(const std::vector<std::string> & /*args*/)
});
}
for (auto & server : servers)
for (auto & server : servers_to_start_before_tables)
server.start();
size_t already_started_servers = servers.size();
SCOPE_EXIT({
/** Ask to cancel background jobs all table engines,
* and also query_log.
@ -789,8 +787,8 @@ int Server::main(const std::vector<std::string> & /*args*/)
LOG_DEBUG(log, "Shut down storages.");
for (size_t i = 0; i < already_started_servers; ++i)
servers[i].stop();
for (auto & server : servers_to_start_before_tables)
server.stop();
/** Explicitly destroy Context. It is more convenient than in destructor of Server, because logger is still available.
* At this moment, no one could own shared part of Context.
@ -930,6 +928,7 @@ int Server::main(const std::vector<std::string> & /*args*/)
LOG_INFO(log, "TaskStats is not implemented for this OS. IO accounting will be disabled.");
#endif
std::vector<ProtocolServerAdapter> servers;
{
/// This object will periodically calculate some metrics.
AsynchronousMetrics async_metrics(*global_context,
@ -1114,8 +1113,8 @@ int Server::main(const std::vector<std::string> & /*args*/)
global_context->enableNamedSessions();
for (size_t i = already_started_servers; i < servers.size(); ++i)
servers[i].start();
for (auto & server : servers)
server.start();
{
String level_str = config().getString("text_log.level", "");
@ -1146,10 +1145,10 @@ int Server::main(const std::vector<std::string> & /*args*/)
is_cancelled = true;
int current_connections = 0;
for (size_t i = already_started_servers; i < servers.size(); ++i)
for (auto & server : servers)
{
servers[i].stop();
current_connections += servers[i].currentConnections();
server.stop();
current_connections += server.currentConnections();
}
if (current_connections)
@ -1168,10 +1167,10 @@ int Server::main(const std::vector<std::string> & /*args*/)
while (sleep_current_ms < sleep_max_ms)
{
current_connections = 0;
for (size_t i = already_started_servers; i < servers.size(); ++i)
for (auto & server : servers)
{
servers[i].stop();
current_connections += servers[i].currentConnections();
server.stop();
current_connections += server.currentConnections();
}
if (!current_connections)
break;