From c20858a1533114a66b23f0857e631e22f3c6bb1b Mon Sep 17 00:00:00 2001 From: obdev Date: Thu, 9 Feb 2023 16:22:41 +0000 Subject: [PATCH] [Fix]manage the memory_usage of checksum_array in ObMacroBlockMeta --- .../storage/blocksstable/test_index_tree.cpp | 19 ++++++++ .../blocksstable/ob_macro_block_meta.cpp | 47 ++++++++++++++++++- .../blocksstable/ob_macro_block_meta.h | 2 + 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/mittest/mtlenv/storage/blocksstable/test_index_tree.cpp b/mittest/mtlenv/storage/blocksstable/test_index_tree.cpp index c32cdd3959..a1ec4f9ec5 100644 --- a/mittest/mtlenv/storage/blocksstable/test_index_tree.cpp +++ b/mittest/mtlenv/storage/blocksstable/test_index_tree.cpp @@ -956,6 +956,25 @@ TEST_F(TestIndexTree, test_merge_info_build_row) ASSERT_EQ(info_val.column_checksums_[i], parsed_meta.val_.column_checksums_[i]); } } + + // test deep_copy of macro_meta with given allocator + ObArenaAllocator arena_allocator; + ObFIFOAllocator safe_allocator; + OK(safe_allocator.init(&arena_allocator, OB_MALLOC_BIG_BLOCK_SIZE)); + ObDataMacroBlockMeta *copy_meta = nullptr; + ObDataMacroBlockMeta &large_meta = *merge_info_list->at(0); + int64_t test_col_cnt = 100; + for (int64_t i = 0; i < test_col_cnt; ++i) { + OK(large_meta.val_.column_checksums_.push_back(i)); + } + ASSERT_EQ(safe_allocator.current_using_, nullptr); + ASSERT_EQ(safe_allocator.normal_used_, 0); + OK(large_meta.deep_copy(copy_meta, safe_allocator)); + ASSERT_NE(safe_allocator.current_using_, nullptr); + safe_allocator.free(copy_meta); + copy_meta->~ObDataMacroBlockMeta(); + const int64_t end_key_deep_copy_size = 64; // due to end_key::reset by memset + ASSERT_EQ(safe_allocator.normal_used_, end_key_deep_copy_size); } TEST_F(TestIndexTree, test_meta_builder) diff --git a/src/storage/blocksstable/ob_macro_block_meta.cpp b/src/storage/blocksstable/ob_macro_block_meta.cpp index 3abdd803de..b2e970ee19 100644 --- a/src/storage/blocksstable/ob_macro_block_meta.cpp +++ b/src/storage/blocksstable/ob_macro_block_meta.cpp @@ -48,13 +48,48 @@ ObDataBlockMetaVal::ObDataBlockMetaVal() snapshot_version_(0), logic_id_(), macro_id_(), - column_checksums_(), + column_checksums_(common::OB_MALLOC_NORMAL_BLOCK_SIZE, ModulePageAllocator("MacroMetaChksum", MTL_ID())), has_string_out_row_(false), all_lob_in_row_(false) { MEMSET(encrypt_key_, 0, share::OB_MAX_TABLESPACE_ENCRYPT_KEY_LENGTH); } +ObDataBlockMetaVal::ObDataBlockMetaVal(ObIAllocator &allocator) + : version_(DATA_BLOCK_META_VAL_VERSION), + length_(0), + data_checksum_(0), + rowkey_count_(0), + column_count_(0), + micro_block_count_(0), + occupy_size_(0), + data_size_(0), + data_zsize_(0), + original_size_(0), + progressive_merge_round_(0), + block_offset_(0), + block_size_(0), + row_count_(0), + row_count_delta_(0), + max_merged_trans_version_(0), + is_encrypted_(false), + is_deleted_(false), + contain_uncommitted_row_(false), + is_last_row_last_flag_(false), + compressor_type_(ObCompressorType::INVALID_COMPRESSOR), + master_key_id_(0), + encrypt_id_(0), + row_store_type_(ObRowStoreType::MAX_ROW_STORE), + schema_version_(0), + snapshot_version_(0), + logic_id_(), + macro_id_(), + column_checksums_(common::OB_MALLOC_NORMAL_BLOCK_SIZE, ModulePageAllocator(allocator, "MacroMetaChksum")), + has_string_out_row_(false), + all_lob_in_row_(false) +{ + MEMSET(encrypt_key_, 0, share::OB_MAX_TABLESPACE_ENCRYPT_KEY_LENGTH); +} ObDataBlockMetaVal::~ObDataBlockMetaVal() { reset(); @@ -361,6 +396,14 @@ ObDataMacroBlockMeta::ObDataMacroBlockMeta() { } +ObDataMacroBlockMeta::ObDataMacroBlockMeta(ObIAllocator &allocator) + : val_(allocator), + end_key_(), + nested_offset_(0), + nested_size_(0) +{ +} + ObDataMacroBlockMeta::~ObDataMacroBlockMeta() { reset(); @@ -395,7 +438,7 @@ int ObDataMacroBlockMeta::deep_copy(ObDataMacroBlockMeta *&dst, ObIAllocator &al ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("fail to allocate memory", K(ret), K(buf_len)); } else { - ObDataMacroBlockMeta *meta = new (buf) ObDataMacroBlockMeta(); + ObDataMacroBlockMeta *meta = new (buf) ObDataMacroBlockMeta(allocator); ObStorageDatum *endkey = new (buf + sizeof(ObDataMacroBlockMeta)) ObStorageDatum[rowkey_count]; for (int64_t i = 0; OB_SUCC(ret) && i < rowkey_count; ++i) { if (OB_FAIL(endkey[i].deep_copy(end_key_.datums_[i], allocator))) { diff --git a/src/storage/blocksstable/ob_macro_block_meta.h b/src/storage/blocksstable/ob_macro_block_meta.h index 7ae8c1ca9b..928c67c7bf 100644 --- a/src/storage/blocksstable/ob_macro_block_meta.h +++ b/src/storage/blocksstable/ob_macro_block_meta.h @@ -38,6 +38,7 @@ private: static const int32_t DATA_BLOCK_META_VAL_VERSION = 1; public: ObDataBlockMetaVal(); + explicit ObDataBlockMetaVal(ObIAllocator &allocator); ~ObDataBlockMetaVal(); void reset(); bool is_valid() const; @@ -97,6 +98,7 @@ class ObDataMacroBlockMeta final { public: ObDataMacroBlockMeta(); + explicit ObDataMacroBlockMeta(ObIAllocator &allocator); ~ObDataMacroBlockMeta(); int assign(const ObDataMacroBlockMeta &meta); int deep_copy(ObDataMacroBlockMeta *&dst, ObIAllocator &allocator) const;