提交 1207f0bf 编写于 作者: O obdev 提交者: ob-robot

ob_table_load_manager use obhashmap instead of ob_current_hash_map

上级 78662489
......@@ -29,25 +29,25 @@ public:
template<typename... Args>
int get_or_new(const KeyType &key, ValueType *&value, bool &is_new, const Args&... args);
template <typename Function>
int for_each(Function &fn) { return value_map_.for_each(fn); }
int for_each(Function &fn) { return value_map_.foreach_refactored(fn); }
private:
template<typename... Args>
int new_value(const KeyType &key, ValueType *&value, const Args&... args);
private:
common::ObConcurrentHashMap<KeyType, ValueType *> value_map_;
common::hash::ObHashMap<KeyType, ValueType *> value_map_;
lib::ObMutex mutex_;
};
template<class KeyType, class ValueType>
int ObTableLoadManager<KeyType, ValueType>::init()
{
return value_map_.init();
return value_map_.create(1024, "TLD_LoadMgr", "TLD_LoadMgr");
}
template<class KeyType, class ValueType>
int ObTableLoadManager<KeyType, ValueType>::put(const KeyType &key, ValueType *value)
{
return value_map_.put_refactored(key, value);
return value_map_.set_refactored(key, value);
}
template<class KeyType, class ValueType>
......@@ -59,7 +59,7 @@ int ObTableLoadManager<KeyType, ValueType>::get(const KeyType &key, ValueType *&
template<class KeyType, class ValueType>
int ObTableLoadManager<KeyType, ValueType>::remove(const KeyType &key, ValueType *value)
{
return value_map_.remove_refactored(key);
return value_map_.erase_refactored(key);
}
template<class KeyType, class ValueType>
......@@ -70,7 +70,7 @@ int ObTableLoadManager<KeyType, ValueType>::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<KeyType, ValueType>::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<KeyType, ValueType>::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<KeyType, ValueType>::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;
......
......@@ -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<uint64_t, ObTableLoadTableCtx *> &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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册