From 5baefa81ff3769f11a7548cc80ec84dee2215049 Mon Sep 17 00:00:00 2001 From: nroskill Date: Mon, 18 Oct 2021 17:53:45 +0800 Subject: [PATCH] support _enable_fatal_error_hang --- CMakeLists.txt | 6 +++ deps/oblib/src/common/object/ob_obj_type.h | 4 +- deps/oblib/src/lib/charset/ob_ctype.h | 2 + .../src/lib/timezone/ob_time_convert.cpp | 18 +++++++++ deps/oblib/src/lib/timezone/ob_time_convert.h | 9 ++--- .../src/lib/utility/ob_hang_fatal_error.cpp | 20 +++++++--- .../src/lib/utility/ob_hang_fatal_error.h | 37 ++++++------------- 7 files changed, 58 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd314aed42..5b703e18c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ project("OceanBase CE" LANGUAGES CXX C ASM) ob_define(WITH_OSS OFF) +ob_define(ENABLE_FATAL_ERROR_HANG OFF) if(ENABLE_DEBUG_LOG) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_DEBUG_LOG") @@ -26,6 +27,11 @@ if(OB_USE_ASAN) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOB_USE_ASAN") endif() +if (ENABLE_FATAL_ERROR_HANG) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFATAL_ERROR_HANG") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFATAL_ERROR_HANG") +endif() + message(STATUS "This is BINARY dir " ${PROJECT_BINARY_DIR}) message(STATUS "This is SOURCE dir " ${PROJECT_SOURCE_DIR}) diff --git a/deps/oblib/src/common/object/ob_obj_type.h b/deps/oblib/src/common/object/ob_obj_type.h index a9a2e2bc75..bb7c0609db 100644 --- a/deps/oblib/src/common/object/ob_obj_type.h +++ b/deps/oblib/src/common/object/ob_obj_type.h @@ -14,11 +14,13 @@ #define OCEANBASE_COMMON_OB_OBJECT_TYPE_H_ #include "lib/utility/ob_print_utils.h" #include "lib/charset/ob_charset.h" -#include "lib/container/ob_iarray.h" + namespace oceanbase { namespace common { class ObObjMeta; class ObAccuracy; +template +class ObIArray; // we can append new type only, do NOT delete nor change order, // modify ObObjTypeClass and ob_obj_type_class when append new object type. diff --git a/deps/oblib/src/lib/charset/ob_ctype.h b/deps/oblib/src/lib/charset/ob_ctype.h index b1f27f21a2..835a82992d 100644 --- a/deps/oblib/src/lib/charset/ob_ctype.h +++ b/deps/oblib/src/lib/charset/ob_ctype.h @@ -100,6 +100,8 @@ extern "C" { #define ob_isgraph(s, c) ((s)->ctype != NULL ? ((s)->ctype + 1)[(uchar)(c)] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR) : 0) #define ob_iscntrl(s, c) ((s)->ctype != NULL ? ((s)->ctype + 1)[(uchar)(c)] & _MY_CTR : 0) +extern void right_to_die_or_duty_to_live_c(); + #define ob_charset_assert(condition) \ if (!(condition)) { \ right_to_die_or_duty_to_live_c(); \ diff --git a/deps/oblib/src/lib/timezone/ob_time_convert.cpp b/deps/oblib/src/lib/timezone/ob_time_convert.cpp index f6e96943a2..74b66d2455 100644 --- a/deps/oblib/src/lib/timezone/ob_time_convert.cpp +++ b/deps/oblib/src/lib/timezone/ob_time_convert.cpp @@ -411,6 +411,24 @@ int ObTime::set_tzd_abbr(const ObString& tzd_abbr) return ret; } +DEF_TO_STRING(ObTime) +{ + int64_t pos = 0; + J_OBJ_START(); + J_KV(K(mode_), + "parts", + ObArrayWrap(parts_, TOTAL_PART_CNT), + "tz_name", + ObString(OB_MAX_TZ_NAME_LEN, tz_name_), + "tzd_abbr", + ObString(OB_MAX_TZ_ABBR_LEN, tzd_abbr_), + K_(time_zone_id), + K_(transition_type_id), + K_(is_tz_name_valid)); + J_OBJ_END(); + return pos; +} + //////////////////////////////// // int / double / string -> datetime / date / time / year. int ObTimeConverter::int_to_datetime( diff --git a/deps/oblib/src/lib/timezone/ob_time_convert.h b/deps/oblib/src/lib/timezone/ob_time_convert.h index e29134ccdc..507d6643d1 100644 --- a/deps/oblib/src/lib/timezone/ob_time_convert.h +++ b/deps/oblib/src/lib/timezone/ob_time_convert.h @@ -17,7 +17,6 @@ //#include "lib/timezone/ob_timezone_info.h" #include "lib/string/ob_string.h" #include "lib/ob_date_unit_type.h" -#include "lib/container/ob_array_wrap.h" #include "common/object/ob_obj_type.h" #include "common/ob_accuracy.h" @@ -223,11 +222,9 @@ public: { return ObString(strlen(tzd_abbr_), tzd_abbr_); } - int set_tz_name(const ObString& tz_name); - int set_tzd_abbr(const ObString& tz_abbr); - TO_STRING_KV(K(mode_), "parts", ObArrayWrap(parts_, TOTAL_PART_CNT), "tz_name", - ObString(OB_MAX_TZ_NAME_LEN, tz_name_), "tzd_abbr", ObString(OB_MAX_TZ_ABBR_LEN, tzd_abbr_), K_(time_zone_id), - K_(transition_type_id), K_(is_tz_name_valid)); + int set_tz_name(const ObString &tz_name); + int set_tzd_abbr(const ObString &tz_abbr); + DECLARE_TO_STRING; ObDTMode mode_; int32_t parts_[TOTAL_PART_CNT]; // year: [1000, 9999]. diff --git a/deps/oblib/src/lib/utility/ob_hang_fatal_error.cpp b/deps/oblib/src/lib/utility/ob_hang_fatal_error.cpp index 2ba1d1de11..666dcc65b1 100644 --- a/deps/oblib/src/lib/utility/ob_hang_fatal_error.cpp +++ b/deps/oblib/src/lib/utility/ob_hang_fatal_error.cpp @@ -14,21 +14,29 @@ #include "lib/utility/ob_print_utils.h" #include "common/ob_common_utility.h" -namespace oceanbase { -namespace common { - +extern "C" { void right_to_die_or_duty_to_live_c() { - right_to_die_or_duty_to_live(); + ::oceanbase::common::right_to_die_or_duty_to_live(); +} } +namespace oceanbase { +namespace common { + +// To die or to live, it's a problem. void right_to_die_or_duty_to_live() { - const ObFatalErrExtraInfoGuard* extra_info = ObFatalErrExtraInfoGuard::get_thd_local_val_ptr(); + const ObFatalErrExtraInfoGuard *extra_info = ObFatalErrExtraInfoGuard::get_thd_local_val_ptr(); BACKTRACE( ERROR, true, "Trying so hard to die, extra_info=(%s)", (NULL == extra_info) ? NULL : to_cstring(*extra_info)); +#ifdef FATAL_ERROR_HANG + while (true) { + sleep(120); + } +#else throw OB_EXCEPTION(); - _OB_LOG(ERROR, "Trying very hard to live"); +#endif } } // namespace common diff --git a/deps/oblib/src/lib/utility/ob_hang_fatal_error.h b/deps/oblib/src/lib/utility/ob_hang_fatal_error.h index 1eae16b6fd..0fde57fbea 100644 --- a/deps/oblib/src/lib/utility/ob_hang_fatal_error.h +++ b/deps/oblib/src/lib/utility/ob_hang_fatal_error.h @@ -14,37 +14,24 @@ #define SRC_LIB_UTILITY_OB_HANG_FATAL_ERROR_H_ #include +namespace oceanbase +{ +namespace common +{ +extern void right_to_die_or_duty_to_live(); -namespace oceanbase { -namespace common { - -extern "C" { -extern void right_to_die_or_duty_to_live_c(); -} - -struct OB_BASE_EXCEPTION : public std::exception { - virtual const char* what() const throw() override - { - return nullptr; - } - virtual int get_errno() - { - return 0; - } +struct OB_BASE_EXCEPTION : public std::exception +{ + virtual const char *what() const throw() override { return nullptr; } + virtual int get_errno() { return 0; } }; template -struct OB_EXCEPTION : public OB_BASE_EXCEPTION { - virtual int get_errno() - { - return ERRNO; - } +struct OB_EXCEPTION : public OB_BASE_EXCEPTION +{ + virtual int get_errno() { return ERRNO; } }; -// Hang th thread. -// To die or to live, it's a problem. -extern void right_to_die_or_duty_to_live(); - } // namespace common } // namespace oceanbase -- GitLab