From c1b95e8b3c1a9334d60ba14fef9b8cd31478b4f1 Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Fri, 29 Sep 2023 10:56:52 +0000 Subject: [PATCH] Suppress error statistics update for internal exceptions --- src/Common/Exception.cpp | 5 +++++ src/Common/Exception.h | 12 ++++++++++++ src/Storages/System/StorageSystemFunctions.cpp | 1 + 3 files changed, 18 insertions(+) diff --git a/src/Common/Exception.cpp b/src/Common/Exception.cpp index 6d4d2aa080a..684392b2c3a 100644 --- a/src/Common/Exception.cpp +++ b/src/Common/Exception.cpp @@ -52,6 +52,8 @@ void abortOnFailedAssertion(const String & description) bool terminate_on_any_exception = false; +thread_local bool update_error_statistics = true; + /// - Aborts the process if error code is LOGICAL_ERROR. /// - Increments error codes statistics. void handle_error_code([[maybe_unused]] const std::string & msg, int code, bool remote, const Exception::FramePointers & trace) @@ -65,6 +67,9 @@ void handle_error_code([[maybe_unused]] const std::string & msg, int code, bool } #endif + if (!update_error_statistics) [[unlikely]] + return; + ErrorCodes::increment(code, remote, msg, trace); } diff --git a/src/Common/Exception.h b/src/Common/Exception.h index 086837f2886..b2411e256ed 100644 --- a/src/Common/Exception.h +++ b/src/Common/Exception.h @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -23,6 +24,17 @@ void abortOnFailedAssertion(const String & description); /// This flag can be set for testing purposes - to check that no exceptions are thrown. extern bool terminate_on_any_exception; +/// This flag controls if error statistics should be updated when an exception is thrown. These +/// statistics are shown for example in system.errors. Defaults to true. If the error is internal, +/// non-critical, and handled otherwise it is useful to disable the statistics update and not +/// alarm the user needlessly. +extern thread_local bool update_error_statistics; + +/// Disable the update of error statistics +#define DO_NOT_UPDATE_ERROR_STATISTICS() \ + update_error_statistics = false; \ + SCOPE_EXIT({ update_error_statistics = true; }) + class Exception : public Poco::Exception { diff --git a/src/Storages/System/StorageSystemFunctions.cpp b/src/Storages/System/StorageSystemFunctions.cpp index 776371a3835..0e2e3d1d03e 100644 --- a/src/Storages/System/StorageSystemFunctions.cpp +++ b/src/Storages/System/StorageSystemFunctions.cpp @@ -141,6 +141,7 @@ void StorageSystemFunctions::fillData(MutableColumns & res_columns, ContextPtr c std::optional is_deterministic; try { + DO_NOT_UPDATE_ERROR_STATISTICS(); is_deterministic = functions_factory.tryGet(function_name, context)->isDeterministic(); } catch (const Exception & e)