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

Fixed race condition in text_log #9726

Merged
merged 1 commit into from
Mar 19, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions base/loggers/OwnSplitChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ void OwnSplitChannel::logSplit(const Poco::Message & msg)


/// Also log to system.text_log table, if message is not too noisy
if (text_log_max_priority && msg.getPriority() <= text_log_max_priority)
auto text_log_max_priority_loaded = text_log_max_priority.load(std::memory_order_relaxed);
if (text_log_max_priority_loaded && msg.getPriority() <= text_log_max_priority_loaded)
{
TextLogElement elem;

Expand Down Expand Up @@ -108,7 +109,7 @@ void OwnSplitChannel::addTextLog(std::shared_ptr<DB::TextLog> log, int max_prior
{
std::lock_guard<std::mutex> lock(text_log_mutex);
text_log = log;
text_log_max_priority = max_priority;
text_log_max_priority.store(max_priority, std::memory_order_relaxed);
}

}
2 changes: 1 addition & 1 deletion base/loggers/OwnSplitChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class OwnSplitChannel : public Poco::Channel
std::mutex text_log_mutex;

std::weak_ptr<DB::TextLog> text_log;
int text_log_max_priority = -1;
std::atomic<int> text_log_max_priority = -1;
};

}