From 0bf3e81dd5ccb46ef749e6c63b63513e7a7e5df9 Mon Sep 17 00:00:00 2001 From: Hongqin-Li Date: Thu, 2 Jan 2025 05:45:08 +0000 Subject: [PATCH] Optimize fetch lob tablet autoinc seq --- src/share/ob_tablet_autoincrement_service.cpp | 28 ++++++++++--------- src/share/ob_tablet_autoincrement_service.h | 4 ++- src/storage/lob/ob_lob_persistent_adaptor.cpp | 4 +-- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/share/ob_tablet_autoincrement_service.cpp b/src/share/ob_tablet_autoincrement_service.cpp index 81f0b45e3..a28206eef 100644 --- a/src/share/ob_tablet_autoincrement_service.cpp +++ b/src/share/ob_tablet_autoincrement_service.cpp @@ -17,6 +17,7 @@ #include "rootserver/ob_root_service.h" #include "share/location_cache/ob_location_service.h" #include "share/ob_rpc_struct.h" +#include "storage/ob_tablet_autoinc_seq_rpc_handler.h" #include "storage/tx_storage/ob_ls_handle.h" #include "share/scn.h" #include "storage/tablet/ob_tablet.h" @@ -117,7 +118,9 @@ int ObTabletAutoincMgr::clear_cache_if_fallback_for_mlog( } return ret; } -int ObTabletAutoincMgr::fetch_interval(const ObTabletAutoincParam ¶m, ObTabletCacheInterval &interval) { + +int ObTabletAutoincMgr::fetch_interval(const ObTabletAutoincParam ¶m, ObTabletCacheInterval &interval) +{ int ret = OB_SUCCESS; if (OB_UNLIKELY(!is_inited_)) { ret = OB_NOT_INIT; @@ -152,7 +155,8 @@ int ObTabletAutoincMgr::fetch_interval(const ObTabletAutoincParam ¶m, ObTabl return ret; } -int ObTabletAutoincMgr::fetch_interval_without_cache(const ObTabletAutoincParam ¶m, ObTabletCacheInterval &interval) { +int ObTabletAutoincMgr::fetch_interval_without_cache(const ObTabletAutoincParam ¶m, ObTabletCacheInterval &interval) +{ int ret = OB_SUCCESS; lib::ObMutexGuard guard(mutex_); ObTabletCacheNode node; @@ -202,9 +206,14 @@ int ObTabletAutoincMgr::fetch_new_range(const ObTabletAutoincParam ¶m, false,/*force_renew*/ leader_addr))) { LOG_WARN("get leader failed", K(ret), K(arg.ls_id_)); - } else if (OB_FAIL(srv_rpc_proxy->to(leader_addr).timeout(rpc_timeout).fetch_tablet_autoinc_seq_cache(arg, res))) { + } else if (GCTX.self_addr() == leader_addr) { + if (OB_FAIL(ObTabletAutoincSeqRpcHandler::get_instance().fetch_tablet_autoinc_seq_cache(arg, res))) { + LOG_WARN("fail to fetch autoinc cache for tablets", K(ret), K(retry_times), K(arg), K(rpc_timeout)); + } + } else if (OB_FAIL(srv_rpc_proxy->to(leader_addr).by(param.tenant_id_).timeout(rpc_timeout).fetch_tablet_autoinc_seq_cache(arg, res))) { LOG_WARN("fail to fetch autoinc cache for tablets", K(ret), K(retry_times), K(arg), K(rpc_timeout)); - } else { + } + if (OB_SUCC(ret)) { finish = true; } if (OB_FAIL(ret)) { @@ -309,11 +318,10 @@ void ObTabletAutoincrementService::release_mgr(ObTabletAutoincMgr *autoinc_mgr) return; } -int ObTabletAutoincrementService::get_autoinc_seq(const uint64_t tenant_id, const common::ObTabletID &tablet_id, uint64_t &autoinc_seq) +int ObTabletAutoincrementService::get_autoinc_seq(const uint64_t tenant_id, const common::ObTabletID &tablet_id, uint64_t &autoinc_seq, const int64_t auto_increment_cache_size) { ACTIVE_SESSION_FLAG_SETTER_GUARD(in_sequence_load); int ret = OB_SUCCESS; - const int64_t auto_increment_cache_size = 10000; //TODO(shuangcan): fix me ObTabletAutoincParam param; param.tenant_id_ = tenant_id; ObTabletAutoincMgr *autoinc_mgr = nullptr; @@ -324,9 +332,6 @@ int ObTabletAutoincrementService::get_autoinc_seq(const uint64_t tenant_id, cons LOG_WARN("failed to acquire mgr", K(ret)); } else { ObTabletCacheInterval interval(tablet_id, 1/*cache size*/); - lib::ObMutex &mutex = init_node_mutexs_[tablet_id.id() % INIT_NODE_MUTEX_NUM]; - lib::ObMutexGuard guard(mutex); - lib::DisableSchedInterGuard sched_guard; if (OB_ISNULL(autoinc_mgr)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("autoinc mgr is unexpected null", K(ret)); @@ -349,7 +354,7 @@ int ObTabletAutoincrementService::get_autoinc_seq_for_mlog( uint64_t &autoinc_seq) { int ret = OB_SUCCESS; - const int64_t auto_increment_cache_size = 10000; //TODO(shuangcan): fix me + const int64_t auto_increment_cache_size = ObTabletAutoincrementService::DEFAULT_CACHE_SIZE; ObTabletAutoincParam param; param.tenant_id_ = tenant_id; ObTabletAutoincMgr *autoinc_mgr = nullptr; @@ -415,9 +420,6 @@ int ObTabletAutoincrementService::get_autoinc_seq_for_mlog( LOG_WARN("failed to acquire mgr", K(ret)); } else { ObTabletCacheInterval interval(tablet_id, 1/*cache size*/); - lib::ObMutex &mutex = init_node_mutexs_[tablet_id.id() % INIT_NODE_MUTEX_NUM]; - lib::ObMutexGuard guard(mutex); - lib::DisableSchedInterGuard sched_guard; if (OB_ISNULL(autoinc_mgr)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("autoinc mgr is unexpected null", K(ret)); diff --git a/src/share/ob_tablet_autoincrement_service.h b/src/share/ob_tablet_autoincrement_service.h index f7c064240..d6de596ff 100644 --- a/src/share/ob_tablet_autoincrement_service.h +++ b/src/share/ob_tablet_autoincrement_service.h @@ -139,11 +139,13 @@ class ObTabletAutoincrementService { public: static ObTabletAutoincrementService &get_instance(); + static const int64_t DEFAULT_CACHE_SIZE = 10000; + static const int64_t LOB_CACHE_SIZE = 100000; int init(); void destroy(); int get_tablet_cache_interval(const uint64_t tenant_id, ObTabletCacheInterval &interval); - int get_autoinc_seq(const uint64_t tenant_id, const common::ObTabletID &tablet_id, uint64_t &autoinc_seq); + int get_autoinc_seq(const uint64_t tenant_id, const common::ObTabletID &tablet_id, uint64_t &autoinc_seq, const int64_t cache_size=ObTabletAutoincrementService::DEFAULT_CACHE_SIZE); int get_autoinc_seq_for_mlog( const uint64_t tenant_id, const ObLSID &ls_id, diff --git a/src/storage/lob/ob_lob_persistent_adaptor.cpp b/src/storage/lob/ob_lob_persistent_adaptor.cpp index 0a1b6445a..6014e383e 100644 --- a/src/storage/lob/ob_lob_persistent_adaptor.cpp +++ b/src/storage/lob/ob_lob_persistent_adaptor.cpp @@ -190,7 +190,7 @@ int ObPersistentLobApator::fetch_lob_id(ObLobAccessParam& param, uint64_t &lob_i } else { uint64_t tenant_id = param.tenant_id_; share::ObTabletAutoincrementService &auto_inc = share::ObTabletAutoincrementService::get_instance(); - if (OB_FAIL(auto_inc.get_autoinc_seq(tenant_id, param.lob_meta_tablet_id_, lob_id))) { + if (OB_FAIL(auto_inc.get_autoinc_seq(tenant_id, param.lob_meta_tablet_id_, lob_id, share::ObTabletAutoincrementService::LOB_CACHE_SIZE))) { LOG_WARN("get lob_id fail", K(ret), K(tenant_id), K(param)); } else { LOG_DEBUG("get lob_id succ", K(lob_id), K(tenant_id), K(param)); @@ -229,7 +229,7 @@ int ObPersistentLobApator::fetch_lob_id_for_split_src(const ObLobAccessParam& pa LOG_WARN("fail to get tablet handle", K(ret), K(lob_tablet_id), K(param)); } else if (OB_FAIL(ObTabletSplitMdsHelper::calc_split_dst_lob(*ls_handle.get_ls(), *tablet_handle.get_obj(), *param.data_row_, param.timeout_, dst_tablet_id))) { LOG_WARN("failed to calc split dst tablet", K(ret)); - } else if (OB_FAIL(auto_inc.get_autoinc_seq(tenant_id, dst_tablet_id, lob_id))) { + } else if (OB_FAIL(auto_inc.get_autoinc_seq(tenant_id, dst_tablet_id, lob_id, share::ObTabletAutoincrementService::LOB_CACHE_SIZE))) { LOG_WARN("get lob_id fail", K(ret), K(tenant_id), K(dst_tablet_id)); } return ret;