Perf optimization: Avoid memory alloc when load aux tablet info

This commit is contained in:
JiahuaChen
2023-12-15 11:13:16 +00:00
committed by ant-ob-hengtang
parent 3e0d23e6e4
commit 37621d8cfe
3 changed files with 9 additions and 30 deletions

View File

@ -195,20 +195,16 @@ inline int ObITabletMdsInterface::get_mds_data_from_tablet<ObTabletBindingMdsUse
#define PRINT_WRAPPER KR(ret), K(aux_tablet_info_addr), K(*this)
MDS_TG(10_ms);
int ret = OB_SUCCESS;
ObTabletBindingMdsUserData *aux_tablet_info = nullptr;
ObArenaAllocator allocator("mds_reader");
ObTabletBindingMdsUserData aux_tablet_info;
const ObTabletComplexAddr<mds::MdsDumpKV> &aux_tablet_info_addr = get_mds_data_().aux_tablet_info_.committed_kv_;
if (CLICK_FAIL(ObTabletMdsData::load_aux_tablet_info(allocator, aux_tablet_info_addr, aux_tablet_info))) {
if (CLICK_FAIL(ObTabletMdsData::load_aux_tablet_info(aux_tablet_info_addr, aux_tablet_info))) {
MDS_LOG_GET(WARN, "failed to load auto inc seq");
} else if (nullptr == aux_tablet_info) {
} else if (!aux_tablet_info.is_valid()) {
ret = OB_EMPTY_RESULT;
} else if (CLICK_FAIL(read_op(*aux_tablet_info))) {
} else if (CLICK_FAIL(read_op(aux_tablet_info))) {
MDS_LOG_GET(WARN, "failed to read_op");
}
ObTabletObjLoadHelper::free(allocator, aux_tablet_info);
return ret;
#undef PRINT_WRAPPER
}

View File

@ -1153,30 +1153,24 @@ int ObTabletMdsData::load_auto_inc_seq(
}
int ObTabletMdsData::load_aux_tablet_info(
common::ObIAllocator &allocator,
const ObTabletComplexAddr<mds::MdsDumpKV> &complex_addr,
ObTabletBindingMdsUserData *&aux_tablet_info)
ObTabletBindingMdsUserData &aux_tablet_info)
{
int ret = OB_SUCCESS;
aux_tablet_info = nullptr;
ObTabletBindingMdsUserData *ptr = nullptr;
aux_tablet_info.reset();
if (OB_UNLIKELY(!complex_addr.is_valid())) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid addr", K(ret), K(complex_addr));
} else if (complex_addr.is_none_object()) {
// do nothing
} else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, ptr))) {
LOG_WARN("failed to alloc and new", K(ret));
} else if (complex_addr.is_memory_object()) {
const mds::MdsDumpKV *dump_kv = complex_addr.ptr_;
const common::ObString &str = dump_kv->v_.user_data_;
int64_t pos = 0;
if (!dump_kv->is_valid() || str.empty()) {
ObTabletObjLoadHelper::free(allocator, ptr);
ptr = nullptr;
LOG_INFO("read empty aux tablet info", K(ret), K(complex_addr));
} else if (OB_FAIL(ptr->deserialize(str.ptr(), str.length(), pos))) {
} else if (OB_FAIL(aux_tablet_info.deserialize(str.ptr(), str.length(), pos))) {
LOG_WARN("failed to deserialize aux tablet info", K(ret), K(str));
}
} else if (complex_addr.is_disk_object()) {
@ -1195,10 +1189,8 @@ int ObTabletMdsData::load_aux_tablet_info(
LOG_WARN("unexpected null member", K(ret));
} else if (!aux_tablet_info_cache->is_valid()) {
// no need to copy
ObTabletObjLoadHelper::free(allocator, ptr);
ptr = nullptr;
LOG_INFO("empty aux tablet info", K(ret));
} else if (OB_FAIL(ptr->assign(*aux_tablet_info_cache))) {
} else if (OB_FAIL(aux_tablet_info.assign(*aux_tablet_info_cache))) {
LOG_WARN("failed to copy", K(ret));
}
} else {
@ -1206,14 +1198,6 @@ int ObTabletMdsData::load_aux_tablet_info(
LOG_WARN("unexpected complex addr type", K(ret), K(complex_addr));
}
if (OB_FAIL(ret)) {
if (nullptr != ptr) {
allocator.free(ptr);
}
} else {
aux_tablet_info = ptr;
}
return ret;
}

View File

@ -127,9 +127,8 @@ public:
const ObTabletComplexAddr<share::ObTabletAutoincSeq> &complex_addr,
share::ObTabletAutoincSeq *&auto_inc_seq);
static int load_aux_tablet_info(
common::ObIAllocator &allocator,
const ObTabletComplexAddr<mds::MdsDumpKV> &complex_addr,
ObTabletBindingMdsUserData *&aux_tablet_info);
ObTabletBindingMdsUserData &aux_tablet_info);
static int build_tablet_status(
common::ObArenaAllocator &allocator,
const ObTabletTxMultiSourceDataUnit &tx_data,