Skip to content

Commit

Permalink
Set log level to FATAL on FFI boundary on exception (pingcap#8364)
Browse files Browse the repository at this point in the history
  • Loading branch information
CalvinNeo authored and JaySon-Huang committed Dec 21, 2023
1 parent c69423d commit 2d2271c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 29 deletions.
52 changes: 34 additions & 18 deletions dbms/src/Common/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,45 @@ void tryLogCurrentException(const char * log_name,
tryLogCurrentException(&Poco::Logger::get(log_name), start_of_message);
}

#define TRY_LOG_CURRENT_EXCEPTION(logger, start_of_message) \
try \
{ \
LOG_ERROR((logger), "{}{}{}", (start_of_message), ((start_of_message).empty() ? "" : ": "), getCurrentExceptionMessage(true)); \
} \
catch (...) \
{ \
}
void tryLogCurrentFatalException(const char * log_name, const std::string & start_of_message)
{
tryLogCurrentFatalException(&Poco::Logger::get(log_name), start_of_message);
}

#define TRY_LOG_CURRENT_EXCEPTION(logger, prio, start_of_message) \
try \
{ \
LOG_IMPL( \
(logger), \
prio, \
"{}{}{}", \
(start_of_message), \
((start_of_message).empty() ? "" : ": "), \
getCurrentExceptionMessage(true)); \
} \
catch (...) \
{}

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

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

void tryLogCurrentFatalException(const LoggerPtr & logger, const std::string & start_of_message)
{
TRY_LOG_CURRENT_EXCEPTION(logger, Poco::Message::PRIO_FATAL, start_of_message);
}

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

#undef TRY_LOG_CURRENT_EXCEPTION
Expand Down Expand Up @@ -114,8 +134,7 @@ std::string getCurrentExceptionMessage(bool with_stacktrace,
<< ", e.what() = " << e.what();
}
catch (...)
{
}
{}
}
catch (const std::exception & e)
{
Expand All @@ -131,8 +150,7 @@ std::string getCurrentExceptionMessage(bool with_stacktrace,
<< ", type: " << name << ", e.what() = " << e.what();
}
catch (...)
{
}
{}
}
catch (...)
{
Expand All @@ -148,8 +166,7 @@ std::string getCurrentExceptionMessage(bool with_stacktrace,
<< ", type: " << name;
}
catch (...)
{
}
{}
}

return stream.str();
Expand Down Expand Up @@ -214,8 +231,7 @@ std::string getExceptionMessage(const Exception & e, bool with_stacktrace, bool
<< e.getStackTrace().toString();
}
catch (...)
{
}
{}

return stream.str();
}
Expand Down
4 changes: 4 additions & 0 deletions dbms/src/Common/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ void tryLogCurrentException(const LoggerPtr & logger,
void tryLogCurrentException(Poco::Logger * logger,
const std::string & start_of_message = "");

void tryLogCurrentFatalException(const char * log_name, const std::string & start_of_message = "");
void tryLogCurrentFatalException(const LoggerPtr & logger, const std::string & start_of_message = "");
void tryLogCurrentFatalException(Poco::Logger * logger, const std::string & start_of_message = "");

/** Prints current exception in canonical format.
* with_stacktrace - prints stack trace for DB::Exception.
* check_embedded_stacktrace - if DB::Exception has embedded stacktrace then
Expand Down
22 changes: 11 additions & 11 deletions dbms/src/Storages/Transaction/ProxyFFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ EngineStoreApplyRes HandleWriteRaftCmd(
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
tryLogCurrentFatalException(__PRETTY_FUNCTION__);
exit(-1);
}
}
Expand Down Expand Up @@ -124,7 +124,7 @@ EngineStoreApplyRes HandleAdminRaftCmd(
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
tryLogCurrentFatalException(__PRETTY_FUNCTION__);
exit(-1);
}
}
Expand All @@ -138,7 +138,7 @@ uint8_t NeedFlushData(EngineStoreServerWrap * server, uint64_t region_id)
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
tryLogCurrentFatalException(__PRETTY_FUNCTION__);
exit(-1);
}
}
Expand All @@ -152,7 +152,7 @@ uint8_t TryFlushData(EngineStoreServerWrap * server, uint64_t region_id, uint8_t
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
tryLogCurrentFatalException(__PRETTY_FUNCTION__);
exit(-1);
}
}
Expand Down Expand Up @@ -198,7 +198,7 @@ void HandleDestroy(EngineStoreServerWrap * server, uint64_t region_id)
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
tryLogCurrentFatalException(__PRETTY_FUNCTION__);
exit(-1);
}
}
Expand All @@ -212,7 +212,7 @@ EngineStoreApplyRes HandleIngestSST(EngineStoreServerWrap * server, SSTViewVec s
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
tryLogCurrentFatalException(__PRETTY_FUNCTION__);
exit(-1);
}
}
Expand All @@ -229,7 +229,7 @@ StoreStats HandleComputeStoreStats(EngineStoreServerWrap * server)
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
tryLogCurrentFatalException(__PRETTY_FUNCTION__);
}
return res;
}
Expand Down Expand Up @@ -395,7 +395,7 @@ RawCppPtr PreHandleSnapshot(
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
tryLogCurrentFatalException(__PRETTY_FUNCTION__);
exit(-1);
}
}
Expand All @@ -415,7 +415,7 @@ void ApplyPreHandledSnapshot(EngineStoreServerWrap * server, PreHandledSnapshot
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
tryLogCurrentFatalException(__PRETTY_FUNCTION__);
exit(-1);
}
}
Expand All @@ -431,7 +431,7 @@ void ApplyPreHandledSnapshot(EngineStoreServerWrap * server, RawVoidPtr res, Raw
break;
}
default:
LOG_ERROR(&Poco::Logger::get(__FUNCTION__), "unknown type {}", type);
LOG_FATAL(&Poco::Logger::get(__FUNCTION__), "unknown type {}", type);
exit(-1);
}
}
Expand All @@ -452,7 +452,7 @@ void GcRawCppPtr(RawVoidPtr ptr, RawCppPtrType type)
delete reinterpret_cast<AsyncNotifier *>(ptr);
break;
default:
LOG_ERROR(&Poco::Logger::get(__FUNCTION__), "unknown type {}", type);
LOG_FATAL(&Poco::Logger::get(__FUNCTION__), "unknown type {}", type);
exit(-1);
}
}
Expand Down

0 comments on commit 2d2271c

Please sign in to comment.