Separate thread mutex, add test

This commit is contained in:
Dmitry Kardymon 2023-07-19 08:46:57 +00:00
parent d601d86fad
commit aa888ad64a
6 changed files with 8 additions and 3 deletions

View File

@ -214,7 +214,7 @@ SystemLogBase<LogElement>::SystemLogBase(
template <typename LogElement>
void SystemLogBase<LogElement>::startup()
{
std::lock_guard lock(queue->mutex);
std::lock_guard lock(thread_mutex);
saving_thread = std::make_unique<ThreadFromGlobalPool>([this] { savingThreadFunction(); });
}

View File

@ -67,6 +67,7 @@ public:
virtual void savingThreadFunction() = 0;
protected:
std::mutex thread_mutex;
std::unique_ptr<ThreadFromGlobalPool> saving_thread;
bool is_shutdown = false;
@ -93,10 +94,10 @@ public:
Index pop(std::vector<LogElement>& output, bool& should_prepare_tables_anyway, bool& exit_this_thread);
void confirm(Index to_flush_end);
private:
/// Data shared between callers of add()/flush()/shutdown(), and the saving thread
std::mutex mutex;
private:
Poco::Logger * log;
// Queue is bounded. But its size is quite large to not block in all normal cases.

View File

@ -358,7 +358,7 @@ template <typename LogElement>
void SystemLog<LogElement>::stopFlushThread()
{
{
std::lock_guard lock(queue->mutex);
std::lock_guard lock(thread_mutex);
if (!saving_thread || !saving_thread->joinable())
return;

View File

@ -124,6 +124,7 @@ protected:
using ISystemLog::is_shutdown;
using ISystemLog::saving_thread;
using ISystemLog::thread_mutex;
using Base::queue;
private:

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,2 @@
SYSTEM FLUSH LOGS;
SELECT count() > 0 FROM system.text_log WHERE event_date >= yesterday() AND message LIKE '%Application: Starting ClickHouse%';