diff --git a/src/observer/table_load/ob_table_load_manager.h b/src/observer/table_load/ob_table_load_manager.h index 77022f28acb32143a70c84ef502d8a9f1b9edd86..9f2c933d860ce50f2d07eeeeda6f2017e3dfd72c 100644 --- a/src/observer/table_load/ob_table_load_manager.h +++ b/src/observer/table_load/ob_table_load_manager.h @@ -29,25 +29,25 @@ public: template int get_or_new(const KeyType &key, ValueType *&value, bool &is_new, const Args&... args); template - int for_each(Function &fn) { return value_map_.for_each(fn); } + int for_each(Function &fn) { return value_map_.foreach_refactored(fn); } private: template int new_value(const KeyType &key, ValueType *&value, const Args&... args); private: - common::ObConcurrentHashMap value_map_; + common::hash::ObHashMap value_map_; lib::ObMutex mutex_; }; template int ObTableLoadManager::init() { - return value_map_.init(); + return value_map_.create(1024, "TLD_LoadMgr", "TLD_LoadMgr"); } template int ObTableLoadManager::put(const KeyType &key, ValueType *value) { - return value_map_.put_refactored(key, value); + return value_map_.set_refactored(key, value); } template @@ -59,7 +59,7 @@ int ObTableLoadManager::get(const KeyType &key, ValueType *& template int ObTableLoadManager::remove(const KeyType &key, ValueType *value) { - return value_map_.remove_refactored(key); + return value_map_.erase_refactored(key); } template @@ -70,7 +70,7 @@ int ObTableLoadManager::new_value(const KeyType &key, ValueT int ret = common::OB_SUCCESS; lib::ObMutexGuard guard(mutex_); ret = get(key, value); - if (ret == common::OB_ENTRY_NOT_EXIST) { + if (ret == common::OB_HASH_NOT_EXIST) { ret = common::OB_SUCCESS; if (OB_ISNULL(value = OB_NEW(ValueType, ObMemAttr(MTL_ID(), "TLD_MgrValue"), args...))) { ret = common::OB_ALLOCATE_MEMORY_FAILED; @@ -89,7 +89,7 @@ int ObTableLoadManager::new_value(const KeyType &key, ValueT } else if (ret != common::OB_SUCCESS) { OB_LOG(WARN, "fail to get value", KR(ret)); } else { // 已存在 - ret = common::OB_ENTRY_EXIST; + ret = common::OB_HASH_EXIST; } return ret; } @@ -106,12 +106,13 @@ int ObTableLoadManager::new_and_insert(const KeyType &key, V const Args&... args) { int ret = common::OB_SUCCESS; - ret = value_map_.contains_key(key); - if (OB_LIKELY(common::OB_ENTRY_NOT_EXIST == ret)) { + ValueType *tmp_value = nullptr; + ret = get(key, tmp_value); + if (OB_LIKELY(common::OB_HASH_NOT_EXIST == ret)) { ret = new_value(key, value, args...); } if (OB_FAIL(ret)) { - if (OB_LIKELY(common::OB_ENTRY_EXIST == ret)) { + if (OB_LIKELY(common::OB_HASH_EXIST == ret)) { OB_LOG(WARN, "value already exist", KR(ret), K(key)); } else { OB_LOG(WARN, "fail to call contains key", KR(ret), K(key)); @@ -129,10 +130,10 @@ int ObTableLoadManager::get_or_new(const KeyType &key, Value value = nullptr; is_new = false; ret = get(key, value); - if (common::OB_ENTRY_NOT_EXIST == ret) { + if (common::OB_HASH_NOT_EXIST == ret) { ret = common::OB_SUCCESS; if (OB_FAIL(new_value(key, value, args...))) { - if (OB_UNLIKELY(common::OB_ENTRY_EXIST != ret)) { + if (OB_UNLIKELY(common::OB_HASH_EXIST != ret)) { OB_LOG(WARN, "fail to new value", KR(ret)); } else { // 已存在 ret = common::OB_SUCCESS; diff --git a/src/observer/table_load/ob_table_load_service.cpp b/src/observer/table_load/ob_table_load_service.cpp index 239ac608cb96fd07eb182a638bd0fff55c73500a..51c957990ff5cd61ed7da0b46161ad3c0160591e 100644 --- a/src/observer/table_load/ob_table_load_service.cpp +++ b/src/observer/table_load/ob_table_load_service.cpp @@ -44,8 +44,9 @@ void ObTableLoadService::ObGCTask::runTimerTask() LOG_WARN("ObTableLoadService::ObGCTask not init", KR(ret), KP(this)); } else { LOG_DEBUG("table load start gc", K(tenant_id_)); - auto fn = [this](uint64_t table_id, ObTableLoadTableCtx *) -> bool { + auto fn = [this](common::hash::HashMapPair &entry) -> int { int ret = OB_SUCCESS; + uint64_t table_id = entry.first; ObTableLoadTableCtx *table_ctx = nullptr; if (OB_FAIL(service_.get_table_ctx(table_id, table_ctx))) { } else if (table_ctx->is_dirty()) { @@ -81,7 +82,7 @@ void ObTableLoadService::ObGCTask::runTimerTask() service_.put_table_ctx(table_ctx); table_ctx = nullptr; } - return true; + return ret; }; service_.table_ctx_manager_.for_each(fn); }