Skip to content

Commit

Permalink
Merge branch 'master' into optimize-like
Browse files Browse the repository at this point in the history
  • Loading branch information
solotzg authored Aug 2, 2022
2 parents 14d10ee + 4972cf3 commit 4141e41
Show file tree
Hide file tree
Showing 110 changed files with 4,549 additions and 4,264 deletions.
2 changes: 1 addition & 1 deletion contrib/googletest
Submodule googletest updated 250 files
2 changes: 2 additions & 0 deletions dbms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ include(${TiFlash_SOURCE_DIR}/cmake/dbms_glob_sources.cmake)

add_headers_and_sources(clickhouse_common_io src/Common)
add_headers_and_sources(clickhouse_common_io src/Common/HashTable)
add_headers_and_sources(clickhouse_common_io src/Common/SyncPoint)
add_headers_and_sources(clickhouse_common_io src/IO)

add_headers_and_sources(dbms src/Analyzers)
Expand Down Expand Up @@ -272,6 +273,7 @@ if (ENABLE_TESTS)
include (${TiFlash_SOURCE_DIR}/cmake/find_gtest.cmake)

if (USE_INTERNAL_GTEST_LIBRARY)
set(INSTALL_GTEST OFF)
# Google Test from sources
add_subdirectory(${TiFlash_SOURCE_DIR}/contrib/googletest/googletest ${CMAKE_CURRENT_BINARY_DIR}/googletest)
# avoid problems with <regexp.h>
Expand Down
53 changes: 34 additions & 19 deletions dbms/src/Common/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <errno.h>
#include <string.h>


namespace DB
{
namespace ErrorCodes
Expand All @@ -35,7 +34,6 @@ extern const int UNKNOWN_EXCEPTION;
extern const int CANNOT_TRUNCATE_FILE;
} // namespace ErrorCodes


void throwFromErrno(const std::string & s, int code, int e)
{
const size_t buf_size = 128;
Expand All @@ -54,14 +52,18 @@ void throwFromErrno(const std::string & s, int code, int e)
strcpy(buf, unknown_message);
strcpy(buf + strlen(unknown_message), code);
}
throw ErrnoException(s + ", errno: " + toString(e) + ", strerror: " + std::string(buf), code, e);
throw ErrnoException(s + ", errno: " + toString(e) + ", strerror: " + std::string(buf),
code,
e);
#else
throw ErrnoException(s + ", errno: " + toString(e) + ", strerror: " + std::string(strerror_r(e, buf, sizeof(buf))), code, e);
throw ErrnoException(s + ", errno: " + toString(e) + ", strerror: " + std::string(strerror_r(e, buf, sizeof(buf))),
code,
e);
#endif
}


void tryLogCurrentException(const char * log_name, const std::string & start_of_message)
void tryLogCurrentException(const char * log_name,
const std::string & start_of_message)
{
tryLogCurrentException(&Poco::Logger::get(log_name), start_of_message);
}
Expand All @@ -75,19 +77,22 @@ void tryLogCurrentException(const char * log_name, const std::string & start_of_
{ \
}

void tryLogCurrentException(const LoggerPtr & logger, const std::string & start_of_message)
void tryLogCurrentException(const LoggerPtr & logger,
const std::string & start_of_message)
{
TRY_LOG_CURRENT_EXCEPTION(logger, start_of_message);
}

void tryLogCurrentException(Poco::Logger * logger, const std::string & start_of_message)
void tryLogCurrentException(Poco::Logger * logger,
const std::string & start_of_message)
{
TRY_LOG_CURRENT_EXCEPTION(logger, start_of_message);
}

#undef TRY_LOG_CURRENT_EXCEPTION

std::string getCurrentExceptionMessage(bool with_stacktrace, bool check_embedded_stacktrace)
std::string getCurrentExceptionMessage(bool with_stacktrace,
bool check_embedded_stacktrace)
{
std::stringstream stream;

Expand All @@ -103,8 +108,10 @@ std::string getCurrentExceptionMessage(bool with_stacktrace, bool check_embedded
{
try
{
stream << "Poco::Exception. Code: " << ErrorCodes::POCO_EXCEPTION << ", e.code() = " << e.code()
<< ", e.displayText() = " << e.displayText() << ", e.what() = " << e.what();
stream << "Poco::Exception. Code: " << ErrorCodes::POCO_EXCEPTION
<< ", e.code() = " << e.code()
<< ", e.displayText() = " << e.displayText()
<< ", e.what() = " << e.what();
}
catch (...)
{
Expand All @@ -120,7 +127,8 @@ std::string getCurrentExceptionMessage(bool with_stacktrace, bool check_embedded
if (status)
name += " (demangling status: " + toString(status) + ")";

stream << "std::exception. Code: " << ErrorCodes::STD_EXCEPTION << ", type: " << name << ", e.what() = " << e.what();
stream << "std::exception. Code: " << ErrorCodes::STD_EXCEPTION
<< ", type: " << name << ", e.what() = " << e.what();
}
catch (...)
{
Expand All @@ -136,7 +144,8 @@ std::string getCurrentExceptionMessage(bool with_stacktrace, bool check_embedded
if (status)
name += " (demangling status: " + toString(status) + ")";

stream << "Unknown exception. Code: " << ErrorCodes::UNKNOWN_EXCEPTION << ", type: " << name;
stream << "Unknown exception. Code: " << ErrorCodes::UNKNOWN_EXCEPTION
<< ", type: " << name;
}
catch (...)
{
Expand All @@ -146,7 +155,6 @@ std::string getCurrentExceptionMessage(bool with_stacktrace, bool check_embedded
return stream.str();
}


int getCurrentExceptionCode()
{
try
Expand All @@ -171,15 +179,13 @@ int getCurrentExceptionCode()
}
}


void rethrowFirstException(const Exceptions & exceptions)
{
for (const auto & exception : exceptions)
if (exception)
std::rethrow_exception(exception);
}


std::string getExceptionMessage(const Exception & e, bool with_stacktrace, bool check_embedded_stacktrace)
{
std::stringstream stream;
Expand All @@ -200,7 +206,8 @@ std::string getExceptionMessage(const Exception & e, bool with_stacktrace, bool
}
}

stream << "Code: " << e.code() << ", e.displayText() = " << text << ", e.what() = " << e.what();
stream << "Code: " << e.code() << ", e.displayText() = " << text
<< ", e.what() = " << e.what();

if (with_stacktrace && !has_embedded_stack_trace)
stream << ", Stack trace:\n\n"
Expand All @@ -225,7 +232,6 @@ std::string getExceptionMessage(std::exception_ptr e, bool with_stacktrace)
}
}


std::string ExecutionStatus::serializeText() const
{
WriteBufferFromOwnString wb;
Expand Down Expand Up @@ -254,11 +260,20 @@ bool ExecutionStatus::tryDeserializeText(const std::string & data)
return true;
}

ExecutionStatus ExecutionStatus::fromCurrentException(const std::string & start_of_message)
ExecutionStatus
ExecutionStatus::fromCurrentException(const std::string & start_of_message)
{
String msg = (start_of_message.empty() ? "" : (start_of_message + ": ")) + getCurrentExceptionMessage(false, true);
return ExecutionStatus(getCurrentExceptionCode(), msg);
}

namespace exception_details
{
const LoggerPtr & getDefaultFatalLogger()
{
static const auto logger = std::make_shared<Logger>("DefaultFatal", "");
return logger;
}
} // namespace exception_details

} // namespace DB
Loading

0 comments on commit 4141e41

Please sign in to comment.