Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to fix ODR for Loggers class #41060

Merged
merged 6 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions programs/keeper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ if (BUILD_STANDALONE_KEEPER)

# Remove some redundant dependencies
target_compile_definitions (clickhouse-keeper PRIVATE -DKEEPER_STANDALONE_BUILD)
target_compile_definitions (clickhouse-keeper PUBLIC -DWITHOUT_TEXT_LOG)

target_include_directories(clickhouse-keeper PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../../src") # uses includes from src directory
target_include_directories(clickhouse-keeper PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/../../src/Core/include") # uses some includes from core
Expand Down
2 changes: 1 addition & 1 deletion src/Loggers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ add_headers_and_sources(loggers .)

# Standard version depends on DBMS and works with text log
add_library(loggers ${loggers_sources} ${loggers_headers})
target_compile_definitions(loggers PUBLIC WITH_TEXT_LOG=1)
target_link_libraries(loggers PRIVATE dbms clickhouse_common_io)

# Lightweight version doesn't work with textlog and also doesn't depend on DBMS
add_library(loggers_no_text_log ${loggers_sources} ${loggers_headers})
target_compile_definitions(loggers_no_text_log PUBLIC WITHOUT_TEXT_LOG=1)
target_link_libraries(loggers_no_text_log PRIVATE clickhouse_common_io)
6 changes: 3 additions & 3 deletions src/Loggers/Loggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <Poco/Logger.h>
#include <Poco/Net/RemoteSyslogChannel.h>

#ifdef WITH_TEXT_LOG
#ifndef WITHOUT_TEXT_LOG
#include <Interpreters/TextLog.h>
#endif

Expand All @@ -34,7 +34,7 @@ static std::string createDirectory(const std::string & file)
return path;
}

#ifdef WITH_TEXT_LOG
#ifndef WITHOUT_TEXT_LOG
void Loggers::setTextLog(std::shared_ptr<DB::TextLog> log, int max_priority)
{
text_log = log;
Expand All @@ -44,7 +44,7 @@ void Loggers::setTextLog(std::shared_ptr<DB::TextLog> log, int max_priority)

void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Logger & logger /*_root*/, const std::string & cmd_name)
{
#ifdef WITH_TEXT_LOG
#ifndef WITHOUT_TEXT_LOG
if (split)
if (auto log = text_log.lock())
split->addTextLog(log, text_log_max_priority);
Expand Down
6 changes: 3 additions & 3 deletions src/Loggers/Loggers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <Poco/Util/Application.h>
#include "OwnSplitChannel.h"

#ifdef WITH_TEXT_LOG
#ifndef WITHOUT_TEXT_LOG
namespace DB
{
class TextLog;
Expand All @@ -29,7 +29,7 @@ class Loggers
/// Close log files. On next log write files will be reopened.
void closeLogs(Poco::Logger & logger);

#ifdef WITH_TEXT_LOG
#ifndef WITHOUT_TEXT_LOG
void setTextLog(std::shared_ptr<DB::TextLog> log, int max_priority);
#endif

Expand All @@ -41,7 +41,7 @@ class Loggers
/// Previous value of logger element in config. It is used to reinitialize loggers whenever the value changed.
std::string config_logger;

#ifdef WITH_TEXT_LOG
#ifndef WITHOUT_TEXT_LOG
std::weak_ptr<DB::TextLog> text_log;
int text_log_max_priority = -1;
#endif
Expand Down
6 changes: 3 additions & 3 deletions src/Loggers/OwnSplitChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace DB
void OwnSplitChannel::log(const Poco::Message & msg)
{

#ifdef WITH_TEXT_LOG
#ifndef WITHOUT_TEXT_LOG
auto logs_queue = CurrentThread::getInternalTextLogsQueue();

if (channels.empty() && (logs_queue == nullptr || !logs_queue->isNeeded(msg.getPriority(), msg.getSource())))
Expand Down Expand Up @@ -89,7 +89,7 @@ void OwnSplitChannel::logSplit(const Poco::Message & msg)
channel.first->log(msg); // ordinary child
}

#ifdef WITH_TEXT_LOG
#ifndef WITHOUT_TEXT_LOG
auto logs_queue = CurrentThread::getInternalTextLogsQueue();

/// Log to "TCP queue" if message is not too noisy
Expand Down Expand Up @@ -150,7 +150,7 @@ void OwnSplitChannel::addChannel(Poco::AutoPtr<Poco::Channel> channel, const std
channels.emplace(name, ExtendedChannelPtrPair(std::move(channel), dynamic_cast<ExtendedLogChannel *>(channel.get())));
}

#ifdef WITH_TEXT_LOG
#ifndef WITHOUT_TEXT_LOG
void OwnSplitChannel::addTextLog(std::shared_ptr<DB::TextLog> log, int max_priority)
{
std::lock_guard<std::mutex> lock(text_log_mutex);
Expand Down
6 changes: 3 additions & 3 deletions src/Loggers/OwnSplitChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <Poco/Channel.h>
#include "ExtendedLogChannel.h"

#ifdef WITH_TEXT_LOG
#ifndef WITHOUT_TEXT_LOG
namespace DB
{
class TextLog;
Expand All @@ -30,7 +30,7 @@ class OwnSplitChannel : public Poco::Channel
/// Adds a child channel
void addChannel(Poco::AutoPtr<Poco::Channel> channel, const std::string & name);

#ifdef WITH_TEXT_LOG
#ifndef WITHOUT_TEXT_LOG
void addTextLog(std::shared_ptr<DB::TextLog> log, int max_priority);
#endif

Expand All @@ -47,7 +47,7 @@ class OwnSplitChannel : public Poco::Channel

std::mutex text_log_mutex;

#ifdef WITH_TEXT_LOG
#ifndef WITHOUT_TEXT_LOG
std::weak_ptr<DB::TextLog> text_log;
std::atomic<int> text_log_max_priority = -1;
#endif
Expand Down