Skip to content

Commit

Permalink
Fix tsan fail in unit test EventTestRunner.base (#6744)
Browse files Browse the repository at this point in the history
close #6743
  • Loading branch information
SeaRise authored Feb 7, 2023
1 parent 3f0dae0 commit 6ba23a1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
33 changes: 16 additions & 17 deletions dbms/src/Common/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include <Common/Exception.h>
#include <Common/FmtUtils.h>
#include <Common/Logger.h>
#include <IO/Operators.h>
#include <IO/ReadBufferFromString.h>
Expand Down Expand Up @@ -94,24 +95,26 @@ void tryLogCurrentException(Poco::Logger * logger,
std::string getCurrentExceptionMessage(bool with_stacktrace,
bool check_embedded_stacktrace)
{
std::stringstream stream;
FmtBuffer buffer;

try
{
throw;
}
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 (...)
{
Expand All @@ -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 (...)
{
Expand All @@ -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()
Expand Down Expand Up @@ -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
{
Expand All @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions dbms/src/Flash/Executor/PipelineExecutorStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
1 change: 1 addition & 0 deletions tests/sanitize/tsan.suppression
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
race:dbms/src/Common/TiFlashMetrics.h
race:DB::Context::setCancelTest
race:DB::getCurrentExceptionMessage

0 comments on commit 6ba23a1

Please sign in to comment.