Fix sstable defragment memory leak

This commit is contained in:
JiahuaChen
2023-02-09 16:49:33 +00:00
committed by ob-robot
parent d840b21191
commit 76724ef91f

View File

@ -383,8 +383,7 @@ int ObSharedMacroBlockMgr::defragment()
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
ObArenaAllocator task_allocator("SSTDefragTask", OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID()); ObArenaAllocator task_allocator("SSTDefragTask", OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
const lib::ObMemAttr mem_attr(MTL_ID(), "SSTDefragIter"); ObArenaAllocator iter_allocator("SSTDefragIter", OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ObFIFOAllocator iter_allocator;
ObFixedArray<MacroBlockId, ObIAllocator> macro_ids(task_allocator); ObFixedArray<MacroBlockId, ObIAllocator> macro_ids(task_allocator);
ObTenantTabletIterator tablet_iter(*(MTL(ObTenantMetaMemMgr*)), iter_allocator); ObTenantTabletIterator tablet_iter(*(MTL(ObTenantMetaMemMgr*)), iter_allocator);
ObSSTableIndexBuilder *sstable_index_builder = nullptr; ObSSTableIndexBuilder *sstable_index_builder = nullptr;
@ -394,9 +393,6 @@ int ObSharedMacroBlockMgr::defragment()
if (IS_NOT_INIT) { if (IS_NOT_INIT) {
ret = OB_NOT_INIT; ret = OB_NOT_INIT;
LOG_WARN("ObSharedMacroBlockMgr hasn't been initiated", K(ret)); LOG_WARN("ObSharedMacroBlockMgr hasn't been initiated", K(ret));
} else if (OB_FAIL(iter_allocator.init(lib::ObMallocAllocator::get_instance(),
OB_MALLOC_NORMAL_BLOCK_SIZE, mem_attr))) {
STORAGE_LOG(WARN, "fail to init fifo allocator", K(ret));
} else if (OB_FAIL(macro_ids.init(MAX_RECYCLABLE_BLOCK_CNT))) { } else if (OB_FAIL(macro_ids.init(MAX_RECYCLABLE_BLOCK_CNT))) {
LOG_WARN("fail to init macro ids", K(ret)); LOG_WARN("fail to init macro ids", K(ret));
} else if (OB_FAIL(get_recyclable_blocks(task_allocator, macro_ids))) { } else if (OB_FAIL(get_recyclable_blocks(task_allocator, macro_ids))) {
@ -408,6 +404,8 @@ int ObSharedMacroBlockMgr::defragment()
} else { } else {
ObTabletHandle tablet_handle; ObTabletHandle tablet_handle;
while (OB_SUCC(ret)) { while (OB_SUCC(ret)) {
tablet_handle.reset();
iter_allocator.reuse();
if (OB_FAIL(tablet_iter.get_next_tablet(tablet_handle))) { if (OB_FAIL(tablet_iter.get_next_tablet(tablet_handle))) {
LOG_WARN("fail to get tablet", K(ret), K(tablet_handle)); LOG_WARN("fail to get tablet", K(ret), K(tablet_handle));
} else if (OB_UNLIKELY(!tablet_handle.is_valid())) { } else if (OB_UNLIKELY(!tablet_handle.is_valid())) {