Suppress error statistics update for internal exceptions

This commit is contained in:
Robert Schulze 2023-09-29 10:56:52 +00:00
parent 613f8db166
commit c1b95e8b3c
No known key found for this signature in database
GPG Key ID: 26703B55FB13728A
3 changed files with 18 additions and 0 deletions

View File

@ -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);
}

View File

@ -7,6 +7,7 @@
#include <Poco/Exception.h>
#include <base/defines.h>
#include <base/scope_guard.h>
#include <Common/StackTrace.h>
#include <Common/LoggingFormatStringHelpers.h>
@ -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
{

View File

@ -141,6 +141,7 @@ void StorageSystemFunctions::fillData(MutableColumns & res_columns, ContextPtr c
std::optional<UInt64> is_deterministic;
try
{
DO_NOT_UPDATE_ERROR_STATISTICS();
is_deterministic = functions_factory.tryGet(function_name, context)->isDeterministic();
}
catch (const Exception & e)