do not allow custom database for system tables

This commit is contained in:
Alexander Tokmakov 2020-03-02 20:25:36 +03:00
parent a4d12b31a1
commit fa27ecf353
4 changed files with 19 additions and 12 deletions

View File

@ -1557,7 +1557,7 @@ std::shared_ptr<QueryLog> Context::getQueryLog()
{
auto lock = getLock();
if (!shared->system_logs || !shared->system_logs->query_log)
if (!shared->system_logs)
return {};
return shared->system_logs->query_log;
@ -1568,7 +1568,7 @@ std::shared_ptr<QueryThreadLog> Context::getQueryThreadLog()
{
auto lock = getLock();
if (!shared->system_logs || !shared->system_logs->query_thread_log)
if (!shared->system_logs)
return {};
return shared->system_logs->query_thread_log;
@ -1580,13 +1580,13 @@ std::shared_ptr<PartLog> Context::getPartLog(const String & part_database)
auto lock = getLock();
/// No part log or system logs are shutting down.
if (!shared->system_logs || !shared->system_logs->part_log)
if (!shared->system_logs)
return {};
/// Will not log operations on system tables (including part_log itself).
/// It doesn't make sense and not allow to destruct PartLog correctly due to infinite logging and flushing,
/// and also make troubles on startup.
if (part_database == shared->system_logs->part_log_database)
if (part_database == DatabaseCatalog::SYSTEM_DATABASE)
return {};
return shared->system_logs->part_log;
@ -1597,7 +1597,7 @@ std::shared_ptr<TraceLog> Context::getTraceLog()
{
auto lock = getLock();
if (!shared->system_logs || !shared->system_logs->trace_log)
if (!shared->system_logs)
return {};
return shared->system_logs->trace_log;
@ -1608,7 +1608,7 @@ std::shared_ptr<TextLog> Context::getTextLog()
{
auto lock = getLock();
if (!shared->system_logs || !shared->system_logs->text_log)
if (!shared->system_logs)
return {};
return shared->system_logs->text_log;
@ -1619,7 +1619,7 @@ std::shared_ptr<MetricLog> Context::getMetricLog()
{
auto lock = getLock();
if (!shared->system_logs || !shared->system_logs->metric_log)
if (!shared->system_logs)
return {};
return shared->system_logs->metric_log;

View File

@ -7,6 +7,7 @@
#include <Interpreters/MetricLog.h>
#include <Poco/Util/AbstractConfiguration.h>
#include <common/logger_useful.h>
namespace DB
@ -37,6 +38,15 @@ std::shared_ptr<TSystemLog> createSystemLog(
String database = config.getString(config_prefix + ".database", default_database_name);
String table = config.getString(config_prefix + ".table", default_table_name);
if (database != default_database_name)
{
/// System tables must be loaded before other tables, but loading order is undefined for all databases except `system`
LOG_ERROR(&Logger::get("SystemLog"), "Custom database name for a system table specified in config. "
"Table `" << table << "` will be created in `system` database "
"instead of `" << database << "`");
database = default_database_name;
}
String engine;
if (config.has(config_prefix + ".engine"))
{
@ -72,8 +82,6 @@ SystemLogs::SystemLogs(Context & global_context, const Poco::Util::AbstractConfi
size_t collect_interval_milliseconds = config.getUInt64("metric_log.collect_interval_milliseconds");
metric_log->startCollectMetric(collect_interval_milliseconds);
}
part_log_database = config.getString("part_log.database", "system");
}

View File

@ -82,8 +82,6 @@ struct SystemLogs
std::shared_ptr<TraceLog> trace_log; /// Used to log traces from query profiler
std::shared_ptr<TextLog> text_log; /// Used to log all text messages.
std::shared_ptr<MetricLog> metric_log; /// Used to log all metrics.
String part_log_database;
};
@ -176,6 +174,7 @@ SystemLog<LogElement>::SystemLog(Context & context_,
, storage_def(storage_def_),
flush_interval_milliseconds(flush_interval_milliseconds_)
{
assert(database_name_ == DatabaseCatalog::SYSTEM_DATABASE);
log = &Logger::get("SystemLog (" + database_name_ + "." + table_name_ + ")");
saving_thread = ThreadFromGlobalPool([this] { savingThreadFunction(); });

View File

@ -5,4 +5,4 @@ CREATE DATABASE memory_01069 ENGINE = Memory()
4
3
4
CREATE TABLE memory_01069.file (`n` UInt8) ENGINE = File(CSV)
CREATE TABLE memory_01069.file (`n` UInt8) ENGINE = File(\'CSV\')