mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 16:50:48 +00:00
Merged with master #2609
This commit is contained in:
parent
7cc867de0a
commit
e9a3c93ef0
@ -1545,7 +1545,7 @@ void Context::initializeSystemLogs()
|
||||
}
|
||||
|
||||
|
||||
QueryLog * Context::getQueryLog(bool create_if_not_exists)
|
||||
QueryLog * Context::getQueryLog()
|
||||
{
|
||||
auto lock = getLock();
|
||||
|
||||
@ -1556,7 +1556,7 @@ QueryLog * Context::getQueryLog(bool create_if_not_exists)
|
||||
}
|
||||
|
||||
|
||||
QueryThreadLog * Context::getQueryThreadLog(bool create_if_not_exists)
|
||||
QueryThreadLog * Context::getQueryThreadLog()
|
||||
{
|
||||
auto lock = getLock();
|
||||
|
||||
@ -1567,7 +1567,7 @@ QueryThreadLog * Context::getQueryThreadLog(bool create_if_not_exists)
|
||||
}
|
||||
|
||||
|
||||
PartLog * Context::getPartLog(const String & part_database, bool create_if_not_exists)
|
||||
PartLog * Context::getPartLog(const String & part_database)
|
||||
{
|
||||
auto lock = getLock();
|
||||
|
||||
|
@ -389,12 +389,12 @@ public:
|
||||
void initializeSystemLogs();
|
||||
|
||||
/// Nullptr if the query log is not ready for this moment.
|
||||
QueryLog * getQueryLog(bool create_if_not_exists = true);
|
||||
QueryThreadLog * getQueryThreadLog(bool create_if_not_exists = true);
|
||||
QueryLog * getQueryLog();
|
||||
QueryThreadLog * getQueryThreadLog();
|
||||
|
||||
/// Returns an object used to log opertaions with parts if it possible.
|
||||
/// Provide table name to make required cheks.
|
||||
PartLog * getPartLog(const String & part_database, bool create_if_not_exists = true);
|
||||
PartLog * getPartLog(const String & part_database);
|
||||
|
||||
const MergeTreeSettings & getMergeTreeSettings() const;
|
||||
|
||||
|
@ -206,9 +206,9 @@ BlockIO InterpreterSystemQuery::execute()
|
||||
break;
|
||||
case Type::FLUSH_LOGS:
|
||||
executeCommandsAndThrowIfError(
|
||||
[&] () { if (auto query_log = context.getQueryLog(false)) query_log->flush(); },
|
||||
[&] () { if (auto part_log = context.getPartLog("", false)) part_log->flush(); },
|
||||
[&] () { if (auto query_thread_log = context.getQueryThreadLog(false)) query_thread_log->flush(); }
|
||||
[&] () { if (auto query_log = context.getQueryLog()) query_log->flush(); },
|
||||
[&] () { if (auto part_log = context.getPartLog("")) part_log->flush(); },
|
||||
[&] () { if (auto query_thread_log = context.getQueryThreadLog()) query_thread_log->flush(); }
|
||||
);
|
||||
break;
|
||||
case Type::STOP_LISTEN_QUERIES:
|
||||
|
@ -11,29 +11,9 @@ namespace DB
|
||||
|
||||
SystemLogs::SystemLogs(Context & global_context, const Poco::Util::AbstractConfiguration & config)
|
||||
{
|
||||
{
|
||||
String database = config.getString("query_log.database", "system");
|
||||
String table = config.getString("query_log.table", "query_log");
|
||||
String partition_by = config.getString("query_log.partition_by", "toYYYYMM(event_date)");
|
||||
size_t flush_interval_milliseconds = config.getUInt64("query_log.flush_interval_milliseconds", DEFAULT_QUERY_LOG_FLUSH_INTERVAL_MILLISECONDS);
|
||||
|
||||
String engine = "ENGINE = MergeTree PARTITION BY (" + partition_by + ") ORDER BY (event_date, event_time) SETTINGS index_granularity = 1024";
|
||||
|
||||
query_log = std::make_unique<QueryLog>(global_context, database, table, engine, flush_interval_milliseconds);
|
||||
}
|
||||
|
||||
if (config.has("part_log"))
|
||||
{
|
||||
part_log_database = config.getString("part_log.database", "system");
|
||||
|
||||
String table = config.getString("part_log.table", "part_log");
|
||||
String partition_by = config.getString("query_log.partition_by", "toYYYYMM(event_date)");
|
||||
size_t flush_interval_milliseconds = config.getUInt64("part_log.flush_interval_milliseconds", DEFAULT_QUERY_LOG_FLUSH_INTERVAL_MILLISECONDS);
|
||||
|
||||
String engine = "ENGINE = MergeTree PARTITION BY (" + partition_by + ") ORDER BY (event_date, event_time) SETTINGS index_granularity = 1024";
|
||||
|
||||
part_log = std::make_unique<PartLog>(global_context, part_log_database, table, engine, flush_interval_milliseconds);
|
||||
}
|
||||
query_log = createDefaultSystemLog<QueryLog>(global_context, "system", "query_log", config, "query_log");
|
||||
query_thread_log = createDefaultSystemLog<QueryThreadLog>(global_context, "system", "query_thread_log", config, "query_thread_log");
|
||||
part_log = createDefaultSystemLog<PartLog>(global_context, "system", "part_log", config, "part_log");
|
||||
}
|
||||
|
||||
|
||||
|
@ -375,23 +375,23 @@ void SystemLog<LogElement>::prepareTable()
|
||||
is_prepared = true;
|
||||
}
|
||||
|
||||
/// Creates a system log with MergeTree engines using parameters from config
|
||||
/// Creates a system log with MergeTree engine using parameters from config
|
||||
template<typename TSystemLog>
|
||||
std::unique_ptr<TSystemLog> createDefaultSystemLog(
|
||||
Context & context_,
|
||||
const String & default_database_name,
|
||||
const String & default_table_name,
|
||||
Poco::Util::AbstractConfiguration & config,
|
||||
const String & config_prefix)
|
||||
Context & context,
|
||||
const String & default_database_name,
|
||||
const String & default_table_name,
|
||||
const Poco::Util::AbstractConfiguration & config,
|
||||
const String & config_prefix)
|
||||
{
|
||||
String database = config.getString(config_prefix + ".database", default_database_name);
|
||||
String table = config.getString(config_prefix + ".table", default_table_name);
|
||||
String database = config.getString(config_prefix + ".database", default_database_name);
|
||||
String table = config.getString(config_prefix + ".table", default_table_name);
|
||||
String partition_by = config.getString(config_prefix + ".partition_by", "toYYYYMM(event_date)");
|
||||
String engine = "ENGINE = MergeTree PARTITION BY (" + partition_by + ") ORDER BY (event_date, event_time) SETTINGS index_granularity = 1024";
|
||||
|
||||
size_t flush_interval_milliseconds = config.getUInt64("query_log.flush_interval_milliseconds", DEFAULT_QUERY_LOG_FLUSH_INTERVAL_MILLISECONDS);
|
||||
size_t flush_interval_milliseconds = config.getUInt64(config_prefix + ".flush_interval_milliseconds", DEFAULT_QUERY_LOG_FLUSH_INTERVAL_MILLISECONDS);
|
||||
|
||||
return std::make_unique<TSystemLog>(context_, database, table, engine, flush_interval_milliseconds);
|
||||
return std::make_unique<TSystemLog>(context, database, table, engine, flush_interval_milliseconds);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user