Add requested changes. [#CLICKHOUSE-3645]

This commit is contained in:
Vitaliy Lyudvichenko 2018-04-23 17:40:23 +03:00 committed by alexey-milovidov
parent 8746149965
commit 864dc0546b
4 changed files with 35 additions and 37 deletions

View File

@ -25,6 +25,36 @@ namespace ErrorCodes
}
/// Call it inside catch section
/// Returns true if it is a network error
static bool isNetworkError()
{
try
{
throw;
}
catch (const Exception & e)
{
if (e.code() == ErrorCodes::TIMEOUT_EXCEEDED || e.code() == ErrorCodes::ALL_CONNECTION_TRIES_FAILED)
return true;
}
catch (Poco::Net::DNSException & e)
{
return true;
}
catch (Poco::TimeoutException & e)
{
return true;
}
catch (...)
{
/// Do nothing
}
return false;
}
DNSCacheUpdater::DNSCacheUpdater(Context & context_)
: context(context_), pool(context_.getBackgroundPool())
{
@ -73,7 +103,7 @@ DNSCacheUpdater::~DNSCacheUpdater()
}
bool DNSCacheUpdater::incrementNetworkErrors()
bool DNSCacheUpdater::incrementNetworkErrorEventsIfNeeded()
{
if (isNetworkError())
{
@ -84,33 +114,5 @@ bool DNSCacheUpdater::incrementNetworkErrors()
return false;
}
bool DNSCacheUpdater::isNetworkError()
{
try
{
throw;
}
catch (const Exception & e)
{
if (e.code() == ErrorCodes::TIMEOUT_EXCEEDED || e.code() == ErrorCodes::ALL_CONNECTION_TRIES_FAILED)
return true;
}
catch (Poco::Net::DNSException & e)
{
return true;
}
catch (Poco::TimeoutException & e)
{
return true;
}
catch (...)
{
/// Do nothing
}
return false;
}
}

View File

@ -15,15 +15,11 @@ class DNSCacheUpdater
{
public:
DNSCacheUpdater(Context & context);
explicit DNSCacheUpdater(Context & context);
~DNSCacheUpdater();
/// Call it inside catch section
/// Returns true if it is a network error
static bool isNetworkError();
/// Checks if it is a network error and increments ProfileEvents::NetworkErrors
static bool incrementNetworkErrors();
static bool incrementNetworkErrorEventsIfNeeded();
private:
bool run();

View File

@ -378,7 +378,7 @@ static std::tuple<ASTPtr, BlockIO> executeQueryImpl(
if (!internal)
onExceptionBeforeStart(query, context, current_time);
DNSCacheUpdater::incrementNetworkErrors();
DNSCacheUpdater::incrementNetworkErrorEventsIfNeeded();
throw;
}

View File

@ -181,7 +181,7 @@ void BackgroundProcessingPool::threadFunction()
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
DNSCacheUpdater::incrementNetworkErrors();
DNSCacheUpdater::incrementNetworkErrorEventsIfNeeded();
}
if (shutdown)