diff --git a/src/Core/SettingsQuirks.cpp b/src/Core/SettingsQuirks.cpp new file mode 100644 index 000000000000..3bf9047af3ae --- /dev/null +++ b/src/Core/SettingsQuirks.cpp @@ -0,0 +1,62 @@ +#include +#include +#include + +#ifdef __linux__ +#include +#endif + +#ifdef __linux__ +/// Detect does epoll_wait with nested epoll fds works correctly. +/// Polling nested epoll fds from epoll_wait is required for async_socket_for_remote and use_hedged_requests. +/// +/// It may not be reliable in 5.5+ [1], that has been fixed in 5.7+ [2] or 5.6.13+. +/// +/// [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=339ddb53d373 +/// [2]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0c54a6a44bf3 +bool nestedEpollWorks(Poco::Logger * log) +{ + bool nested_epoll_works = +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 5, 0)) && (LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 13)) + /// the check is correct since there will be no more 5.5.x releases. + false +#else + true +#endif + ; + + if (!nested_epoll_works) + { + if (log) + LOG_WARNING(log, "Nested epoll_wait has some issues on kernels [5.5.0, 5.6.13). You should upgrade it to avoid possible issues."); + } + return nested_epoll_works; +} +#else +bool nestedEpollWorks(Poco::Logger *) { return true; } +#endif + +namespace DB +{ + +/// Update some settings defaults to avoid some known issues. +void applySettingsQuirks(Settings & settings, Poco::Logger * log) +{ + if (!nestedEpollWorks(log)) + { + if (!settings.async_socket_for_remote.changed && settings.async_socket_for_remote) + { + settings.async_socket_for_remote = false; + if (log) + LOG_WARNING(log, "async_socket_for_remote has been disabled (you can explicitly enable it still)"); + } + if (!settings.use_hedged_requests.changed && settings.use_hedged_requests) + { + settings.use_hedged_requests = false; + if (log) + LOG_WARNING(log, "use_hedged_requests has been disabled (you can explicitly enable it still)"); + } + } +} + +} diff --git a/src/Core/SettingsQuirks.h b/src/Core/SettingsQuirks.h new file mode 100644 index 000000000000..38def8eebf2b --- /dev/null +++ b/src/Core/SettingsQuirks.h @@ -0,0 +1,16 @@ +#pragma once + +namespace Poco +{ +class Logger; +} + +namespace DB +{ + +struct Settings; + +/// Update some settings defaults to avoid some known issues. +void applySettingsQuirks(Settings & settings, Poco::Logger * log = nullptr); + +} diff --git a/src/Core/ya.make b/src/Core/ya.make index 1eae848163bd..004653d060e0 100644 --- a/src/Core/ya.make +++ b/src/Core/ya.make @@ -36,6 +36,7 @@ SRCS( Settings.cpp SettingsEnums.cpp SettingsFields.cpp + SettingsQuirks.cpp SortDescription.cpp iostream_debug_helpers.cpp diff --git a/src/Interpreters/Context.cpp b/src/Interpreters/Context.cpp index ec3fc5b8eb6b..7989ababac97 100644 --- a/src/Interpreters/Context.cpp +++ b/src/Interpreters/Context.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -1102,6 +1103,7 @@ void Context::applySettingsChanges(const SettingsChanges & changes) auto lock = getLock(); for (const SettingChange & change : changes) applySettingChange(change); + applySettingsQuirks(settings); } @@ -2300,6 +2302,8 @@ void Context::setDefaultProfiles(const Poco::Util::AbstractConfiguration & confi shared->system_profile_name = config.getString("system_profile", shared->default_profile_name); setProfile(shared->system_profile_name); + applySettingsQuirks(settings, &Poco::Logger::get("SettingsQuirks")); + shared->buffer_profile_name = config.getString("buffer_profile", shared->system_profile_name); buffer_context = std::make_shared(*this); buffer_context->setProfile(shared->buffer_profile_name);