mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2026-10-28 16:18:23 +08:00
`config()` has a writable layer at `PRIO_APPLICATION` where `Poco::Util::Application` puts
`application.name`, `application.dir` and the other `application.*` properties. The reload
snapshot of the file, the command line and `SystemConfiguration` did not have it, so
`${application.name}` stayed literal on reload: a masking rule written with it masked at
startup and silently stopped masking after the first `SYSTEM RELOAD CONFIG`, for a rule in
the file as well as for one on the command line.
Copy the `application.*` properties at the start of `Server::initialize`, before
`BaseDaemon::initialize` adds the command line and the file, and add that copy to every
reload snapshot at `PRIO_APPLICATION`. Copying them from `config()` at reload time instead
would also capture an `application.*` key of the previous file (a file can have one only with
`skip_check_for_incorrect_settings`) above the reloaded file. The snapshot now has the same
sources as `config()`: the command line, the application properties, the file and the system
properties.
The masking test now uses `${application.name}_${system.env.MASK_PATTERN}`, so it covers both
property sources: it fails on the previous head after the reload and passes here.
Reported by the review bot on #124915:
https://github.com/ClickHouse/ClickHouse/pull/124915#discussion_r4270445050
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
146 lines
4.4 KiB
C++
146 lines
4.4 KiB
C++
#pragma once
|
|
|
|
#include <Core/ServerSettings.h>
|
|
#include <Server/IServer.h>
|
|
|
|
#include <Daemon/BaseDaemon.h>
|
|
#include <Server/HTTP/HTTPContext.h>
|
|
#include <Server/TCPProtocolStackFactory.h>
|
|
#include <Server/ServerType.h>
|
|
#include <Poco/Net/HTTPServerParams.h>
|
|
|
|
/** Server provides three interfaces:
|
|
* 1. HTTP - simple interface for any applications.
|
|
* 2. TCP - interface for native clickhouse-client and for server to server internal communications.
|
|
* More rich and efficient, but less compatible
|
|
* - data is transferred by columns;
|
|
* - data is transferred compressed;
|
|
* Allows to get more information in response.
|
|
* 3. Interserver HTTP - for replication.
|
|
*/
|
|
|
|
namespace Poco
|
|
{
|
|
namespace Net
|
|
{
|
|
class ServerSocket;
|
|
}
|
|
}
|
|
|
|
namespace DB
|
|
{
|
|
class AsynchronousMetrics;
|
|
class ProtocolServerAdapter;
|
|
|
|
class Server : public BaseDaemon, public IServer
|
|
{
|
|
public:
|
|
using ServerApplication::run;
|
|
|
|
// Please register settings in ServerSettings.cpp instead of accessing the config directly if possible.
|
|
Poco::Util::LayeredConfiguration & config() const override
|
|
{
|
|
return BaseDaemon::config();
|
|
}
|
|
|
|
Poco::Logger & logger() const override
|
|
{
|
|
return BaseDaemon::logger();
|
|
}
|
|
|
|
ContextMutablePtr context() const override
|
|
{
|
|
return global_context;
|
|
}
|
|
|
|
bool isCancelled() const override
|
|
{
|
|
return BaseDaemon::isCancelled();
|
|
}
|
|
|
|
void defineOptions(Poco::Util::OptionSet & _options) override;
|
|
|
|
protected:
|
|
int run() override;
|
|
|
|
void initialize(Application & self) override;
|
|
|
|
void uninitialize() override;
|
|
|
|
int main(const std::vector<std::string> & args) override;
|
|
|
|
std::string getDefaultCorePath() const override;
|
|
|
|
private:
|
|
ContextMutablePtr global_context;
|
|
/// Updated/recent config, to compare http_handlers
|
|
ConfigurationPtr latest_config;
|
|
/// The `application.*` properties that `Poco::Util::Application` sets before any file or command-line layer is added.
|
|
ConfigurationPtr application_properties;
|
|
|
|
HTTPContextPtr httpContext() const;
|
|
|
|
Poco::Net::SocketAddress socketBindListen(
|
|
const ServerSettings & server_settings,
|
|
Poco::Net::ServerSocket & socket,
|
|
const std::string & host,
|
|
UInt16 port,
|
|
[[maybe_unused]] bool secure = false) const;
|
|
|
|
std::unique_ptr<TCPProtocolStackFactory> buildProtocolStackFromConfig(
|
|
const Poco::Util::AbstractConfiguration & config,
|
|
const ServerSettings & server_settings,
|
|
const std::string & protocol,
|
|
Poco::Net::HTTPServerParams::Ptr http_params,
|
|
AsynchronousMetrics & async_metrics,
|
|
bool & is_secure,
|
|
ServerType::Type & protocol_type);
|
|
|
|
using CreateServerFunc = std::function<ProtocolServerAdapter(UInt16)>;
|
|
void createServer(
|
|
Poco::Util::AbstractConfiguration & config,
|
|
const std::string & listen_host,
|
|
const char * port_name,
|
|
bool listen_try,
|
|
bool start_server,
|
|
std::vector<ProtocolServerAdapter> & servers,
|
|
CreateServerFunc && func) const;
|
|
|
|
void createServers(
|
|
Poco::Util::AbstractConfiguration & config,
|
|
const ServerSettings & server_settings,
|
|
const Strings & listen_hosts,
|
|
bool listen_try,
|
|
Poco::ThreadPool & server_pool,
|
|
AsynchronousMetrics & async_metrics,
|
|
std::vector<ProtocolServerAdapter> & servers,
|
|
bool start_servers = false,
|
|
const ServerType & server_type = ServerType(ServerType::Type::QUERIES_ALL),
|
|
bool only_introspection_protocols = false);
|
|
|
|
void createInterserverServers(
|
|
Poco::Util::AbstractConfiguration & config,
|
|
const ServerSettings & server_settings,
|
|
const Strings & interserver_listen_hosts,
|
|
bool listen_try,
|
|
Poco::ThreadPool & server_pool,
|
|
AsynchronousMetrics & async_metrics,
|
|
std::vector<ProtocolServerAdapter> & servers,
|
|
bool start_servers = false,
|
|
const ServerType & server_type = ServerType(ServerType::Type::QUERIES_ALL));
|
|
|
|
void updateServers(
|
|
Poco::Util::AbstractConfiguration & config,
|
|
const ServerSettings & server_settings,
|
|
Poco::ThreadPool & server_pool,
|
|
AsynchronousMetrics & async_metrics,
|
|
std::vector<ProtocolServerAdapter> & servers,
|
|
std::vector<ProtocolServerAdapter> & servers_to_start_before_tables);
|
|
|
|
void stopServers(
|
|
std::vector<ProtocolServerAdapter> & servers,
|
|
const ServerType & server_type) const;
|
|
};
|
|
|
|
}
|