diff --git a/src/storage/access/ob_index_tree_prefetcher.cpp b/src/storage/access/ob_index_tree_prefetcher.cpp index db66c1d2c3..36dfe72079 100644 --- a/src/storage/access/ob_index_tree_prefetcher.cpp +++ b/src/storage/access/ob_index_tree_prefetcher.cpp @@ -29,6 +29,7 @@ void ObIndexTreePrefetcher::reset() { is_inited_ = false; is_rescan_ = false; + rescan_cnt_ = 0; data_version_ = 0; sstable_ = nullptr; data_block_cache_ = nullptr; @@ -108,6 +109,14 @@ int ObIndexTreePrefetcher::switch_context( if (OB_FAIL(micro_block_handle_mgr_.init(true, false, *access_ctx.stmt_allocator_))) { LOG_WARN("failed to init block handle mgr", K(ret)); } + } else { + rescan_cnt_++; + if (rescan_cnt_ >= MAX_RESCAN_HOLD_LIMIT) { + rescan_cnt_ = 0; + if (OB_FAIL(micro_block_handle_mgr_.reset_handle_cache())) { + STORAGE_LOG(WARN, "failed to reset handle cache", K(ret)); + } + } } } return ret; @@ -483,6 +492,14 @@ int ObIndexTreeMultiPrefetcher::switch_context( if (OB_FAIL(micro_block_handle_mgr_.init(true, false, *access_ctx.stmt_allocator_))) { LOG_WARN("failed to init block handle mgr", K(ret)); } + } else { + rescan_cnt_++; + if (rescan_cnt_ >= MAX_RESCAN_HOLD_LIMIT) { + rescan_cnt_ = 0; + if (OB_FAIL(micro_block_handle_mgr_.reset_handle_cache())) { + STORAGE_LOG(WARN, "failed to reset handle cache", K(ret)); + } + } } if (OB_SUCC(ret)) { if (index_scanner_.is_valid()) { diff --git a/src/storage/access/ob_index_tree_prefetcher.h b/src/storage/access/ob_index_tree_prefetcher.h index 2e3a380443..5ec4ec6c32 100644 --- a/src/storage/access/ob_index_tree_prefetcher.h +++ b/src/storage/access/ob_index_tree_prefetcher.h @@ -115,6 +115,7 @@ public: ObIndexTreePrefetcher() : is_inited_(false), is_rescan_(false), + rescan_cnt_(0), data_version_(0), sstable_(nullptr), data_block_cache_(nullptr), @@ -172,8 +173,10 @@ private: } protected: + static const int64_t MAX_RESCAN_HOLD_LIMIT = 64; bool is_inited_; bool is_rescan_; + int64_t rescan_cnt_; int64_t data_version_; ObSSTable *sstable_; ObDataMicroBlockCache *data_block_cache_; diff --git a/src/storage/ob_handle_cache.h b/src/storage/ob_handle_cache.h index 7cb229ca0b..5f914e3626 100644 --- a/src/storage/ob_handle_cache.h +++ b/src/storage/ob_handle_cache.h @@ -57,6 +57,15 @@ public: virtual ~ObHandleCache() {} + void reset_handles() + { + for (int64_t i = 0; i < N; ++i) { + nodes_[i].reset(); + } + MEMSET(buckets_, -1, sizeof(buckets_)); + MEMSET(chain_, -1, sizeof(chain_)); + } + int get_handle(const Key &key, Handle &handle) { int ret = common::OB_SUCCESS; diff --git a/src/storage/ob_micro_block_handle_mgr.cpp b/src/storage/ob_micro_block_handle_mgr.cpp index 2d238772af..494c18c259 100644 --- a/src/storage/ob_micro_block_handle_mgr.cpp +++ b/src/storage/ob_micro_block_handle_mgr.cpp @@ -333,5 +333,21 @@ int ObMicroBlockHandleMgr::put_micro_block_handle( return ret; } +int ObMicroBlockHandleMgr::reset_handle_cache() +{ + int ret = OB_SUCCESS; + if (IS_NOT_INIT) { + ret = OB_NOT_INIT; + STORAGE_LOG(WARN, "block handle mgr is not inited", K(ret)); + } else if (is_multi_) { + if (is_ordered_) { + last_handle_->reset(); + } else { + handle_cache_->reset_handles(); + } + } + return ret; +} + } } diff --git a/src/storage/ob_micro_block_handle_mgr.h b/src/storage/ob_micro_block_handle_mgr.h index 6fee396a64..4c66545101 100644 --- a/src/storage/ob_micro_block_handle_mgr.h +++ b/src/storage/ob_micro_block_handle_mgr.h @@ -87,6 +87,7 @@ public: const blocksstable::MacroBlockId ¯o_id, const blocksstable::ObIndexBlockRowHeader &idx_header, ObMicroBlockDataHandle µ_block_handle); + int reset_handle_cache(); private: // allocator for index micro block prefetch failed and async io common::ObFIFOAllocator allocator_;