From 2acb71337fc9f42e02473eb73a40a80b757138bc Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 26 Jan 2020 14:19:04 +0300 Subject: [PATCH] Added workaround for Google Cloud Runner --- dbms/src/Common/QueryProfiler.cpp | 7 +++++++ dbms/src/Interpreters/ThreadStatusExt.cpp | 24 +++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/dbms/src/Common/QueryProfiler.cpp b/dbms/src/Common/QueryProfiler.cpp index e142be2e4d9..36041df4fd5 100644 --- a/dbms/src/Common/QueryProfiler.cpp +++ b/dbms/src/Common/QueryProfiler.cpp @@ -141,7 +141,14 @@ QueryProfilerBase::QueryProfilerBase(const Int32 thread_id, const sev._sigev_un._tid = thread_id; #endif if (timer_create(clock_type, &sev, &timer_id)) + { + /// In Google Cloud Runner, the function "timer_create" is implemented incorrectly as of 2020-01-25. + if (errno == 0) + throw Exception("Failed to create thread timer. The function 'timer_create' returned non-zero but didn't set errno. This is bug in your OS.", + ErrorCodes::CANNOT_CREATE_TIMER); + throwFromErrno("Failed to create thread timer", ErrorCodes::CANNOT_CREATE_TIMER); + } /// Randomize offset as uniform random value from 0 to period - 1. /// It will allow to sample short queries even if timer period is large. diff --git a/dbms/src/Interpreters/ThreadStatusExt.cpp b/dbms/src/Interpreters/ThreadStatusExt.cpp index 0bf1ac36d3d..80a9d75cd80 100644 --- a/dbms/src/Interpreters/ThreadStatusExt.cpp +++ b/dbms/src/Interpreters/ThreadStatusExt.cpp @@ -160,15 +160,23 @@ void ThreadStatus::initQueryProfiler() const auto & settings = query_context->getSettingsRef(); - if (settings.query_profiler_real_time_period_ns > 0) - query_profiler_real = std::make_unique( - /* thread_id */ os_thread_id, - /* period */ static_cast(settings.query_profiler_real_time_period_ns)); + try + { + if (settings.query_profiler_real_time_period_ns > 0) + query_profiler_real = std::make_unique( + /* thread_id */ os_thread_id, + /* period */ static_cast(settings.query_profiler_real_time_period_ns)); - if (settings.query_profiler_cpu_time_period_ns > 0) - query_profiler_cpu = std::make_unique( - /* thread_id */ os_thread_id, - /* period */ static_cast(settings.query_profiler_cpu_time_period_ns)); + if (settings.query_profiler_cpu_time_period_ns > 0) + query_profiler_cpu = std::make_unique( + /* thread_id */ os_thread_id, + /* period */ static_cast(settings.query_profiler_cpu_time_period_ns)); + } + catch (...) + { + /// QueryProfiler is optional. + tryLogCurrentException("ThreadStatus", "Cannot initialize QueryProfiler"); + } } void ThreadStatus::finalizeQueryProfiler()