Merge pull request #6322 from yandex/text-log-simplification

Text log simplification
This commit is contained in:
alexey-milovidov 2019-08-05 01:01:02 +03:00 committed by GitHub
commit af949cce84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 36 deletions

View File

@ -273,17 +273,13 @@ int Server::main(const std::vector<std::string> & /*args*/)
* table engines could use Context on destroy.
*/
LOG_INFO(log, "Shutting down storages.");
if (text_log)
text_log->shutdown();
global_context->shutdown();
LOG_DEBUG(log, "Shutted down storages.");
/** 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.
*/
text_log.reset();
global_context.reset();
LOG_DEBUG(log, "Destroyed global context.");
});
@ -413,7 +409,7 @@ int Server::main(const std::vector<std::string> & /*args*/)
main_config_zk_changed_event,
[&](ConfigurationPtr config)
{
setTextLog(text_log);
setTextLog(global_context->getTextLog());
buildLoggers(*config, logger());
global_context->setClustersConfig(config);
global_context->setMacros(std::make_unique<Macros>(*config, "macros"));
@ -500,14 +496,11 @@ int Server::main(const std::vector<std::string> & /*args*/)
LOG_INFO(log, "Loading metadata from " + path);
/// Create text_log instance
text_log = createSystemLog<TextLog>(*global_context, "system", "text_log", global_context->getConfigRef(), "text_log");
try
{
loadMetadataSystem(*global_context);
/// After attaching system databases we can initialize system log.
global_context->initializeSystemLogs(text_log);
global_context->initializeSystemLogs();
/// After the system database is created, attach virtual system tables (in addition to query_log and part_log)
attachSystemTablesServer(*global_context->getDatabase("system"), has_zookeeper);
/// Then, load remaining databases

View File

@ -57,7 +57,6 @@ protected:
private:
std::unique_ptr<Context> global_context;
std::shared_ptr<TextLog> text_log;
};
}

View File

@ -1645,11 +1645,10 @@ Compiler & Context::getCompiler()
}
void Context::initializeSystemLogs(std::shared_ptr<TextLog> text_log)
void Context::initializeSystemLogs()
{
auto lock = getLock();
shared->system_logs.emplace(*global_context, getConfigRef());
shared->system_logs->text_log = text_log;
}
bool Context::hasTraceCollector()
@ -1716,11 +1715,10 @@ std::shared_ptr<TextLog> Context::getTextLog()
{
auto lock = getLock();
if (!shared->system_logs)
if (auto log = shared->system_logs->text_log.lock())
return log;
if (!shared->system_logs || !shared->system_logs->text_log)
return {};
return shared->system_logs->text_log;
}

View File

@ -424,7 +424,7 @@ public:
Compiler & getCompiler();
/// Call after initialization before using system logs. Call for global context.
void initializeSystemLogs(std::shared_ptr<TextLog> text_log);
void initializeSystemLogs();
void initializeTraceCollector();
bool hasTraceCollector();

View File

@ -47,6 +47,7 @@ SystemLogs::SystemLogs(Context & global_context, const Poco::Util::AbstractConfi
query_thread_log = createSystemLog<QueryThreadLog>(global_context, "system", "query_thread_log", config, "query_thread_log");
part_log = createSystemLog<PartLog>(global_context, "system", "part_log", config, "part_log");
trace_log = createSystemLog<TraceLog>(global_context, "system", "trace_log", config, "trace_log");
text_log = createSystemLog<TextLog>(global_context, "system", "text_log", config, "text_log");
part_log_database = config.getString("part_log.database", "system");
}
@ -67,6 +68,8 @@ void SystemLogs::shutdown()
part_log->shutdown();
if (trace_log)
trace_log->shutdown();
if (text_log)
text_log->shutdown();
}
}

View File

@ -75,8 +75,7 @@ struct SystemLogs
std::shared_ptr<QueryThreadLog> query_thread_log; /// Used to log query threads.
std::shared_ptr<PartLog> part_log; /// Used to log operations with parts
std::shared_ptr<TraceLog> trace_log; /// Used to log traces from query profiler
std::weak_ptr<TextLog> text_log; /// Used to log all text. We use weak_ptr, because this log is
/// a server's field.
std::shared_ptr<TextLog> text_log; /// Used to log all text messages.
String part_log_database;
};

View File

@ -24,13 +24,15 @@ using DB::CurrentThread;
{ \
const bool is_clients_log = (CurrentThread::getGroup() != nullptr) && \
(CurrentThread::getGroup()->client_logs_level >= (priority)); \
if ((logger)->is((PRIORITY)) || is_clients_log) { \
if ((logger)->is((PRIORITY)) || is_clients_log) \
{ \
std::stringstream oss_internal_rare; \
oss_internal_rare << message; \
if (auto channel = (logger)->getChannel()) { \
if (auto channel = (logger)->getChannel()) \
{ \
std::string file_function; \
file_function += __FILE__; \
file_function += ", "; \
file_function += "; "; \
file_function += __PRETTY_FUNCTION__; \
Message poco_message((logger)->name(), oss_internal_rare.str(), \
(PRIORITY), file_function.c_str(), __LINE__); \