diff --git a/dbms/src/Common/Exception.cpp b/dbms/src/Common/Exception.cpp index f94a077e4be..7714db6adc3 100644 --- a/dbms/src/Common/Exception.cpp +++ b/dbms/src/Common/Exception.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include +#include #include #include #include @@ -94,7 +95,7 @@ void tryLogCurrentException(Poco::Logger * logger, std::string getCurrentExceptionMessage(bool with_stacktrace, bool check_embedded_stacktrace) { - std::stringstream stream; + FmtBuffer buffer; try { @@ -102,16 +103,18 @@ std::string getCurrentExceptionMessage(bool with_stacktrace, } catch (const Exception & e) { - stream << getExceptionMessage(e, with_stacktrace, check_embedded_stacktrace); + buffer.append(getExceptionMessage(e, with_stacktrace, check_embedded_stacktrace)); } catch (const Poco::Exception & e) { try { - stream << "Poco::Exception. Code: " << ErrorCodes::POCO_EXCEPTION - << ", e.code() = " << e.code() - << ", e.displayText() = " << e.displayText() - << ", e.what() = " << e.what(); + buffer.fmtAppend( + "Poco::Exception. Code: {}, e.code() = {}, e.displayText() = {}, e.what() = {}", + ErrorCodes::POCO_EXCEPTION, + e.code(), + e.displayText(), + e.what()); } catch (...) { @@ -127,8 +130,7 @@ std::string getCurrentExceptionMessage(bool with_stacktrace, if (status) name += " (demangling status: " + toString(status) + ")"; - stream << "std::exception. Code: " << ErrorCodes::STD_EXCEPTION - << ", type: " << name << ", e.what() = " << e.what(); + buffer.fmtAppend("std::exception. Code: {}, type: {}, e.what() = {}", ErrorCodes::STD_EXCEPTION, name, e.what()); } catch (...) { @@ -144,15 +146,14 @@ std::string getCurrentExceptionMessage(bool with_stacktrace, if (status) name += " (demangling status: " + toString(status) + ")"; - stream << "Unknown exception. Code: " << ErrorCodes::UNKNOWN_EXCEPTION - << ", type: " << name; + buffer.fmtAppend("Unknown exception. Code: {}, type: {}", ErrorCodes::UNKNOWN_EXCEPTION, name); } catch (...) { } } - return stream.str(); + return buffer.toString(); } int getCurrentExceptionCode() @@ -188,7 +189,7 @@ void rethrowFirstException(const Exceptions & exceptions) std::string getExceptionMessage(const Exception & e, bool with_stacktrace, bool check_embedded_stacktrace) { - std::stringstream stream; + FmtBuffer buffer; try { @@ -206,18 +207,16 @@ std::string getExceptionMessage(const Exception & e, bool with_stacktrace, bool } } - stream << "Code: " << e.code() << ", e.displayText() = " << text - << ", e.what() = " << e.what(); + buffer.fmtAppend("Code: {}, e.displayText() = {}, e.what() = {}", e.code(), text, e.what()); if (with_stacktrace && !has_embedded_stack_trace) - stream << ", Stack trace:\n\n" - << e.getStackTrace().toString(); + buffer.append(", Stack trace:\n\n").append(e.getStackTrace().toString()); } catch (...) { } - return stream.str(); + return buffer.toString(); } std::string getExceptionMessage(std::exception_ptr e, bool with_stacktrace) diff --git a/dbms/src/Flash/Executor/PipelineExecutorStatus.cpp b/dbms/src/Flash/Executor/PipelineExecutorStatus.cpp index 2667c07fa04..12c4c8af3bc 100644 --- a/dbms/src/Flash/Executor/PipelineExecutorStatus.cpp +++ b/dbms/src/Flash/Executor/PipelineExecutorStatus.cpp @@ -56,12 +56,10 @@ void PipelineExecutorStatus::onEventSchedule() void PipelineExecutorStatus::onEventFinish() { - bool notify = false; - { - std::lock_guard lock(mu); - notify = (0 == --active_event_count); - } - if (notify) + std::lock_guard lock(mu); + assert(active_event_count > 0); + --active_event_count; + if (0 == active_event_count) cv.notify_all(); } diff --git a/tests/sanitize/tsan.suppression b/tests/sanitize/tsan.suppression index 537b584e8ff..e2fb4d10325 100644 --- a/tests/sanitize/tsan.suppression +++ b/tests/sanitize/tsan.suppression @@ -1,2 +1,3 @@ race:dbms/src/Common/TiFlashMetrics.h race:DB::Context::setCancelTest +race:DB::getCurrentExceptionMessage