ob_table_load_manager use obhashmap instead of ob_current_hash_map
This commit is contained in:
@ -29,25 +29,25 @@ public:
|
|||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
int get_or_new(const KeyType &key, ValueType *&value, bool &is_new, const Args&... args);
|
int get_or_new(const KeyType &key, ValueType *&value, bool &is_new, const Args&... args);
|
||||||
template <typename Function>
|
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:
|
private:
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
int new_value(const KeyType &key, ValueType *&value, const Args&... args);
|
int new_value(const KeyType &key, ValueType *&value, const Args&... args);
|
||||||
private:
|
private:
|
||||||
common::ObConcurrentHashMap<KeyType, ValueType *> value_map_;
|
common::hash::ObHashMap<KeyType, ValueType *> value_map_;
|
||||||
lib::ObMutex mutex_;
|
lib::ObMutex mutex_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class KeyType, class ValueType>
|
template<class KeyType, class ValueType>
|
||||||
int ObTableLoadManager<KeyType, ValueType>::init()
|
int ObTableLoadManager<KeyType, ValueType>::init()
|
||||||
{
|
{
|
||||||
return value_map_.init();
|
return value_map_.create(1024, "TLD_LoadMgr", "TLD_LoadMgr");
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class KeyType, class ValueType>
|
template<class KeyType, class ValueType>
|
||||||
int ObTableLoadManager<KeyType, ValueType>::put(const KeyType &key, ValueType *value)
|
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>
|
template<class KeyType, class ValueType>
|
||||||
@ -59,7 +59,7 @@ int ObTableLoadManager<KeyType, ValueType>::get(const KeyType &key, ValueType *&
|
|||||||
template<class KeyType, class ValueType>
|
template<class KeyType, class ValueType>
|
||||||
int ObTableLoadManager<KeyType, ValueType>::remove(const KeyType &key, ValueType *value)
|
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>
|
template<class KeyType, class ValueType>
|
||||||
@ -70,7 +70,7 @@ int ObTableLoadManager<KeyType, ValueType>::new_value(const KeyType &key, ValueT
|
|||||||
int ret = common::OB_SUCCESS;
|
int ret = common::OB_SUCCESS;
|
||||||
lib::ObMutexGuard guard(mutex_);
|
lib::ObMutexGuard guard(mutex_);
|
||||||
ret = get(key, value);
|
ret = get(key, value);
|
||||||
if (ret == common::OB_ENTRY_NOT_EXIST) {
|
if (ret == common::OB_HASH_NOT_EXIST) {
|
||||||
ret = common::OB_SUCCESS;
|
ret = common::OB_SUCCESS;
|
||||||
if (OB_ISNULL(value = OB_NEW(ValueType, ObMemAttr(MTL_ID(), "TLD_MgrValue"), args...))) {
|
if (OB_ISNULL(value = OB_NEW(ValueType, ObMemAttr(MTL_ID(), "TLD_MgrValue"), args...))) {
|
||||||
ret = common::OB_ALLOCATE_MEMORY_FAILED;
|
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) {
|
} else if (ret != common::OB_SUCCESS) {
|
||||||
OB_LOG(WARN, "fail to get value", KR(ret));
|
OB_LOG(WARN, "fail to get value", KR(ret));
|
||||||
} else { // 已存在
|
} else { // 已存在
|
||||||
ret = common::OB_ENTRY_EXIST;
|
ret = common::OB_HASH_EXIST;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -106,12 +106,13 @@ int ObTableLoadManager<KeyType, ValueType>::new_and_insert(const KeyType &key, V
|
|||||||
const Args&... args)
|
const Args&... args)
|
||||||
{
|
{
|
||||||
int ret = common::OB_SUCCESS;
|
int ret = common::OB_SUCCESS;
|
||||||
ret = value_map_.contains_key(key);
|
ValueType *tmp_value = nullptr;
|
||||||
if (OB_LIKELY(common::OB_ENTRY_NOT_EXIST == ret)) {
|
ret = get(key, tmp_value);
|
||||||
|
if (OB_LIKELY(common::OB_HASH_NOT_EXIST == ret)) {
|
||||||
ret = new_value(key, value, args...);
|
ret = new_value(key, value, args...);
|
||||||
}
|
}
|
||||||
if (OB_FAIL(ret)) {
|
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));
|
OB_LOG(WARN, "value already exist", KR(ret), K(key));
|
||||||
} else {
|
} else {
|
||||||
OB_LOG(WARN, "fail to call contains key", KR(ret), K(key));
|
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;
|
value = nullptr;
|
||||||
is_new = false;
|
is_new = false;
|
||||||
ret = get(key, value);
|
ret = get(key, value);
|
||||||
if (common::OB_ENTRY_NOT_EXIST == ret) {
|
if (common::OB_HASH_NOT_EXIST == ret) {
|
||||||
ret = common::OB_SUCCESS;
|
ret = common::OB_SUCCESS;
|
||||||
if (OB_FAIL(new_value(key, value, args...))) {
|
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));
|
OB_LOG(WARN, "fail to new value", KR(ret));
|
||||||
} else { // 已存在
|
} else { // 已存在
|
||||||
ret = common::OB_SUCCESS;
|
ret = common::OB_SUCCESS;
|
||||||
|
|||||||
@ -44,8 +44,9 @@ void ObTableLoadService::ObGCTask::runTimerTask()
|
|||||||
LOG_WARN("ObTableLoadService::ObGCTask not init", KR(ret), KP(this));
|
LOG_WARN("ObTableLoadService::ObGCTask not init", KR(ret), KP(this));
|
||||||
} else {
|
} else {
|
||||||
LOG_DEBUG("table load start gc", K(tenant_id_));
|
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;
|
int ret = OB_SUCCESS;
|
||||||
|
uint64_t table_id = entry.first;
|
||||||
ObTableLoadTableCtx *table_ctx = nullptr;
|
ObTableLoadTableCtx *table_ctx = nullptr;
|
||||||
if (OB_FAIL(service_.get_table_ctx(table_id, table_ctx))) {
|
if (OB_FAIL(service_.get_table_ctx(table_id, table_ctx))) {
|
||||||
} else if (table_ctx->is_dirty()) {
|
} else if (table_ctx->is_dirty()) {
|
||||||
@ -81,7 +82,7 @@ void ObTableLoadService::ObGCTask::runTimerTask()
|
|||||||
service_.put_table_ctx(table_ctx);
|
service_.put_table_ctx(table_ctx);
|
||||||
table_ctx = nullptr;
|
table_ctx = nullptr;
|
||||||
}
|
}
|
||||||
return true;
|
return ret;
|
||||||
};
|
};
|
||||||
service_.table_ctx_manager_.for_each(fn);
|
service_.table_ctx_manager_.for_each(fn);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user