diff --git a/dbms/src/Common/Exception.cpp b/dbms/src/Common/Exception.cpp index f3a536919a9..e5aa6132625 100644 --- a/dbms/src/Common/Exception.cpp +++ b/dbms/src/Common/Exception.cpp @@ -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 @@ -114,8 +134,7 @@ std::string getCurrentExceptionMessage(bool with_stacktrace, << ", e.what() = " << e.what(); } catch (...) - { - } + {} } catch (const std::exception & e) { @@ -131,8 +150,7 @@ std::string getCurrentExceptionMessage(bool with_stacktrace, << ", type: " << name << ", e.what() = " << e.what(); } catch (...) - { - } + {} } catch (...) { @@ -148,8 +166,7 @@ std::string getCurrentExceptionMessage(bool with_stacktrace, << ", type: " << name; } catch (...) - { - } + {} } return stream.str(); @@ -214,8 +231,7 @@ std::string getExceptionMessage(const Exception & e, bool with_stacktrace, bool << e.getStackTrace().toString(); } catch (...) - { - } + {} return stream.str(); } diff --git a/dbms/src/Common/Exception.h b/dbms/src/Common/Exception.h index cc4300f11f3..255be691376 100644 --- a/dbms/src/Common/Exception.h +++ b/dbms/src/Common/Exception.h @@ -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 diff --git a/dbms/src/Storages/Transaction/ProxyFFI.cpp b/dbms/src/Storages/Transaction/ProxyFFI.cpp index efac3b48788..b94dac4a267 100644 --- a/dbms/src/Storages/Transaction/ProxyFFI.cpp +++ b/dbms/src/Storages/Transaction/ProxyFFI.cpp @@ -96,7 +96,7 @@ EngineStoreApplyRes HandleWriteRaftCmd( } catch (...) { - tryLogCurrentException(__PRETTY_FUNCTION__); + tryLogCurrentFatalException(__PRETTY_FUNCTION__); exit(-1); } } @@ -124,7 +124,7 @@ EngineStoreApplyRes HandleAdminRaftCmd( } catch (...) { - tryLogCurrentException(__PRETTY_FUNCTION__); + tryLogCurrentFatalException(__PRETTY_FUNCTION__); exit(-1); } } @@ -138,7 +138,7 @@ uint8_t NeedFlushData(EngineStoreServerWrap * server, uint64_t region_id) } catch (...) { - tryLogCurrentException(__PRETTY_FUNCTION__); + tryLogCurrentFatalException(__PRETTY_FUNCTION__); exit(-1); } } @@ -152,7 +152,7 @@ uint8_t TryFlushData(EngineStoreServerWrap * server, uint64_t region_id, uint8_t } catch (...) { - tryLogCurrentException(__PRETTY_FUNCTION__); + tryLogCurrentFatalException(__PRETTY_FUNCTION__); exit(-1); } } @@ -198,7 +198,7 @@ void HandleDestroy(EngineStoreServerWrap * server, uint64_t region_id) } catch (...) { - tryLogCurrentException(__PRETTY_FUNCTION__); + tryLogCurrentFatalException(__PRETTY_FUNCTION__); exit(-1); } } @@ -212,7 +212,7 @@ EngineStoreApplyRes HandleIngestSST(EngineStoreServerWrap * server, SSTViewVec s } catch (...) { - tryLogCurrentException(__PRETTY_FUNCTION__); + tryLogCurrentFatalException(__PRETTY_FUNCTION__); exit(-1); } } @@ -229,7 +229,7 @@ StoreStats HandleComputeStoreStats(EngineStoreServerWrap * server) } catch (...) { - tryLogCurrentException(__PRETTY_FUNCTION__); + tryLogCurrentFatalException(__PRETTY_FUNCTION__); } return res; } @@ -395,7 +395,7 @@ RawCppPtr PreHandleSnapshot( } catch (...) { - tryLogCurrentException(__PRETTY_FUNCTION__); + tryLogCurrentFatalException(__PRETTY_FUNCTION__); exit(-1); } } @@ -415,7 +415,7 @@ void ApplyPreHandledSnapshot(EngineStoreServerWrap * server, PreHandledSnapshot } catch (...) { - tryLogCurrentException(__PRETTY_FUNCTION__); + tryLogCurrentFatalException(__PRETTY_FUNCTION__); exit(-1); } } @@ -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); } } @@ -452,7 +452,7 @@ void GcRawCppPtr(RawVoidPtr ptr, RawCppPtrType type) delete reinterpret_cast(ptr); break; default: - LOG_ERROR(&Poco::Logger::get(__FUNCTION__), "unknown type {}", type); + LOG_FATAL(&Poco::Logger::get(__FUNCTION__), "unknown type {}", type); exit(-1); } }