diff --git a/src/storage/blocksstable/ob_sstable.cpp b/src/storage/blocksstable/ob_sstable.cpp index 6ee018ccc..0d52c8cf6 100644 --- a/src/storage/blocksstable/ob_sstable.cpp +++ b/src/storage/blocksstable/ob_sstable.cpp @@ -889,8 +889,6 @@ int ObSSTable::deserialize_post_work() if (OB_UNLIKELY(hold_macro_ref_)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("post work may be done", K(ret), KPC(this)); - } else if (OB_FAIL(meta_.macro_info_.deserialize_post_work())) { - LOG_WARN("fail to do post work for sstable meta", K(ret), K(meta_)); } else if (OB_FAIL(add_macro_ref())) { LOG_WARN("fail to add macro ref", K(ret)); } else if (SSTABLE_WRITE_BUILDING != meta_.get_basic_meta().status_ && OB_FAIL(check_valid_for_reading())) { @@ -922,6 +920,12 @@ void ObSSTable::dec_macro_ref() LOG_ERROR("fail to dec other block ref cnt", K(ret), K(macro_id), K(idx)); } } + for (idx = 0; idx < meta_.get_macro_info().get_linked_block_ids().count(); ++idx) {// ignore ret + const MacroBlockId ¯o_id = meta_.get_macro_info().get_linked_block_ids().at(idx); + if (OB_FAIL(OB_SERVER_BLOCK_MGR.dec_ref(macro_id))) { + LOG_ERROR("fail to dec link block ref cnt", K(ret), K(macro_id), K(idx)); + } + } if (OB_FAIL(dec_used_size())) {// ignore ret LOG_ERROR("fail to dec used size of shared block", K(ret)); } @@ -933,6 +937,7 @@ int ObSSTable::add_macro_ref() int ret = OB_SUCCESS; int64_t i = 0; int64_t j = 0; + int64_t k = 0; while (OB_SUCC(ret) && i < meta_.get_macro_info().get_data_block_ids().count()) { const MacroBlockId ¯o_id = meta_.get_macro_info().get_data_block_ids().at(i); if (OB_FAIL(OB_SERVER_BLOCK_MGR.inc_ref(macro_id))) { @@ -949,6 +954,14 @@ int ObSSTable::add_macro_ref() ++j; } } + while (OB_SUCC(ret) && k < meta_.get_macro_info().get_linked_block_ids().count()) { + const MacroBlockId ¯o_id = meta_.get_macro_info().get_linked_block_ids().at(k); + if (OB_FAIL(OB_SERVER_BLOCK_MGR.inc_ref(macro_id))) { + LOG_ERROR("fail to inc link block ref cnt", K(ret), K(macro_id), K(k)); + } else { + ++k; + } + } if (OB_SUCC(ret) && OB_FAIL(add_used_size())) { LOG_ERROR("fail to add used size", K(ret)); } @@ -968,6 +981,13 @@ int ObSSTable::add_macro_ref() LOG_ERROR("fail to dec other block ref cnt", K(ret), K(tmp_ret), K(macro_id)); } } + idx = k - 1; + for (; idx >= 0; --idx) {// ignore ret + const MacroBlockId ¯o_id = meta_.get_macro_info().get_linked_block_ids().at(idx); + if (OB_UNLIKELY(OB_SUCCESS != (tmp_ret = OB_SERVER_BLOCK_MGR.dec_ref(macro_id)))) { + LOG_ERROR("fail to dec link block ref cnt", K(ret), K(tmp_ret), K(macro_id)); + } + } } if (OB_SUCC(ret)) { hold_macro_ref_ = true; diff --git a/src/storage/blocksstable/ob_sstable_meta_info.cpp b/src/storage/blocksstable/ob_sstable_meta_info.cpp index 9bb3066f2..ac5689a90 100644 --- a/src/storage/blocksstable/ob_sstable_meta_info.cpp +++ b/src/storage/blocksstable/ob_sstable_meta_info.cpp @@ -425,9 +425,9 @@ void ObSSTableMacroInfo::reset() macro_meta_info_.reset(); data_block_ids_.reset(); other_block_ids_.reset(); + linked_block_ids_.reset(); entry_id_.reset(); is_meta_root_ = false; - reset_linked_block_list(); nested_offset_ = 0; nested_size_ = 0; } @@ -538,18 +538,6 @@ int ObSSTableMacroInfo::save_linked_block_list( return ret; } -void ObSSTableMacroInfo::reset_linked_block_list() -{ - int ret = OB_SUCCESS; - for (int64_t i = 0; i < linked_block_ids_.count(); i++) { - const MacroBlockId ¯o_id = linked_block_ids_.at(i); - if (OB_FAIL(OB_SERVER_BLOCK_MGR.dec_ref(macro_id))) { - LOG_ERROR("fail to dec macro block ref cnt", K(ret), K(i), K(macro_id)); - } - } - linked_block_ids_.reset(); -} - int ObSSTableMacroInfo::deserialize( common::ObIAllocator *allocator, const ObMicroBlockDesMeta &des_meta, @@ -590,20 +578,6 @@ int ObSSTableMacroInfo::deserialize( return ret; } -int ObSSTableMacroInfo::deserialize_post_work() -{ - int ret = OB_SUCCESS; - if (ObServerSuperBlock::EMPTY_LIST_ENTRY_BLOCK != entry_id_) { // linked block - ObLinkedMacroBlockItemReader block_reader; - if (OB_FAIL(read_block_ids(block_reader))) { - LOG_WARN("fail to read data block ids", K(ret)); - } else if (OB_FAIL(save_linked_block_list(block_reader.get_meta_block_list(), linked_block_ids_))) { - LOG_WARN("fail to save linked block ids", K(ret), K_(linked_block_ids)); - } - } - return ret; -} - int ObSSTableMacroInfo::deserialize_( common::ObIAllocator *allocator, const ObMicroBlockDesMeta &des_meta, @@ -622,7 +596,12 @@ int ObSSTableMacroInfo::deserialize_( LOG_WARN("fail to deserialize entry block macro id", K(ret), KP(buf), K(data_len), K(pos)); } else if (ObServerSuperBlock::EMPTY_LIST_ENTRY_BLOCK != entry_id_) { linked_block_ids_.set_allocator(allocator); - // Here, do nothing. ID's array will be read from linked block at post work. + ObLinkedMacroBlockItemReader block_reader; + if (OB_FAIL(read_block_ids(block_reader))) { + LOG_WARN("fail to read data block ids", K(ret)); + } else if (OB_FAIL(linked_block_ids_.assign(block_reader.get_meta_block_list()))) { + LOG_WARN("fail to save linked block ids", K(ret), K_(linked_block_ids)); + } } else { if (pos < data_len && OB_FAIL(data_block_ids_.deserialize(buf, data_len, pos))) { LOG_WARN("fail to deserialize data block ids", K(ret), KP(buf), K(data_len), K(pos)); diff --git a/src/storage/blocksstable/ob_sstable_meta_info.h b/src/storage/blocksstable/ob_sstable_meta_info.h index 91a87688e..27adad57d 100644 --- a/src/storage/blocksstable/ob_sstable_meta_info.h +++ b/src/storage/blocksstable/ob_sstable_meta_info.h @@ -95,7 +95,6 @@ public: const char *buf, const int64_t data_len, int64_t &pos); - int deserialize_post_work(); int64_t get_serialize_size() const; OB_INLINE const storage::ObMetaDiskAddr &get_macro_meta_addr() const { @@ -153,7 +152,6 @@ private: int save_linked_block_list( const common::ObIArray &list, common::ObIArray &linked_list) const; - void reset_linked_block_list(); private: friend class ObSSTable; diff --git a/unittest/storage/blocksstable/test_sstable_meta.cpp b/unittest/storage/blocksstable/test_sstable_meta.cpp index e32c274ac..4c5e9879c 100644 --- a/unittest/storage/blocksstable/test_sstable_meta.cpp +++ b/unittest/storage/blocksstable/test_sstable_meta.cpp @@ -451,7 +451,6 @@ TEST_F(TestSSTableMacroInfo, test_huge_block_ids) ObSSTableMacroInfo tmp_info; pos = 0; ASSERT_EQ(OB_SUCCESS, tmp_info.deserialize(&allocator_, des_meta_, buf, buf_len, pos)); - ASSERT_EQ(OB_SUCCESS, tmp_info.deserialize_post_work()); for (int i = 0; i < blocksstable::ObSSTableMacroInfo::BLOCK_CNT_THRESHOLD; i++) { ASSERT_EQ(sstable_macro_info.data_block_ids_.at(i), tmp_info.data_block_ids_.at(i)); }