From 2f62b5283be84db5177355b0821a69113e6d9f8e Mon Sep 17 00:00:00 2001 From: obdev Date: Mon, 3 Jul 2023 03:47:59 +0000 Subject: [PATCH] [CP] fix core when timezone info deserialize --- src/observer/mysql/obmp_query.cpp | 2 + src/observer/mysql/obmp_stmt_execute.cpp | 2 + src/observer/mysql/obmp_stmt_prepare.cpp | 2 + src/sql/session/ob_basic_session_info.cpp | 56 +++++++++++++---------- src/sql/session/ob_basic_session_info.h | 1 + src/sql/session/ob_sql_session_info.cpp | 2 - 6 files changed, 39 insertions(+), 26 deletions(-) diff --git a/src/observer/mysql/obmp_query.cpp b/src/observer/mysql/obmp_query.cpp index 56db0a2eb5..cca5cc5740 100644 --- a/src/observer/mysql/obmp_query.cpp +++ b/src/observer/mysql/obmp_query.cpp @@ -515,6 +515,8 @@ int ObMPQuery::process_single_stmt(const ObMultiStmtItem &multi_stmt_item, session.get_effective_tenant_id(), &session))) { LOG_WARN("failed to check_and_refresh_schema", K(ret)); + } else if (OB_FAIL(session.update_timezone_info())) { + LOG_WARN("fail to update time zone info", K(ret)); } else { need_response_error = false; //每次执行不同sql都需要更新 diff --git a/src/observer/mysql/obmp_stmt_execute.cpp b/src/observer/mysql/obmp_stmt_execute.cpp index c502ef9073..430f6eb3c3 100644 --- a/src/observer/mysql/obmp_stmt_execute.cpp +++ b/src/observer/mysql/obmp_stmt_execute.cpp @@ -1658,6 +1658,8 @@ int ObMPStmtExecute::process_execute_stmt(const ObMultiStmtItem &multi_stmt_item if (OB_FAIL(check_and_refresh_schema(session.get_login_tenant_id(), session.get_effective_tenant_id()))) { LOG_WARN("failed to check_and_refresh_schema", K(ret)); + } else if (OB_FAIL(session.update_timezone_info())) { + LOG_WARN("fail to update time zone info", K(ret)); } else if (is_arraybinding_) { need_response_error = false; bool optimization_done = false; diff --git a/src/observer/mysql/obmp_stmt_prepare.cpp b/src/observer/mysql/obmp_stmt_prepare.cpp index 6322e2ed3d..454ff4fc88 100644 --- a/src/observer/mysql/obmp_stmt_prepare.cpp +++ b/src/observer/mysql/obmp_stmt_prepare.cpp @@ -300,6 +300,8 @@ int ObMPStmtPrepare::process_prepare_stmt(const ObMultiStmtItem &multi_stmt_item if (OB_FAIL(check_and_refresh_schema(session.get_login_tenant_id(), session.get_effective_tenant_id()))) { LOG_WARN("failed to check_and_refresh_schema", K(ret)); + } else if (OB_FAIL(session.update_timezone_info())) { + LOG_WARN("fail to update time zone info", K(ret)); } else { ctx_.self_add_plan_ = false; ctx_.is_prepare_protocol_ = true; //set to prepare protocol diff --git a/src/sql/session/ob_basic_session_info.cpp b/src/sql/session/ob_basic_session_info.cpp index dd39b7b7c7..b75822e7bf 100644 --- a/src/sql/session/ob_basic_session_info.cpp +++ b/src/sql/session/ob_basic_session_info.cpp @@ -147,8 +147,8 @@ ObBasicSessionInfo::ObBasicSessionInfo(const uint64_t tenant_id) labels_(), thread_id_(0), is_password_expired_(false), - process_query_time_(0) - + process_query_time_(0), + last_update_tz_time_(0) { thread_data_.reset(); MEMSET(sys_vars_, 0, sizeof(sys_vars_)); @@ -424,6 +424,7 @@ void ObBasicSessionInfo::reset(bool skip_sys_var) thread_id_ = 0; is_password_expired_ = false; process_query_time_ = 0; + last_update_tz_time_ = 0; sess_bt_buff_pos_ = 0; ATOMIC_SET(&sess_ref_cnt_ , 0); // 最后再重置所有allocator @@ -5963,31 +5964,38 @@ int ObBasicSessionInfo::set_time_zone(const ObString &str_val, const bool is_ora int ObBasicSessionInfo::update_timezone_info() { int ret = OB_SUCCESS; - ObTZMapWrap tz_map_wrap; - ObTimeZoneInfoManager *tz_info_mgr = NULL; - if (OB_FAIL(OTTZ_MGR.get_tenant_timezone(tenant_id_, tz_map_wrap, tz_info_mgr))) { - LOG_WARN("get tenant timezone with lock failed", K(ret)); - } else if (OB_ISNULL(tz_info_mgr)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("tenant timezone mgr is null", K(tz_info_mgr)); - } else if (OB_UNLIKELY(tz_info_wrap_.is_position_class() - && tz_info_mgr->get_version() > tz_info_wrap_.get_cur_version())) { - ObString tz_name; - if (OB_UNLIKELY(!tz_info_wrap_.get_tz_info_pos().is_valid())) { + const int64_t UPDATE_PERIOD = 1000 * 1000 * 5; //5s + int64_t cur_time = ObTimeUtility::current_time(); + if (cur_time - last_update_tz_time_ > UPDATE_PERIOD) { + ObTZMapWrap tz_map_wrap; + ObTimeZoneInfoManager *tz_info_mgr = NULL; + if (OB_FAIL(OTTZ_MGR.get_tenant_timezone(tenant_id_, tz_map_wrap, tz_info_mgr))) { + LOG_WARN("get tenant timezone with lock failed", K(ret)); + } else if (OB_ISNULL(tz_info_mgr)) { ret = OB_ERR_UNEXPECTED; - LOG_WARN("time zone info is invalid", K(tz_info_wrap_.get_tz_info_pos()), K(ret)); - } else if (OB_FAIL(tz_info_wrap_.get_tz_info_pos().get_tz_name(tz_name))) { - LOG_WARN("fal to get time zone name", K(tz_info_wrap_.get_tz_info_pos()), K(ret)); - } else {//此处需要先更新version,这样可以保证find到的tz_info version >= cur_version - int64_t orig_version = tz_info_wrap_.get_cur_version(); - tz_info_wrap_.set_cur_version(tz_info_mgr->get_version()); - if (OB_FAIL(tz_info_mgr->find_time_zone_info(tz_name, tz_info_wrap_.get_tz_info_pos()))) { - LOG_WARN("fail to find time zone info", K(tz_name), K(ret)); - tz_info_wrap_.set_cur_version(orig_version); - } else { - tz_info_wrap_.get_tz_info_pos().set_error_on_overlap_time(tz_info_wrap_.is_error_on_overlap_time()); + LOG_WARN("tenant timezone mgr is null", K(tz_info_mgr)); + } else if (OB_UNLIKELY(tz_info_wrap_.is_position_class() + && tz_info_mgr->get_version() > tz_info_wrap_.get_cur_version())) { + ObString tz_name; + if (OB_UNLIKELY(!tz_info_wrap_.get_tz_info_pos().is_valid())) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("time zone info is invalid", K(tz_info_wrap_.get_tz_info_pos()), K(ret)); + } else if (OB_FAIL(tz_info_wrap_.get_tz_info_pos().get_tz_name(tz_name))) { + LOG_WARN("fal to get time zone name", K(tz_info_wrap_.get_tz_info_pos()), K(ret)); + } else {//此处需要先更新version,这样可以保证find到的tz_info version >= cur_version + int64_t orig_version = tz_info_wrap_.get_cur_version(); + tz_info_wrap_.set_cur_version(tz_info_mgr->get_version()); + if (OB_FAIL(tz_info_mgr->find_time_zone_info(tz_name, tz_info_wrap_.get_tz_info_pos()))) { + LOG_WARN("fail to find time zone info", K(tz_name), K(ret)); + tz_info_wrap_.set_cur_version(orig_version); + } else { + tz_info_wrap_.get_tz_info_pos().set_error_on_overlap_time(tz_info_wrap_.is_error_on_overlap_time()); + } } } + if (OB_SUCC(ret)) { + last_update_tz_time_ = cur_time; + } } return ret; } diff --git a/src/sql/session/ob_basic_session_info.h b/src/sql/session/ob_basic_session_info.h index aecc88ae01..28d16af190 100644 --- a/src/sql/session/ob_basic_session_info.h +++ b/src/sql/session/ob_basic_session_info.h @@ -2202,6 +2202,7 @@ private: bool is_password_expired_; // timestamp of processing current query. refresh when retry. int64_t process_query_time_; + int64_t last_update_tz_time_; //timestamp of last attempt to update timezone info }; diff --git a/src/sql/session/ob_sql_session_info.cpp b/src/sql/session/ob_sql_session_info.cpp index d4867aa0de..6dd1df5a55 100644 --- a/src/sql/session/ob_sql_session_info.cpp +++ b/src/sql/session/ob_sql_session_info.cpp @@ -2459,8 +2459,6 @@ void ObSQLSessionInfo::ObCachedTenantConfigInfo::refresh() // 7. print_sample_ppm_ for flt ATOMIC_STORE(&print_sample_ppm_, tenant_config->_print_sample_ppm); } - //timezone的更新频率非常低,放到后台驱动 - (void)session_->update_timezone_info(); ATOMIC_STORE(&last_check_ec_ts_, cur_ts); session_->update_tenant_config_version( (::oceanbase::omt::ObTenantConfigMgr::get_instance()).get_tenant_config_version(effective_tenant_id));