diff --git a/mittest/mtlenv/storage/CMakeLists.txt b/mittest/mtlenv/storage/CMakeLists.txt index f0f2c75e5..48149792d 100644 --- a/mittest/mtlenv/storage/CMakeLists.txt +++ b/mittest/mtlenv/storage/CMakeLists.txt @@ -20,6 +20,7 @@ storage_dml_unittest(test_multi_version_sstable_single_get) #storage_dml_unittest(test_multi_version_sstable_merge) TODO(dengzhi.ldz): fix it storage_dml_unittest(test_medium_info_reader test_medium_info_reader.cpp) storage_dml_unittest(test_tablet_mds_data test_tablet_mds_data.cpp) +storage_dml_unittest(test_mds_data_read_write test_mds_data_read_write.cpp) storage_unittest(test_physical_copy_task test_physical_copy_task.cpp) storage_unittest(test_shared_block_reader_writer) storage_dml_unittest(test_macro_ref_cnt test_macro_ref_cnt.cpp) diff --git a/mittest/mtlenv/storage/test_mds_data_read_write.cpp b/mittest/mtlenv/storage/test_mds_data_read_write.cpp new file mode 100644 index 000000000..0be6608e5 --- /dev/null +++ b/mittest/mtlenv/storage/test_mds_data_read_write.cpp @@ -0,0 +1,488 @@ +/** + * Copyright (c) 2021 OceanBase + * OceanBase CE is licensed under Mulan PubL v2. + * You can use this software according to the terms and conditions of the Mulan PubL v2. + * You may obtain a copy of Mulan PubL v2 at: + * http://license.coscl.org.cn/MulanPubL-2.0 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PubL v2 for more details. + */ + +#include + +#define protected public +#define private public + +#include "lib/ob_errno.h" +#include "lib/allocator/page_arena.h" +#include "lib/oblog/ob_log.h" +#include "mtlenv/mock_tenant_module_env.h" +#include "mtlenv/storage/medium_info_helper.h" +#include "storage/tablet/ob_tablet_mds_data.h" +#include "storage/tablet/ob_tablet_complex_addr.h" +#include "storage/tablet/ob_tablet_obj_load_helper.h" +#include "storage/slog_ckpt/ob_tenant_checkpoint_slog_handler.h" + +#define USING_LOG_PREFIX STORAGE + +using namespace oceanbase::common; + +namespace oceanbase +{ +namespace storage +{ +class TestMdsDataReadWrite : public::testing::Test +{ +public: + TestMdsDataReadWrite(); + virtual ~TestMdsDataReadWrite() = default; + static void SetUpTestCase(); + static void TearDownTestCase(); + //virtual void SetUp() override; + //virtual void TearDown() override; +private: + static int mock_tablet_status_disk_addr( + common::ObArenaAllocator &allocator, + ObMetaDiskAddr &addr); + static int mock_empty_tablet_status_disk_addr( + common::ObArenaAllocator &allocator, + ObMetaDiskAddr &addr); + static int mock_auto_inc_seq_disk_addr( + common::ObArenaAllocator &allocator, + ObMetaDiskAddr &addr); + static int mock_empty_auto_inc_seq_disk_addr( + common::ObArenaAllocator &allocator, + ObMetaDiskAddr &addr); +}; + +TestMdsDataReadWrite::TestMdsDataReadWrite() +{ +} + +void TestMdsDataReadWrite::SetUpTestCase() +{ + EXPECT_EQ(OB_SUCCESS, MockTenantModuleEnv::get_instance().init()); +} + +void TestMdsDataReadWrite::TearDownTestCase() +{ + MockTenantModuleEnv::get_instance().destroy(); +} + +int TestMdsDataReadWrite::mock_tablet_status_disk_addr( + common::ObArenaAllocator &allocator, + ObMetaDiskAddr &addr) +{ + int ret = OB_SUCCESS; + ObTenantCheckpointSlogHandler *ckpt_slog_handler = MTL(ObTenantCheckpointSlogHandler*); + mds::MdsDumpKV kv; + + { + ObTabletCreateDeleteMdsUserData user_data; + user_data.tablet_status_ = ObTabletStatus::NORMAL; + const int64_t size = user_data.get_serialize_size(); + int64_t pos = 0; + char *buf = static_cast(allocator.alloc(size)); + if (OB_ISNULL(buf)) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_WARN("failed to alloc memory", K(ret), K(size)); + } else if (OB_FAIL(user_data.serialize(buf, size, pos))) { + LOG_WARN("failed to serialize", K(ret)); + } else { + ObString &str = kv.v_.user_data_; + str.assign(buf, size); + } + } + + + const int64_t size = kv.get_serialize_size(); + int64_t pos = 0; + + char *buf = static_cast(allocator.alloc(size)); + if (OB_FAIL(ret)) { + } else if (OB_ISNULL(buf)) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_WARN("failed to alloc memory", K(ret), K(size)); + } else if (OB_FAIL(kv.serialize(buf, size, pos))) { + LOG_WARN("failed to serialize", K(ret)); + } else { + ObSharedBlockWriteInfo write_info; + write_info.buffer_ = buf; + write_info.offset_ = 0; + write_info.size_ = size; + write_info.io_desc_.set_wait_event(ObWaitEventIds::DB_FILE_COMPACT_WRITE); + + ObSharedBlockWriteHandle handle; + ObSharedBlocksWriteCtx write_ctx; + if (OB_FAIL(ckpt_slog_handler->get_shared_block_reader_writer().async_write(write_info, handle))) { + LOG_WARN("failed to do async write", K(ret)); + } else if (OB_FAIL(handle.get_write_ctx(write_ctx))) { + LOG_WARN("failed to get write ctx", K(ret)); + } else { + addr = write_ctx.addr_; + } + } + + if (nullptr != buf) { + allocator.free(buf); + } + + return ret; +} + +int TestMdsDataReadWrite::mock_empty_tablet_status_disk_addr( + common::ObArenaAllocator &allocator, + ObMetaDiskAddr &addr) +{ + int ret = OB_SUCCESS; + ObTenantCheckpointSlogHandler *ckpt_slog_handler = MTL(ObTenantCheckpointSlogHandler*); + mds::MdsDumpKV kv; + const int64_t size = kv.get_serialize_size(); + int64_t pos = 0; + + char *buf = static_cast(allocator.alloc(size)); + if (OB_ISNULL(buf)) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_WARN("failed to alloc memory", K(ret), K(size)); + } else if (OB_FAIL(kv.serialize(buf, size, pos))) { + LOG_WARN("failed to serialize", K(ret)); + } else { + ObSharedBlockWriteInfo write_info; + write_info.buffer_ = buf; + write_info.offset_ = 0; + write_info.size_ = size; + write_info.io_desc_.set_wait_event(ObWaitEventIds::DB_FILE_COMPACT_WRITE); + + ObSharedBlockWriteHandle handle; + ObSharedBlocksWriteCtx write_ctx; + if (OB_FAIL(ckpt_slog_handler->get_shared_block_reader_writer().async_write(write_info, handle))) { + LOG_WARN("failed to do async write", K(ret)); + } else if (OB_FAIL(handle.get_write_ctx(write_ctx))) { + LOG_WARN("failed to get write ctx", K(ret)); + } else { + addr = write_ctx.addr_; + } + } + + if (nullptr != buf) { + allocator.free(buf); + } + + return ret; +} + +int TestMdsDataReadWrite::mock_auto_inc_seq_disk_addr( + common::ObArenaAllocator &allocator, + ObMetaDiskAddr &addr) +{ + int ret = OB_SUCCESS; + ObTenantCheckpointSlogHandler *ckpt_slog_handler = MTL(ObTenantCheckpointSlogHandler*); + share::ObTabletAutoincSeq auto_inc_seq; + + { + if (OB_FAIL(auto_inc_seq.set_autoinc_seq_value(allocator, 100))) { + LOG_WARN("failed to set auto inc seq", K(ret)); + } + } + + const int64_t size = auto_inc_seq.get_serialize_size(); + int64_t pos = 0; + + char *buf = static_cast(allocator.alloc(size)); + if (OB_FAIL(ret)) { + } else if (OB_ISNULL(buf)) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_WARN("failed to alloc memory", K(ret), K(size)); + } else if (OB_FAIL(auto_inc_seq.serialize(buf, size, pos))) { + LOG_WARN("failed to serialize", K(ret)); + } else { + ObSharedBlockWriteInfo write_info; + write_info.buffer_ = buf; + write_info.offset_ = 0; + write_info.size_ = size; + write_info.io_desc_.set_wait_event(ObWaitEventIds::DB_FILE_COMPACT_WRITE); + + ObSharedBlockWriteHandle handle; + ObSharedBlocksWriteCtx write_ctx; + if (OB_FAIL(ckpt_slog_handler->get_shared_block_reader_writer().async_write(write_info, handle))) { + LOG_WARN("failed to do async write", K(ret)); + } else if (OB_FAIL(handle.get_write_ctx(write_ctx))) { + LOG_WARN("failed to get write ctx", K(ret)); + } else { + addr = write_ctx.addr_; + } + } + + if (nullptr != buf) { + allocator.free(buf); + } + + return ret; +} + +int TestMdsDataReadWrite::mock_empty_auto_inc_seq_disk_addr( + common::ObArenaAllocator &allocator, + ObMetaDiskAddr &addr) +{ + int ret = OB_SUCCESS; + ObTenantCheckpointSlogHandler *ckpt_slog_handler = MTL(ObTenantCheckpointSlogHandler*); + share::ObTabletAutoincSeq auto_inc_seq; + const int64_t size = auto_inc_seq.get_serialize_size(); + int64_t pos = 0; + + char *buf = static_cast(allocator.alloc(size)); + if (OB_ISNULL(buf)) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_WARN("failed to alloc memory", K(ret), K(size)); + } else if (OB_FAIL(auto_inc_seq.serialize(buf, size, pos))) { + LOG_WARN("failed to serialize", K(ret)); + } else { + ObSharedBlockWriteInfo write_info; + write_info.buffer_ = buf; + write_info.offset_ = 0; + write_info.size_ = size; + write_info.io_desc_.set_wait_event(ObWaitEventIds::DB_FILE_COMPACT_WRITE); + + ObSharedBlockWriteHandle handle; + ObSharedBlocksWriteCtx write_ctx; + if (OB_FAIL(ckpt_slog_handler->get_shared_block_reader_writer().async_write(write_info, handle))) { + LOG_WARN("failed to do async write", K(ret)); + } else if (OB_FAIL(handle.get_write_ctx(write_ctx))) { + LOG_WARN("failed to get write ctx", K(ret)); + } else { + addr = write_ctx.addr_; + } + } + + if (nullptr != buf) { + allocator.free(buf); + } + + return ret; +} + +TEST_F(TestMdsDataReadWrite, mds_dump_kv) +{ + int ret = OB_SUCCESS; + common::ObArenaAllocator allocator; + ObTabletComplexAddr src_addr; + ObTabletComplexAddr dst_addr; + + { + ret = ObTabletMdsData::init_single_complex_addr(allocator, src_addr, dst_addr); + ASSERT_EQ(OB_INVALID_ARGUMENT, ret); + } + + { + src_addr.reset(); + dst_addr.reset(); + ret = ObTabletObjLoadHelper::alloc_and_new(allocator, src_addr.ptr_); + ASSERT_EQ(OB_SUCCESS, ret); + src_addr.addr_.set_none_addr(); + ret = ObTabletMdsData::init_single_complex_addr(allocator, src_addr, dst_addr); + ASSERT_EQ(OB_SUCCESS, ret); + ASSERT_TRUE(dst_addr.is_none_object()); + } + + { + src_addr.reset(); + dst_addr.reset(); + + ObMetaDiskAddr addr; + ret = TestMdsDataReadWrite::mock_empty_tablet_status_disk_addr(allocator, addr); + ASSERT_EQ(OB_SUCCESS, ret); + ASSERT_TRUE(addr.is_block()); + src_addr.ptr_ = nullptr; + src_addr.addr_ = addr; + ret = ObTabletMdsData::init_single_complex_addr(allocator, src_addr, dst_addr); + ASSERT_EQ(OB_SUCCESS, ret); + ASSERT_TRUE(dst_addr.is_none_object()); + } + + { + src_addr.reset(); + dst_addr.reset(); + + ObMetaDiskAddr addr; + ret = TestMdsDataReadWrite::mock_tablet_status_disk_addr(allocator, addr); + ASSERT_EQ(OB_SUCCESS, ret); + ASSERT_TRUE(addr.is_block()); + src_addr.ptr_ = nullptr; + src_addr.addr_ = addr; + ret = ObTabletMdsData::init_single_complex_addr(allocator, src_addr, dst_addr); + ASSERT_EQ(OB_SUCCESS, ret); + ASSERT_TRUE(dst_addr.is_memory_object()); + } +} + +TEST_F(TestMdsDataReadWrite, auto_inc_seq) +{ + int ret = OB_SUCCESS; + common::ObArenaAllocator allocator; + ObTabletComplexAddr src_addr; + ObTabletComplexAddr dst_addr; + + { + ret = ObTabletMdsData::init_single_complex_addr(allocator, src_addr, dst_addr); + ASSERT_EQ(OB_INVALID_ARGUMENT, ret); + } + + { + src_addr.reset(); + dst_addr.reset(); + ret = ObTabletObjLoadHelper::alloc_and_new(allocator, src_addr.ptr_); + ASSERT_EQ(OB_SUCCESS, ret); + src_addr.addr_.set_none_addr(); + ret = ObTabletMdsData::init_single_complex_addr(allocator, src_addr, dst_addr); + ASSERT_EQ(OB_SUCCESS, ret); + ASSERT_TRUE(dst_addr.is_none_object()); + } + + { + src_addr.reset(); + dst_addr.reset(); + + ObMetaDiskAddr addr; + ret = TestMdsDataReadWrite::mock_empty_auto_inc_seq_disk_addr(allocator, addr); + ASSERT_EQ(OB_SUCCESS, ret); + ASSERT_TRUE(addr.is_block()); + src_addr.ptr_ = nullptr; + src_addr.addr_ = addr; + ret = ObTabletMdsData::init_single_complex_addr(allocator, src_addr, dst_addr); + ASSERT_EQ(OB_SUCCESS, ret); + ASSERT_TRUE(dst_addr.is_none_object()); + } + + { + src_addr.reset(); + dst_addr.reset(); + + ObMetaDiskAddr addr; + ret = TestMdsDataReadWrite::mock_auto_inc_seq_disk_addr(allocator, addr); + ASSERT_EQ(OB_SUCCESS, ret); + ASSERT_TRUE(addr.is_block()); + src_addr.ptr_ = nullptr; + src_addr.addr_ = addr; + ret = ObTabletMdsData::init_single_complex_addr(allocator, src_addr, dst_addr); + ASSERT_EQ(OB_SUCCESS, ret); + ASSERT_TRUE(dst_addr.is_memory_object()); + } +} + +TEST_F(TestMdsDataReadWrite, medium_info_list) +{ + int ret = OB_SUCCESS; + common::ObArenaAllocator allocator; + ObTabletComplexAddr src_addr; + ObTabletComplexAddr dst_addr; + + { + const int64_t finish_medium_scn = 0; + ret = ObTabletMdsData::init_single_complex_addr(allocator, src_addr, 0, dst_addr); + ASSERT_EQ(OB_INVALID_ARGUMENT, ret); + } + + { + src_addr.reset(); + dst_addr.reset(); + ret = ObTabletObjLoadHelper::alloc_and_new(allocator, src_addr.ptr_); + ASSERT_EQ(OB_SUCCESS, ret); + ret = src_addr.ptr_->init_for_first_creation(allocator); + ASSERT_EQ(OB_SUCCESS, ret); + src_addr.addr_.set_none_addr(); + + const int64_t finish_medium_scn = 0; + ret = ObTabletMdsData::init_single_complex_addr(allocator, src_addr, finish_medium_scn, dst_addr); + ASSERT_EQ(OB_SUCCESS, ret); + ASSERT_TRUE(dst_addr.is_none_object()); + } + + { + src_addr.reset(); + dst_addr.reset(); + ret = ObTabletObjLoadHelper::alloc_and_new(allocator, src_addr.ptr_); + ASSERT_EQ(OB_SUCCESS, ret); + ret = src_addr.ptr_->init_for_first_creation(allocator); + ASSERT_EQ(OB_SUCCESS, ret); + src_addr.addr_.set_none_addr(); + + compaction::ObMediumCompactionInfo medium_info; + ret = MediumInfoHelper::build_medium_compaction_info(allocator, medium_info, 100); + ASSERT_EQ(OB_SUCCESS, ret); + ret = src_addr.ptr_->append(medium_info); + ASSERT_EQ(OB_SUCCESS, ret); + + int64_t finish_medium_scn = 80; + ret = ObTabletMdsData::init_single_complex_addr(allocator, src_addr, finish_medium_scn, dst_addr); + ASSERT_EQ(OB_SUCCESS, ret); + ASSERT_TRUE(dst_addr.is_memory_object()); + + finish_medium_scn = 200; + dst_addr.reset(); + ret = ObTabletMdsData::init_single_complex_addr(allocator, src_addr, finish_medium_scn, dst_addr); + ASSERT_EQ(OB_SUCCESS, ret); + ASSERT_TRUE(dst_addr.is_none_object()); + } + + { + src_addr.reset(); + dst_addr.reset(); + ret = ObTabletObjLoadHelper::alloc_and_new(allocator, src_addr.ptr_); + ASSERT_EQ(OB_SUCCESS, ret); + ret = src_addr.ptr_->init_for_first_creation(allocator); + ASSERT_EQ(OB_SUCCESS, ret); + src_addr.addr_.set_none_addr(); + + compaction::ObMediumCompactionInfo medium_info; + ret = MediumInfoHelper::build_medium_compaction_info(allocator, medium_info, 100); + ASSERT_EQ(OB_SUCCESS, ret); + ret = src_addr.ptr_->append(medium_info); + ASSERT_EQ(OB_SUCCESS, ret); + + ObTabletDumpedMediumInfo src_data; + ret = src_data.init_for_first_creation(allocator); + ASSERT_EQ(OB_SUCCESS, ret); + medium_info.medium_snapshot_ = 120; + ret = src_data.append(medium_info); + ASSERT_EQ(OB_SUCCESS, ret); + + compaction::ObExtraMediumInfo src_addr_extra_info; + src_addr_extra_info.last_medium_scn_ = 10; + compaction::ObExtraMediumInfo src_data_extra_info; + src_data_extra_info.last_medium_scn_ = 20; + compaction::ObExtraMediumInfo dst_extra_info; + + int64_t finish_medium_scn = 80; + ret = ObTabletMdsData::init_single_complex_addr_and_extra_info(allocator, src_addr, src_addr_extra_info, + src_data, src_data_extra_info, finish_medium_scn, dst_addr, dst_extra_info); + ASSERT_EQ(OB_SUCCESS, ret); + ASSERT_TRUE(dst_addr.is_memory_object()); + ASSERT_EQ(2, dst_addr.ptr_->medium_info_list_.count()); + + finish_medium_scn = 110; + ret = ObTabletMdsData::init_single_complex_addr_and_extra_info(allocator, src_addr, src_addr_extra_info, + src_data, src_data_extra_info, finish_medium_scn, dst_addr, dst_extra_info); + ASSERT_EQ(OB_SUCCESS, ret); + ASSERT_TRUE(dst_addr.is_memory_object()); + ASSERT_EQ(1, dst_addr.ptr_->medium_info_list_.count()); + + finish_medium_scn = 130; + ret = ObTabletMdsData::init_single_complex_addr_and_extra_info(allocator, src_addr, src_addr_extra_info, + src_data, src_data_extra_info, finish_medium_scn, dst_addr, dst_extra_info); + ASSERT_EQ(OB_SUCCESS, ret); + ASSERT_TRUE(dst_addr.is_none_object()); + } +} +} // namespace storage +} // namespace oceanbase + +int main(int argc, char **argv) +{ + system("rm -f test_mds_data_read_write.log*"); + oceanbase::common::ObLogger::get_logger().set_log_level("INFO"); + OB_LOGGER.set_file_name("test_mds_data_read_write.log", true); + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/mittest/mtlenv/storage/test_medium_info_reader.cpp b/mittest/mtlenv/storage/test_medium_info_reader.cpp index 78f16b469..2f2aa3c4f 100644 --- a/mittest/mtlenv/storage/test_medium_info_reader.cpp +++ b/mittest/mtlenv/storage/test_medium_info_reader.cpp @@ -351,7 +351,13 @@ TEST_F(TestMediumInfoReader, pure_dump_data) // insert data into tablet { - ObTabletDumpedMediumInfo &medium_info_list = *tablet->mds_data_.medium_info_list_.ptr_; + common::ObIAllocator &allocator = *tablet_handle.get_allocator(); + ObTabletComplexAddr &medium_info_list_complex_addr = tablet->mds_data_.medium_info_list_; + ret = ObTabletObjLoadHelper::alloc_and_new(allocator, medium_info_list_complex_addr.ptr_); + ASSERT_EQ(OB_SUCCESS, ret); + ret = medium_info_list_complex_addr.ptr_->init_for_first_creation(allocator); + ASSERT_EQ(OB_SUCCESS, ret); + ObTabletDumpedMediumInfo &medium_info_list = *medium_info_list_complex_addr.ptr_; constexpr uint8_t table_id = mds::TupleTypeIdx::value; constexpr uint8_t unit_id = mds::TupleTypeIdx>::value; @@ -417,7 +423,13 @@ TEST_F(TestMediumInfoReader, mds_table_dump_data_overlap) // insert data into mds data { - ObTabletDumpedMediumInfo &medium_info_list = *tablet->mds_data_.medium_info_list_.ptr_; + common::ObIAllocator &allocator = *tablet_handle.get_allocator(); + ObTabletComplexAddr &medium_info_list_complex_addr = tablet->mds_data_.medium_info_list_; + ret = ObTabletObjLoadHelper::alloc_and_new(allocator, medium_info_list_complex_addr.ptr_); + ASSERT_EQ(OB_SUCCESS, ret); + ret = medium_info_list_complex_addr.ptr_->init_for_first_creation(allocator); + ASSERT_EQ(OB_SUCCESS, ret); + ObTabletDumpedMediumInfo &medium_info_list = *medium_info_list_complex_addr.ptr_; constexpr uint8_t table_id = mds::TupleTypeIdx::value; constexpr uint8_t unit_id = mds::TupleTypeIdx>::value; @@ -529,7 +541,13 @@ TEST_F(TestMediumInfoReader, mds_table_dump_data_no_overlap) // insert data into mds data { - ObTabletDumpedMediumInfo &medium_info_list = *tablet->mds_data_.medium_info_list_.ptr_; + common::ObIAllocator &allocator = *tablet_handle.get_allocator(); + ObTabletComplexAddr &medium_info_list_complex_addr = tablet->mds_data_.medium_info_list_; + ret = ObTabletObjLoadHelper::alloc_and_new(allocator, medium_info_list_complex_addr.ptr_); + ASSERT_EQ(OB_SUCCESS, ret); + ret = medium_info_list_complex_addr.ptr_->init_for_first_creation(allocator); + ASSERT_EQ(OB_SUCCESS, ret); + ObTabletDumpedMediumInfo &medium_info_list = *medium_info_list_complex_addr.ptr_; constexpr uint8_t table_id = mds::TupleTypeIdx::value; constexpr uint8_t unit_id = mds::TupleTypeIdx>::value; @@ -631,7 +649,13 @@ TEST_F(TestMediumInfoReader, mds_table_dump_data_full_inclusion) // insert data into mds data { - ObTabletDumpedMediumInfo &medium_info_list = *tablet->mds_data_.medium_info_list_.ptr_; + common::ObIAllocator &allocator = *tablet_handle.get_allocator(); + ObTabletComplexAddr &medium_info_list_complex_addr = tablet->mds_data_.medium_info_list_; + ret = ObTabletObjLoadHelper::alloc_and_new(allocator, medium_info_list_complex_addr.ptr_); + ASSERT_EQ(OB_SUCCESS, ret); + ret = medium_info_list_complex_addr.ptr_->init_for_first_creation(allocator); + ASSERT_EQ(OB_SUCCESS, ret); + ObTabletDumpedMediumInfo &medium_info_list = *medium_info_list_complex_addr.ptr_; constexpr uint8_t table_id = mds::TupleTypeIdx::value; constexpr uint8_t unit_id = mds::TupleTypeIdx>::value; diff --git a/src/storage/blockstore/ob_shared_block_reader_writer.cpp b/src/storage/blockstore/ob_shared_block_reader_writer.cpp index f9ea8a0c5..f73261c78 100644 --- a/src/storage/blockstore/ob_shared_block_reader_writer.cpp +++ b/src/storage/blockstore/ob_shared_block_reader_writer.cpp @@ -17,6 +17,7 @@ namespace oceanbase { using namespace blocksstable; +using namespace common; namespace storage { diff --git a/src/storage/blockstore/ob_shared_block_reader_writer.h b/src/storage/blockstore/ob_shared_block_reader_writer.h index 124da687a..57dcb4027 100644 --- a/src/storage/blockstore/ob_shared_block_reader_writer.h +++ b/src/storage/blockstore/ob_shared_block_reader_writer.h @@ -239,7 +239,7 @@ public: const ObSharedBlockWriteInfo &write_info, ObSharedBlockWriteHandle &block_handle); int async_batch_write( - const ObIArray &write_infos, + const common::ObIArray &write_infos, ObSharedBlockBatchHandle &block_handle); int async_link_write( const ObSharedBlockWriteInfo &write_infos, diff --git a/src/storage/compaction/ob_medium_compaction_mgr.cpp b/src/storage/compaction/ob_medium_compaction_mgr.cpp index a4e2fb1ad..0968505ee 100644 --- a/src/storage/compaction/ob_medium_compaction_mgr.cpp +++ b/src/storage/compaction/ob_medium_compaction_mgr.cpp @@ -18,7 +18,8 @@ #include "logservice/ob_log_base_header.h" #include "storage/multi_data_source/mds_ctx.h" #include "storage/multi_data_source/mds_writer.h" -#include "src/storage/tx/ob_trans_define.h" +#include "storage/tx/ob_trans_define.h" +#include "storage/tablet/ob_tablet_obj_load_helper.h" #include "storage/tablet/ob_tablet_service_clog_replay_executor.h" namespace oceanbase @@ -448,7 +449,7 @@ int ObMediumCompactionInfoList::init( int ObMediumCompactionInfoList::init( common::ObIAllocator &allocator, const ObExtraMediumInfo &extra_medium_info, - const ObTabletDumpedMediumInfo &medium_info_list) + const ObTabletDumpedMediumInfo *medium_info_list) { int ret = OB_SUCCESS; @@ -457,32 +458,30 @@ int ObMediumCompactionInfoList::init( LOG_WARN("init twice", K(ret)); } else { allocator_ = &allocator; - const common::ObIArray &array = medium_info_list.medium_info_list_; - for (int64_t i = 0; OB_SUCC(ret) && i < array.count(); ++i) { - const ObMediumCompactionInfo *src_medium_info = array.at(i); - if (OB_ISNULL(src_medium_info)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected error, medium info is null", K(ret), K(i), KP(src_medium_info)); - } else { - ObMediumCompactionInfo *medium_info = nullptr; - void *buffer = allocator.alloc(sizeof(ObMediumCompactionInfo)); - if (OB_ISNULL(buffer)) { - ret = OB_ALLOCATE_MEMORY_FAILED; - LOG_WARN("failed to allocate memory", K(ret), "size", sizeof(ObMediumCompactionInfo)); - } else { - medium_info = new (buffer) ObMediumCompactionInfo(); - if (OB_FAIL(medium_info->init(allocator, *src_medium_info))) { - LOG_WARN("failed to copy medium info", K(ret), KPC(src_medium_info)); - } else if (OB_UNLIKELY(!medium_info_list_.add_last(medium_info))) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("failed to add last", K(ret), KPC(medium_info)); - } + if (nullptr == medium_info_list) { + // medium info is null, no need to copy + } else { + const common::ObIArray &array = medium_info_list->medium_info_list_; + ObMediumCompactionInfo *medium_info = nullptr; + for (int64_t i = 0; OB_SUCC(ret) && i < array.count(); ++i) { + medium_info = nullptr; + const ObMediumCompactionInfo *src_medium_info = array.at(i); + if (OB_ISNULL(src_medium_info)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected error, medium info is null", K(ret), K(i), KP(src_medium_info)); + } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, medium_info))) { + LOG_WARN("failed to alloc and new", K(ret)); + } else if (OB_FAIL(medium_info->init(allocator, *src_medium_info))) { + LOG_WARN("failed to copy medium info", K(ret), KPC(src_medium_info)); + } else if (OB_UNLIKELY(!medium_info_list_.add_last(medium_info))) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("failed to add last", K(ret), KPC(medium_info)); + } - if (OB_FAIL(ret)) { - if (OB_NOT_NULL(medium_info)) { - medium_info->~ObMediumCompactionInfo(); - allocator.free(medium_info); - } + if (OB_FAIL(ret)) { + if (OB_NOT_NULL(medium_info)) { + medium_info->~ObMediumCompactionInfo(); + allocator.free(medium_info); } } } diff --git a/src/storage/compaction/ob_medium_compaction_mgr.h b/src/storage/compaction/ob_medium_compaction_mgr.h index 6ed2d5549..c78b7d7a8 100644 --- a/src/storage/compaction/ob_medium_compaction_mgr.h +++ b/src/storage/compaction/ob_medium_compaction_mgr.h @@ -101,7 +101,8 @@ public: int init( common::ObIAllocator &allocator, const ObExtraMediumInfo &extra_medium_info, - const ObTabletDumpedMediumInfo &medium_info_list); + const ObTabletDumpedMediumInfo *medium_info_list); + void reset(); OB_INLINE bool is_empty() const { return 0 == medium_info_list_.get_size(); } OB_INLINE int64_t size() const { return medium_info_list_.get_size(); } diff --git a/src/storage/tablet/ob_i_tablet_mds_interface.h b/src/storage/tablet/ob_i_tablet_mds_interface.h index b121b6808..93d22a405 100644 --- a/src/storage/tablet/ob_i_tablet_mds_interface.h +++ b/src/storage/tablet/ob_i_tablet_mds_interface.h @@ -71,7 +71,6 @@ protected:// implemented by ObTablet virtual int get_mds_table_handle_(mds::MdsTableHandle &handle, const bool create_if_not_exist) const = 0; virtual ObTabletPointer *get_tablet_ponter_() const = 0; - virtual int fetch_autoinc_seq(ObTabletMemberWrapper &wrapper) const = 0; template int get_mds_data_from_tablet(const common::ObFunction &read_op) const; diff --git a/src/storage/tablet/ob_i_tablet_mds_interface.ipp b/src/storage/tablet/ob_i_tablet_mds_interface.ipp index b833a3f04..7548ed231 100644 --- a/src/storage/tablet/ob_i_tablet_mds_interface.ipp +++ b/src/storage/tablet/ob_i_tablet_mds_interface.ipp @@ -183,9 +183,8 @@ inline int ObITabletMdsInterface::get_mds_data_from_tabletv_.user_data_; int64_t pos = 0; @@ -224,9 +223,8 @@ inline int ObITabletMdsInterface::get_mds_data_from_tabletv_.user_data_; int64_t pos = 0; @@ -261,16 +259,18 @@ inline int ObITabletMdsInterface::get_mds_data_from_tablet &auto_inc_seq_addr = get_mds_data_().auto_inc_seq_; const share::ObTabletAutoincSeq *auto_inc_seq = nullptr; - ObTabletMemberWrapper wrapper; + ObArenaAllocator allocator("mds_reader"); - if (CLICK_FAIL(ObTabletMdsData::fetch_auto_inc_seq(auto_inc_seq_addr, wrapper))) { - MDS_LOG_GET(WARN, "failed to fetch auto inc seq"); - } else if (CLICK_FAIL(wrapper.get_member(auto_inc_seq))) { - MDS_LOG_GET(WARN, "failed to get member"); + if (CLICK_FAIL(ObTabletMdsData::load_auto_inc_seq(allocator, auto_inc_seq_addr, auto_inc_seq))) { + MDS_LOG_GET(WARN, "failed to load auto inc seq"); + } else if (nullptr == auto_inc_seq) { + ret = OB_EMPTY_RESULT; } else if (CLICK_FAIL(read_op(*auto_inc_seq))) { MDS_LOG_GET(WARN, "failed to read_op"); } + ObTabletMdsData::free_auto_inc_seq(allocator, auto_inc_seq); + return ret; #undef PRINT_WRAPPER } @@ -680,17 +680,14 @@ int ObITabletMdsInterface::fill_virtual_info_by_complex_addr_(const ObTabletComp const mds::MdsDumpKV *dump_kv = nullptr; if (CLICK_FAIL(mds_node_info_array.push_back(mds::MdsNodeInfoForVirtualTable()))) { - MDS_LOG_GET(WARN, "fatil to push_back"); + MDS_LOG_GET(WARN, "fail to push_back"); } else if (FALSE_IT(cur_virtual_info = &mds_node_info_array.at(mds_node_info_array.count() - 1))) { } else { if (CLICK_FAIL(ObTabletMdsData::load_mds_dump_kv(allocator, addr, dump_kv))) { MDS_LOG_GET(WARN, "fatil to read tablet_status_addr"); - } else if (!dump_kv->is_valid()) { + } else if (nullptr == dump_kv || (nullptr != dump_kv && !dump_kv->is_valid())) { ret = OB_ENTRY_NOT_EXIST; MDS_LOG_GET(INFO, "dump kv not exist"); - if (OB_NOT_NULL(dump_kv)) { - MDS_LOG_GET(INFO, "xuwang.txw debug", K(dump_kv->k_), K(dump_kv->v_)); - } } else if (CLICK_FAIL(obj_to_string_holder_(dump_kv->k_, cur_virtual_info->user_key_))) { MDS_LOG_GET(WARN, "fatil to fill string holder"); } else if (CLICK_FAIL(dump_kv->v_.convert_to_user_mds_node(user_mds_node, get_tablet_meta_().ls_id_, get_tablet_meta_().tablet_id_))) { diff --git a/src/storage/tablet/ob_tablet.cpp b/src/storage/tablet/ob_tablet.cpp index 089636e53..d59301eca 100755 --- a/src/storage/tablet/ob_tablet.cpp +++ b/src/storage/tablet/ob_tablet.cpp @@ -239,24 +239,24 @@ int ObTablet::init_for_first_time_creation( ALLOC_AND_INIT(allocator, storage_schema_addr_, table_schema, compat_mode, true/*skip_column_info*/, ObStorageSchema::STORAGE_SCHEMA_VERSION_V2); } - if (OB_SUCC(ret)) { - if (OB_FAIL(check_sstable_column_checksum())) { - LOG_WARN("failed to check sstable column checksum", K(ret), KPC(this)); - } else if (OB_FAIL(build_read_info(allocator))) { - LOG_WARN("failed to build read info", K(ret)); - } else if (OB_FAIL(mds_data_.init(allocator))) { - LOG_WARN("failed to init mds data", K(ret)); - } else if (is_ls_inner_tablet() && - OB_FAIL(mds_data_.set_tablet_status(allocator_, ObTabletStatus::Status::NORMAL, ObTabletMdsUserDataType::CREATE_TABLET))) { - LOG_WARN("failed to set normal status for ls inner tablet", K(ret)); - } else if (FALSE_IT(set_mem_addr())) { - } else if (OB_FAIL(inner_inc_macro_ref_cnt())) { - LOG_WARN("failed to increase macro ref cnt", K(ret)); - } else { - is_inited_ = true; - LOG_INFO("succeeded to init tablet for first time creation", K(ret), KPC(sstable), K(*this)); - } + + if (OB_FAIL(ret)) { + } else if (OB_FAIL(check_sstable_column_checksum())) { + LOG_WARN("failed to check sstable column checksum", K(ret), KPC(this)); + } else if (OB_FAIL(build_read_info(allocator))) { + LOG_WARN("failed to build read info", K(ret)); + } else if (!is_ls_inner_tablet() && OB_FAIL(mds_data_.init_for_first_creation(allocator))) { + LOG_WARN("failed to init mds data", K(ret)); + } else if (is_ls_inner_tablet() && OB_FAIL(mds_data_.init_with_tablet_status(allocator, ObTabletStatus::NORMAL, ObTabletMdsUserDataType::CREATE_TABLET))) { + LOG_WARN("failed to init mds data for ls inner tablet", K(ret)); + } else if (FALSE_IT(set_mem_addr())) { + } else if (OB_FAIL(inner_inc_macro_ref_cnt())) { + LOG_WARN("failed to increase macro ref cnt", K(ret)); + } else { + is_inited_ = true; + LOG_INFO("succeeded to init tablet for first time creation", K(ret), KPC(sstable), K(*this)); } + if (OB_UNLIKELY(!is_inited_)) { reset(); } @@ -331,7 +331,7 @@ int ObTablet::init_for_merge( LOG_WARN("failed to update table store flag", K(ret), K(param), K(table_store_addr_)); } else if (OB_FAIL(get_finish_medium_scn(finish_medium_scn))) { LOG_WARN("failed to get finish medium scn", K(ret)); - } else if (OB_FAIL(mds_data_.init(allocator, old_mds_data, finish_medium_scn, param.merge_type_))) { + } else if (OB_FAIL(mds_data_.init_for_evict_medium_info(allocator, old_mds_data, finish_medium_scn, param.merge_type_))) { LOG_WARN("failed to init mds data", K(ret), K(old_mds_data), K(finish_medium_scn), "merge_type", param.merge_type_); } else if (OB_FAIL(build_read_info(allocator))) { LOG_WARN("failed to build read info", K(ret)); @@ -412,7 +412,7 @@ int ObTablet::init_for_mds_table_dump( LOG_WARN("fail to init table store", K(ret), KPC(old_table_store)); } else if (CLICK_FAIL(get_finish_medium_scn(finish_medium_scn))) { LOG_WARN("failed to get finish medium scn", K(ret)); - } else if (CLICK_FAIL(mds_data_.init(allocator, mds_table_data, base_data, finish_medium_scn))) { + } else if (CLICK_FAIL(mds_data_.init_for_mds_table_dump(allocator, mds_table_data, base_data, finish_medium_scn))) { LOG_WARN("failed to init mds data", K(ret), K(finish_medium_scn)); } else { ddl_kvs_ = ddl_kvs_addr; @@ -496,7 +496,7 @@ int ObTablet::init_with_migrate_param( LOG_INFO("succeeded to init empty shell tablet", K(ret), K(param), KPC(this)); } } else { - if (OB_FAIL(mds_data_.init(*allocator_, param.mds_data_))) { + if (OB_FAIL(mds_data_.init_by_full_memory_mds_data(*allocator_, param.mds_data_))) { LOG_WARN("failed to assign mds data", K(ret), K(param)); } else if (OB_FAIL(pull_memtables(allocator, ddl_kvs_addr, ddl_kv_count))) { LOG_WARN("fail to pull memtable", K(ret)); @@ -580,7 +580,7 @@ int ObTablet::init_for_defragment( } if (OB_FAIL(ret)) { - } else if (OB_FAIL(mds_data_.init(allocator, old_mds_data, 0/*finish_medium_scn*/))) { + } else if (OB_FAIL(mds_data_.init_for_evict_medium_info(allocator, old_mds_data, 0/*finish_medium_scn*/))) { LOG_WARN("failed to init mds data", K(ret), K(old_mds_data)); } else if (OB_FAIL(build_read_info(*allocator_))) { LOG_WARN("fail to build read info", K(ret)); @@ -663,10 +663,10 @@ int ObTablet::init_for_sstable_replace( } else if (OB_FAIL(get_finish_medium_scn(finish_medium_scn))) { LOG_WARN("failed to get finish medium scn", K(ret)); } else if (nullptr != param.tablet_meta_ - && OB_FAIL(mds_data_.init(allocator, old_tablet.mds_data_, param.tablet_meta_->mds_data_.medium_info_list_, finish_medium_scn))) { + && OB_FAIL(mds_data_.init_for_merge_with_full_mds_data(allocator, old_tablet.mds_data_, param.tablet_meta_->mds_data_.medium_info_list_, finish_medium_scn))) { LOG_WARN("failed to init mds data", K(ret), "mds_data", param.tablet_meta_->mds_data_, K(finish_medium_scn)); } else if (nullptr == param.tablet_meta_ - && OB_FAIL(mds_data_.init(allocator, old_tablet.mds_data_, finish_medium_scn))) { + && OB_FAIL(mds_data_.init_for_evict_medium_info(allocator, old_tablet.mds_data_, finish_medium_scn))) { LOG_WARN("failed to init mds data", K(ret), "mds_data", old_tablet.mds_data_, K(finish_medium_scn)); } else if (OB_FAIL(build_read_info(*allocator_))) { LOG_WARN("failed to build read info", K(ret)); @@ -835,7 +835,7 @@ int ObTablet::read_medium_info_list( if (OB_UNLIKELY(!is_inited_)) { ret = OB_NOT_INIT; LOG_WARN("not inited", K(ret), K_(is_inited)); - } else if (OB_FAIL(fused_medium_info_list.init(allocator))) { + } else if (OB_FAIL(fused_medium_info_list.init_for_first_creation(allocator))) { LOG_WARN("failed to init medium info list", K(ret)); } else if (OB_FAIL(get_finish_medium_scn(finish_medium_scn))) { LOG_WARN("failed to get finish medium scn", K(ret)); @@ -850,7 +850,8 @@ int ObTablet::read_medium_info_list( if (OB_FAIL(ret)) { } else if (OB_FAIL(ObTabletMdsData::load_medium_info_list(allocator, complex_addr, base_medium_info_list))) { LOG_WARN("failed to load medium info list", K(ret)); - } else if (OB_FAIL(ObTabletMdsData::copy_medium_info_list(finish_medium_scn, *base_medium_info_list, fused_medium_info_list))) { + } else if (nullptr != base_medium_info_list + && OB_FAIL(ObTabletMdsData::copy_medium_info_list(finish_medium_scn, *base_medium_info_list, fused_medium_info_list))) { LOG_WARN("failed to copy base medium info list", K(ret)); } else if (OB_FAIL(ObTabletMdsData::copy_medium_info_list(finish_medium_scn, mds_table_medium_info_list, fused_medium_info_list))) { LOG_WARN("failed to copy mds table medium info list", K(ret)); @@ -858,7 +859,7 @@ int ObTablet::read_medium_info_list( compaction::ObMediumCompactionInfoList *tmp_list = nullptr; if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, tmp_list))) { LOG_WARN("failed to alloc and new", K(ret)); - } else if (OB_FAIL(tmp_list->init(allocator, mds_data_.extra_medium_info_, fused_medium_info_list))) { + } else if (OB_FAIL(tmp_list->init(allocator, mds_data_.extra_medium_info_, &fused_medium_info_list))) { LOG_WARN("failed to init", K(ret)); } else { medium_info_list = tmp_list; @@ -1994,6 +1995,9 @@ void ObTablet::set_mem_addr() int ObTablet::check_meta_addr() const { int ret = OB_SUCCESS; + const share::ObLSID &ls_id = tablet_meta_.ls_id_; + const common::ObTabletID &tablet_id = tablet_meta_.tablet_id_; + const ObTabletComplexAddr &tablet_status_uncommitted_kv_addr = mds_data_.tablet_status_.uncommitted_kv_; const ObTabletComplexAddr &tablet_status_committed_kv_addr = mds_data_.tablet_status_.committed_kv_; const ObTabletComplexAddr &aux_tablet_info_uncommitted_kv_addr = mds_data_.aux_tablet_info_.uncommitted_kv_; @@ -2008,7 +2012,7 @@ int ObTablet::check_meta_addr() const || !aux_tablet_info_committed_kv_addr.is_valid())) { ret = OB_ERR_UNEXPECTED; - LOG_WARN("meta addrs are invalid", K(ret), K(tablet_addr_), K(table_store_addr_.addr_), + LOG_WARN("meta addrs are invalid", K(ret), K(ls_id), K(tablet_id), K(tablet_addr_), K(table_store_addr_.addr_), K(auto_inc_seq_addr.addr_), K(storage_schema_addr_.addr_), K(medium_info_list_addr.addr_), K(tablet_status_uncommitted_kv_addr.addr_), K(tablet_status_committed_kv_addr.addr_), K(aux_tablet_info_uncommitted_kv_addr.addr_), K(aux_tablet_info_committed_kv_addr.addr_)); @@ -2017,8 +2021,8 @@ int ObTablet::check_meta_addr() const && ((tablet_addr_.is_block() ^ table_store_addr_.addr_.is_none()) || (tablet_addr_.is_block() ^ storage_schema_addr_.addr_.is_none()))) { ret = OB_ERR_UNEXPECTED; - LOG_WARN("meta addrs are inconsistent", - K(ret), K(tablet_addr_), K(table_store_addr_.addr_), K(storage_schema_addr_.addr_)); + LOG_WARN("meta addrs are inconsistent", K(ret), K(ls_id), K(tablet_id), + K(tablet_addr_), K(table_store_addr_.addr_), K(storage_schema_addr_.addr_)); } return ret; @@ -4762,6 +4766,8 @@ int ObTablet::check_and_set_initial_state() int ObTablet::check_medium_list() const { int ret = OB_SUCCESS; + const share::ObLSID &ls_id = tablet_meta_.ls_id_; + const common::ObTabletID &tablet_id = tablet_meta_.tablet_id_; if (tablet_meta_.ha_status_.is_none()) { ObTabletMemberWrapper table_store_wrapper; ObITable *last_major = nullptr; @@ -4771,21 +4777,20 @@ int ObTablet::check_medium_list() const ObArenaAllocator arena_allocator("check_medium", OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID()); const ObTabletDumpedMediumInfo *dumped_list = nullptr; if (OB_FAIL(ObTabletMdsData::load_medium_info_list(arena_allocator, mds_data_.medium_info_list_, dumped_list))) { - LOG_WARN("failed to load medium info list", K(ret), K(mds_data_)); - } else if (OB_ISNULL(dumped_list)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected error, list is null", K(ret), KP(dumped_list)); + LOG_WARN("failed to load medium info list", K(ret), K(ls_id), K(tablet_id), K(mds_data_)); + } else if (nullptr == dumped_list) { + // do nothing + LOG_INFO("skip check medium list for empty dumped medium info list", KR(ret), K(ls_id), K(tablet_id)); } else if (OB_FAIL(ObMediumListChecker::validate_medium_info_list( mds_data_.extra_medium_info_, dumped_list->medium_info_list_, last_major->get_snapshot_version()))) { - LOG_WARN("fail to validate medium info list", K(ret), K(mds_data_), KPC(dumped_list), KPC(last_major)); + LOG_WARN("fail to validate medium info list", K(ret), K(ls_id), K(tablet_id), K(mds_data_), KPC(dumped_list), KPC(last_major)); } ObTabletMdsData::free_medium_info_list(arena_allocator, dumped_list); } } else { - LOG_INFO("skip check medium list for non empty ha_status", KR(ret), - "tablet_id", tablet_meta_.tablet_id_, K(tablet_meta_.ha_status_)); + LOG_INFO("skip check medium list for non empty ha_status", KR(ret), K(ls_id), K(tablet_id), "ha_status", tablet_meta_.ha_status_); } return ret; } @@ -4979,7 +4984,7 @@ int ObTablet::build_transfer_tablet_param( if (OB_FAIL(ret)) { } else if (OB_FAIL(get_finish_medium_scn(finish_medium_scn))) { LOG_WARN("failed to get finish medium scn", K(ret)); - } else if (OB_FAIL(new_mds_data.init(mig_tablet_param.allocator_, mds_table_data, mds_data_, finish_medium_scn))) { + } else if (OB_FAIL(new_mds_data.init_for_mds_table_dump(mig_tablet_param.allocator_, mds_table_data, mds_data_, finish_medium_scn))) { LOG_WARN("failed to init new mds data", K(ret), K(finish_medium_scn)); } else if (OB_FAIL(build_transfer_in_tablet_status_(user_data, new_mds_data, mig_tablet_param.allocator_))) { LOG_WARN("failed to build transfer in tablet status", K(new_mds_data), K(mds_data_), KPC(this)); @@ -5149,11 +5154,17 @@ int ObTablet::build_transfer_in_tablet_status_( } else if (OB_FAIL(new_user_data.serialize(buffer, length, pos))) { LOG_WARN("failed to serialize user data", K(ret)); } else { - mds::MdsDumpKV *uncommitted_kv = mds_data.tablet_status_.uncommitted_kv_.ptr_; + mds::MdsDumpKV *&uncommitted_kv = mds_data.tablet_status_.uncommitted_kv_.ptr_; const mds::MdsDumpKV *committed_kv = mds_data.tablet_status_.committed_kv_.ptr_; - if (OB_ISNULL(uncommitted_kv) || OB_ISNULL(committed_kv)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("dump kv is null", K(ret), KP(uncommitted_kv), KP(committed_kv)); + if (nullptr == uncommitted_kv) { + if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, uncommitted_kv))) { + LOG_WARN("failed to alloc and new", K(ret)); + } + } + + if (OB_FAIL(ret)) { + } else if (nullptr == committed_kv) { + // do nothing, no need to copy } else if (OB_FAIL(uncommitted_kv->assign(*committed_kv, allocator))) { LOG_WARN("failed to copy committed kv to uncommitted kv", K(ret)); } else { @@ -5255,7 +5266,7 @@ int ObTablet::read_mds_table(common::ObIAllocator &allocator, if (OB_UNLIKELY(!is_inited_)) { ret = OB_NOT_INIT; LOG_WARN("not inited", K(ret), K_(is_inited)); - } else if (CLICK_FAIL(mds_data.init(allocator))) { + } else if (CLICK_FAIL(mds_data.init_for_first_creation(allocator))) { LOG_WARN("failed to init mds data", K(ret)); } else if (CLICK_FAIL(inner_get_mds_table(mds_table_handle))) { if (OB_ENTRY_NOT_EXIST == ret) { @@ -5288,7 +5299,7 @@ int ObTablet::read_mds_table_medium_info_list( medium_info_list.reset(); mds::MdsTableHandle mds_table_handle; - if (CLICK_FAIL(medium_info_list.init(allocator))) { + if (CLICK_FAIL(medium_info_list.init_for_first_creation(allocator))) { LOG_WARN("failed to init medium info list", K(ret)); } else if (CLICK_FAIL(inner_get_mds_table(mds_table_handle))) { if (OB_ENTRY_NOT_EXIST == ret) { @@ -5668,10 +5679,7 @@ int ObTablet::load_medium_info_list( if (OB_FAIL(ObTabletMdsData::load_medium_info_list(allocator, complex_addr, list))) { LOG_WARN("failed to load medium info list", K(ret), K(complex_addr)); - } else if (OB_ISNULL(list)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected error, list is null", K(ret), KP(list)); - } else if (OB_FAIL(medium_info_list.init(allocator, extra_info, *list))) { + } else if (OB_FAIL(medium_info_list.init(allocator, extra_info, list))) { LOG_WARN("failed to init", K(ret)); } @@ -5704,7 +5712,7 @@ int ObTablet::get_fused_medium_info_list( if (OB_FAIL(ret)) { } else if (OB_FAIL(get_finish_medium_scn(finish_medium_scn))) { LOG_WARN("failed to get finish medium scn", K(ret)); - } else if (OB_FAIL(new_mds_data.init(allocator, mds_table_data, mds_data_, finish_medium_scn))) { + } else if (OB_FAIL(new_mds_data.init_for_mds_table_dump(allocator, mds_table_data, mds_data_, finish_medium_scn))) { LOG_WARN("failed to init new mds data", K(ret), K(finish_medium_scn)); } else if (OB_FAIL(validate_medium_info_list(finish_medium_scn, new_mds_data))) { LOG_WARN("failed to validate medium info list", K(ret), K(finish_medium_scn)); @@ -5724,9 +5732,11 @@ int ObTablet::validate_medium_info_list( const ObTabletDumpedMediumInfo *medium_info_list = mds_data.medium_info_list_.ptr_; const ObExtraMediumInfo &extra_info = mds_data.extra_medium_info_; - if (OB_ISNULL(medium_info_list)) { + if (mds_data.medium_info_list_.is_none_object()) { + LOG_INFO("medium info list addr is none, no need to validate", K(ret), K(ls_id), K(tablet_id), K(finish_medium_scn), "medium_info_list_complex_addr", mds_data.medium_info_list_); + } else if (OB_ISNULL(medium_info_list)) { ret = OB_ERR_UNEXPECTED; - LOG_WARN("medium info list is null", K(ret), K(mds_data), KP(medium_info_list)); + LOG_WARN("medium info list is null", K(ret), K(ls_id), K(tablet_id), K(finish_medium_scn), KP(medium_info_list)); } else if (OB_FAIL(ObMediumListChecker::validate_medium_info_list(extra_info, medium_info_list->medium_info_list_, finish_medium_scn))) { LOG_WARN("failed to validate medium info list", KR(ret), K(ls_id), K(tablet_id), K(mds_data), K(finish_medium_scn)); } @@ -5866,20 +5876,25 @@ int ObTablet::get_auto_inc_seq_mds_dump_kv( mds::MdsDumpKV *&kv) { int ret = OB_SUCCESS; + kv = nullptr; const ObTabletComplexAddr &complex_addr = mds_data_.auto_inc_seq_; if (OB_UNLIKELY(!is_inited_)) { ret = OB_NOT_INIT; LOG_WARN("not inited", K(ret), K_(is_inited)); + } else if (complex_addr.is_none_object()) { + // do nothing } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, kv))) { LOG_WARN("failed to alloc and new", K(ret)); } else { - ObTabletMemberWrapper wrapper; const share::ObTabletAutoincSeq *auto_inc_seq = nullptr; - if (OB_FAIL(ObTabletMdsData::fetch_auto_inc_seq(complex_addr, wrapper))) { - LOG_WARN("failed to fetch auto inc seq", K(ret)); - } else if (OB_FAIL(wrapper.get_member(auto_inc_seq))) { - LOG_WARN("failed to get member", K(ret)); + if (OB_FAIL(ObTabletMdsData::load_auto_inc_seq(allocator, complex_addr, auto_inc_seq))) { + LOG_WARN("failed to load auto inc seq", K(ret), K(complex_addr)); + } else if (nullptr == auto_inc_seq) { + // do nothing + if (nullptr != kv) { + allocator.free(kv); + } } else if (OB_FAIL(convert_to_mds_dump_kv(allocator, *auto_inc_seq, *kv))) { LOG_WARN("failed to convert to mds dump kv", K(ret)); } diff --git a/src/storage/tablet/ob_tablet.h b/src/storage/tablet/ob_tablet.h index c01a38d15..037d90cfb 100755 --- a/src/storage/tablet/ob_tablet.h +++ b/src/storage/tablet/ob_tablet.h @@ -102,7 +102,6 @@ class ObDDLKVHandle; class ObStorageSchema; class ObTabletTableIterator; class ObMetaDiskAddr; -class ObTabletMdsDumpStruct; class ObTabletCreateDeleteMdsUserData; class ObTabletBindingMdsUserData; class ObMemtableArray; diff --git a/src/storage/tablet/ob_tablet_dumped_medium_info.cpp b/src/storage/tablet/ob_tablet_dumped_medium_info.cpp index aa48ba7f3..6dc64980b 100644 --- a/src/storage/tablet/ob_tablet_dumped_medium_info.cpp +++ b/src/storage/tablet/ob_tablet_dumped_medium_info.cpp @@ -53,7 +53,7 @@ void ObTabletDumpedMediumInfo::reset() is_inited_ = false; } -int ObTabletDumpedMediumInfo::init(common::ObIAllocator &allocator) +int ObTabletDumpedMediumInfo::init_for_first_creation(common::ObIAllocator &allocator) { int ret = OB_SUCCESS; @@ -69,6 +69,139 @@ int ObTabletDumpedMediumInfo::init(common::ObIAllocator &allocator) return ret; } +int ObTabletDumpedMediumInfo::init_for_evict_medium_info( + common::ObIAllocator &allocator, + const int64_t finish_medium_scn, + const ObTabletDumpedMediumInfo &other) +{ + int ret = OB_SUCCESS; + const common::ObIArray &array = other.medium_info_list_; + + if (OB_UNLIKELY(is_inited_)) { + ret = OB_INIT_TWICE; + LOG_WARN("init twice", K(ret), K_(is_inited)); + } else { + allocator_ = &allocator; + for (int64_t i = 0; OB_SUCC(ret) && i < array.count(); ++i) { + const compaction::ObMediumCompactionInfo *src_info = array.at(i); + if (OB_ISNULL(src_info)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected error, medium info is null", K(ret), K(i), KP(src_info)); + } else if (src_info->medium_snapshot_ <= finish_medium_scn) { + // medium snapshot no bigger than finish medium scn(which is from last major sstable), + // no need to copy it + } else if (src_info->medium_snapshot_ <= get_max_medium_snapshot()) { + // medium info no bigger than current max medium snapshot, + // no need to copy it + } else if (OB_FAIL(do_append(*src_info))) { + LOG_WARN("failed to append medium info", K(ret), K(i), KPC(src_info)); + } + } + + if (OB_FAIL(ret)) { + reset(); + } else { + is_inited_ = true; + } + } + + return ret; +} + +int ObTabletDumpedMediumInfo::init_for_mds_table_dump( + common::ObIAllocator &allocator, + const int64_t finish_medium_scn, + const ObTabletDumpedMediumInfo &other1, + const ObTabletDumpedMediumInfo &other2) +{ + int ret = OB_SUCCESS; + + if (OB_UNLIKELY(is_inited_)) { + ret = OB_INIT_TWICE; + LOG_WARN("init twice", K(ret), K_(is_inited)); + } else { + allocator_ = &allocator; + common::ObSEArray array1; + common::ObSEArray array2; + + if (OB_FAIL(array1.assign(other1.medium_info_list_))) { + LOG_WARN("failed to assign", K(ret)); + } else if (OB_FAIL(array2.assign(other2.medium_info_list_))) { + LOG_WARN("failed to assign", K(ret)); + } else { + // sort first + std::sort(array1.begin(), array1.end(), ObTabletDumpedMediumInfo::compare); + std::sort(array2.begin(), array2.end(), ObTabletDumpedMediumInfo::compare); + + // merge + bool contain = false; + int64_t i = 0; + int64_t j = 0; + while (OB_SUCC(ret) && i < array1.count() && j < array2.count()) { + const compaction::ObMediumCompactionInfo *info1 = array1.at(i); + const compaction::ObMediumCompactionInfo *info2 = array2.at(j); + const compaction::ObMediumCompactionInfo *chosen_info = nullptr; + + if (OB_ISNULL(info1) || OB_ISNULL(info2)) { + LOG_WARN("medium info is null", K(ret), K(i), K(j), KP(info1), KP(info2)); + } else if (info1->medium_snapshot_ < info2->medium_snapshot_) { + chosen_info = info1; + ++i; + } else if (info1->medium_snapshot_ > info2->medium_snapshot_) { + chosen_info = info2; + ++j; + } else { + chosen_info = info2; + ++i; + ++j; + } + + if (OB_FAIL(ret)) { + } else if (chosen_info->medium_snapshot_ <= finish_medium_scn) { + // medium snapshot no bigger than finish medium scn(which is from last major sstable), + // no need to copy it + } else if (chosen_info->medium_snapshot_ <= get_max_medium_snapshot()) { + // do nothing + } else if (OB_FAIL(do_append(*chosen_info))) { + LOG_WARN("failed to append medium info", K(ret), K(i), K(j), KPC(chosen_info)); + } + } + + for (; OB_SUCC(ret) && i < array1.count(); ++i) { + const compaction::ObMediumCompactionInfo *info = array1.at(i); + if (info->medium_snapshot_ <= finish_medium_scn) { + // medium snapshot no bigger than finish medium scn(which is from last major sstable), + // no need to copy it + } else if (info->medium_snapshot_ <= get_max_medium_snapshot()) { + // do nothing + } else if (OB_FAIL(do_append(*info))) { + LOG_WARN("failed to append medium info", K(ret), K(i), KPC(info)); + } + } + + for (; OB_SUCC(ret) && j < array2.count(); ++j) { + const compaction::ObMediumCompactionInfo *info = array2.at(j); + if (info->medium_snapshot_ <= finish_medium_scn) { + // medium snapshot no bigger than finish medium scn(which is from last major sstable), + // no need to copy it + } else if (info->medium_snapshot_ <= get_max_medium_snapshot()) { + // do nothing + } else if (OB_FAIL(do_append(*info))) { + LOG_WARN("failed to append medium info", K(ret), K(j), KPC(info)); + } + } + } + + if (OB_FAIL(ret)) { + reset(); + } else { + is_inited_ = true; + } + } + + return ret; +} + int ObTabletDumpedMediumInfo::assign(const ObTabletDumpedMediumInfo &other, common::ObIAllocator &allocator) { int ret = OB_SUCCESS; @@ -152,7 +285,19 @@ int ObTabletDumpedMediumInfo::append(const compaction::ObMediumCompactionInfo &m if (OB_UNLIKELY(!is_inited_)) { ret = OB_NOT_INIT; LOG_WARN("not inited", K(ret), K_(is_inited)); - } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(*allocator_, info))) { + } else if (OB_FAIL(do_append(medium_info))) { + LOG_WARN("failed to do append", K(ret)); + } + + return ret; +} + +int ObTabletDumpedMediumInfo::do_append(const compaction::ObMediumCompactionInfo &medium_info) +{ + int ret = OB_SUCCESS; + compaction::ObMediumCompactionInfo *info = nullptr; + + if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(*allocator_, info))) { LOG_WARN("failed to alloc and new", K(ret)); } else if (OB_FAIL(info->assign(*allocator_, medium_info))) { LOG_WARN("failed to copy medium info", K(ret), K(medium_info)); @@ -202,7 +347,7 @@ int ObTabletDumpedMediumInfo::get_min_medium_info_key(compaction::ObMediumCompac } else { ObTabletDumpedMediumInfoIterator iter; ObArenaAllocator arena_allocator("iter"); - if (OB_FAIL(iter.init(arena_allocator, *this))) { + if (OB_FAIL(iter.init(arena_allocator, this))) { LOG_WARN("failed to init", K(ret)); } else { while (OB_SUCC(ret)) { @@ -234,7 +379,7 @@ int ObTabletDumpedMediumInfo::get_max_medium_info_key(compaction::ObMediumCompac } else { ObTabletDumpedMediumInfoIterator iter; ObArenaAllocator arena_allocator("iter"); - if (OB_FAIL(iter.init(arena_allocator, *this))) { + if (OB_FAIL(iter.init(arena_allocator, this))) { LOG_WARN("failed to init", K(ret)); } else if (OB_FAIL(iter.get_next_key(key))) { LOG_WARN("failed to get next medium info", K(ret)); @@ -479,7 +624,7 @@ ObTabletDumpedMediumInfoIterator::~ObTabletDumpedMediumInfoIterator() int ObTabletDumpedMediumInfoIterator::init( common::ObIAllocator &allocator, - const ObTabletDumpedMediumInfo &dumped_medium_info) + const ObTabletDumpedMediumInfo *dumped_medium_info) { int ret = OB_SUCCESS; @@ -487,25 +632,30 @@ int ObTabletDumpedMediumInfoIterator::init( ret = OB_INIT_TWICE; LOG_WARN("init twice", K(ret), K_(is_inited)); } else { - const common::ObSEArray &array = dumped_medium_info.medium_info_list_; - compaction::ObMediumCompactionInfo* info = nullptr; - for (int64_t i = 0; OB_SUCC(ret) && i < array.count(); ++i) { - compaction::ObMediumCompactionInfo* src_medium_info = array.at(i); - info = nullptr; - if (OB_ISNULL(src_medium_info)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected error, src medium info is null", K(ret), K(i), KP(src_medium_info)); - } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, info))) { - LOG_WARN("failed to alloc and new", K(ret)); - } else if (OB_FAIL(info->assign(allocator, *src_medium_info))) { - LOG_WARN("failed to copy medium info", K(ret), KPC(src_medium_info)); - } else if (OB_FAIL(medium_info_list_.push_back(info))) { - LOG_WARN("failed to push back to array", K(ret)); - } + if (nullptr == dumped_medium_info) { + // no need to copy medium info + } else { + const common::ObSEArray &array = dumped_medium_info->medium_info_list_; + compaction::ObMediumCompactionInfo *info = nullptr; + for (int64_t i = 0; OB_SUCC(ret) && i < array.count(); ++i) { + info = nullptr; + compaction::ObMediumCompactionInfo *src_medium_info = array.at(i); + if (OB_ISNULL(src_medium_info)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected error, src medium info is null", K(ret), K(i), KP(src_medium_info)); + } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, info))) { + LOG_WARN("failed to alloc and new", K(ret)); + } else if (OB_FAIL(info->assign(allocator, *src_medium_info))) { + LOG_WARN("failed to copy medium info", K(ret), KPC(src_medium_info)); + } else if (OB_FAIL(medium_info_list_.push_back(info))) { + LOG_WARN("failed to push back to array", K(ret)); + } - if (OB_FAIL(ret)) { - if (nullptr != info) { - allocator.free(info); + if (OB_FAIL(ret)) { + if (nullptr != info) { + info->compaction::ObMediumCompactionInfo::~ObMediumCompactionInfo(); + allocator.free(info); + } } } } diff --git a/src/storage/tablet/ob_tablet_dumped_medium_info.h b/src/storage/tablet/ob_tablet_dumped_medium_info.h index c6d7da1af..40102abd9 100644 --- a/src/storage/tablet/ob_tablet_dumped_medium_info.h +++ b/src/storage/tablet/ob_tablet_dumped_medium_info.h @@ -43,7 +43,16 @@ public: ObTabletDumpedMediumInfo(const ObTabletDumpedMediumInfo &) = delete; ObTabletDumpedMediumInfo &operator=(const ObTabletDumpedMediumInfo &) = delete; public: - int init(common::ObIAllocator &allocator); + int init_for_first_creation(common::ObIAllocator &allocator); + int init_for_evict_medium_info( + common::ObIAllocator &allocator, + const int64_t finish_medium_scn, + const ObTabletDumpedMediumInfo &other); + int init_for_mds_table_dump( + common::ObIAllocator &allocator, + const int64_t finish_medium_scn, + const ObTabletDumpedMediumInfo &other1, + const ObTabletDumpedMediumInfo &other2); void reset(); // key order in array: big -> small @@ -70,6 +79,8 @@ public: int64_t simple_to_string(char* buf, const int64_t buf_len, int64_t &pos) const; public: static bool compare(const compaction::ObMediumCompactionInfo *lhs, const compaction::ObMediumCompactionInfo *rhs); +private: + int do_append(const compaction::ObMediumCompactionInfo &medium_info); public: bool is_inited_; common::ObIAllocator *allocator_; @@ -86,7 +97,7 @@ public: public: int init( common::ObIAllocator &allocator, - const ObTabletDumpedMediumInfo &dumped_medium_info); + const ObTabletDumpedMediumInfo *dumped_medium_info); void reset(); int get_next_key(compaction::ObMediumCompactionInfoKey &key); int get_next_medium_info( diff --git a/src/storage/tablet/ob_tablet_full_memory_mds_data.cpp b/src/storage/tablet/ob_tablet_full_memory_mds_data.cpp index 2d1a4126c..71b16db3f 100644 --- a/src/storage/tablet/ob_tablet_full_memory_mds_data.cpp +++ b/src/storage/tablet/ob_tablet_full_memory_mds_data.cpp @@ -47,7 +47,7 @@ int ObTabletFullMemoryMdsData::init(common::ObArenaAllocator &allocator) if (OB_UNLIKELY(is_inited_)) { ret = OB_INIT_TWICE; LOG_WARN("init twice", K(ret), K_(is_inited)); - } else if (OB_FAIL(medium_info_list_.medium_info_list_.init(allocator))) { + } else if (OB_FAIL(medium_info_list_.medium_info_list_.init_for_first_creation(allocator))) { LOG_WARN("failed to init medium info list", K(ret)); } else { is_inited_ = true; @@ -136,9 +136,9 @@ int ObTabletFullMemoryMdsData::read_mds_dump_kv( LOG_WARN("invalid args", K(ret), K(mds_dump_kv_addr)); } else if (OB_FAIL(ObTabletMdsData::load_mds_dump_kv(allocator, mds_dump_kv_addr, ptr))) { LOG_WARN("failed to load mds dump kv", K(ret)); - } else if (OB_ISNULL(ptr)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected error, ptr is null", K(ret), KP(ptr)); + } else if (nullptr == ptr) { + // do nothing + dump_kv.reset(); } else if (OB_FAIL(dump_kv.assign(*ptr, allocator))) { LOG_WARN("failed to copy mds dump kv", K(ret)); } @@ -161,11 +161,10 @@ int ObTabletFullMemoryMdsData::read_medium_info_list( LOG_WARN("invalid args", K(ret), K(medium_info_list_addr)); } else if (OB_FAIL(ObTabletMdsData::load_medium_info_list(allocator, medium_info_list_addr, ptr))) { LOG_WARN("failed to load medium info list", K(ret)); - } else if (OB_ISNULL(ptr)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected error, ptr is null", K(ret), KP(ptr)); - } else if (OB_FAIL(medium_info_list.assign(*ptr, allocator))) { - LOG_WARN("failed to medium info list", K(ret)); + } else if (nullptr == ptr && OB_FAIL(medium_info_list.init_for_first_creation(allocator))) { + LOG_WARN("failed to init medium info list", K(ret)); + } else if (nullptr != ptr && OB_FAIL(medium_info_list.assign(*ptr, allocator))) { + LOG_WARN("failed to copy medium info list", K(ret)); } ObTabletMdsData::free_medium_info_list(allocator, ptr); @@ -180,15 +179,11 @@ int ObTabletFullMemoryMdsData::read_auto_inc_seq( { int ret = OB_SUCCESS; const share::ObTabletAutoincSeq *ptr = nullptr; - ObTabletMemberWrapper auto_inc_seq_wrapper; - if (OB_FAIL(ObTabletMdsData::fetch_auto_inc_seq(auto_inc_seq_addr, auto_inc_seq_wrapper))) { - LOG_WARN("failed to fetch auto inc seq", K(ret)); - } else if (OB_FAIL(auto_inc_seq_wrapper.get_member(ptr))) { - LOG_WARN("ObTabletMemberWrapper get member failed", K(ret)); - } else if (OB_ISNULL(ptr)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected error, ptr is null", K(ret), KP(ptr)); + if (OB_FAIL(ObTabletMdsData::load_auto_inc_seq(allocator, auto_inc_seq_addr, ptr))) { + LOG_WARN("failed to load auto inc seq", K(ret), K(auto_inc_seq_addr)); + } else if (nullptr == ptr) { + // do nothing } else if (OB_FAIL(auto_inc_seq.assign(allocator, *ptr))) { LOG_WARN("failed to copy auto inc seq", K(ret)); } diff --git a/src/storage/tablet/ob_tablet_mds_data.cpp b/src/storage/tablet/ob_tablet_mds_data.cpp index a00f6d280..6d4470bfc 100644 --- a/src/storage/tablet/ob_tablet_mds_data.cpp +++ b/src/storage/tablet/ob_tablet_mds_data.cpp @@ -17,11 +17,11 @@ #include "lib/utility/ob_macro_utils.h" #include "storage/blocksstable/ob_storage_cache_suite.h" #include "storage/compaction/ob_medium_compaction_mgr.h" +#include "storage/compaction/ob_medium_list_checker.h" #include "storage/compaction/ob_extra_medium_info.h" #include "storage/tablet/ob_tablet_full_memory_mds_data.h" #include "storage/tablet/ob_tablet_obj_load_helper.h" -#include "ob_i_tablet_mds_interface.h" -#include "storage/compaction/ob_medium_list_checker.h" +#include "storage/tablet/ob_i_tablet_mds_interface.h" #define USING_LOG_PREFIX MDS @@ -116,13 +116,62 @@ void ObTabletMdsData::reset() is_inited_ = false; } +void ObTabletMdsData::reset(common::ObIAllocator &allocator) +{ + free_auto_inc_seq(allocator, auto_inc_seq_.ptr_); + free_medium_info_list(allocator, medium_info_list_.ptr_); + free_mds_dump_kv(allocator, aux_tablet_info_.uncommitted_kv_.ptr_); + free_mds_dump_kv(allocator, aux_tablet_info_.committed_kv_.ptr_); + free_mds_dump_kv(allocator, tablet_status_.uncommitted_kv_.ptr_); + free_mds_dump_kv(allocator, tablet_status_.committed_kv_.ptr_); + + auto_inc_seq_.ptr_ = nullptr; + auto_inc_seq_.addr_.reset(); + medium_info_list_.ptr_ = nullptr; + medium_info_list_.addr_.reset(); + aux_tablet_info_.uncommitted_kv_.ptr_ = nullptr; + aux_tablet_info_.uncommitted_kv_.addr_.reset(); + aux_tablet_info_.committed_kv_.ptr_ = nullptr; + aux_tablet_info_.committed_kv_.addr_.reset(); + tablet_status_.uncommitted_kv_.ptr_ = nullptr; + tablet_status_.uncommitted_kv_.addr_.reset(); + tablet_status_.committed_kv_.ptr_ = nullptr; + tablet_status_.committed_kv_.addr_.reset(); + + is_inited_ = false; +} + bool ObTabletMdsData::is_valid() const { // TODO(@bowen.gbw): add more check rules return is_inited_; } -int ObTabletMdsData::init(common::ObIAllocator &allocator) +int ObTabletMdsData::init_for_first_creation(common::ObIAllocator &allocator) +{ + int ret = OB_SUCCESS; + + if (OB_UNLIKELY(is_inited_)) { + ret = OB_INIT_TWICE; + LOG_WARN("init twice", K(ret), K_(is_inited)); + } else { + auto_inc_seq_.addr_.set_none_addr(); + medium_info_list_.addr_.set_none_addr(); + aux_tablet_info_.uncommitted_kv_.addr_.set_none_addr(); + aux_tablet_info_.committed_kv_.addr_.set_none_addr(); + tablet_status_.uncommitted_kv_.addr_.set_none_addr(); + tablet_status_.committed_kv_.addr_.set_none_addr(); + + is_inited_ = true; + } + + return ret; +} + +int ObTabletMdsData::init_with_tablet_status( + common::ObIAllocator &allocator, + const ObTabletStatus::Status &tablet_status, + const ObTabletMdsUserDataType &data_type) { int ret = OB_SUCCESS; @@ -131,23 +180,23 @@ int ObTabletMdsData::init(common::ObIAllocator &allocator) LOG_WARN("init twice", K(ret), K_(is_inited)); } else if (OB_FAIL(tablet_status_.init(allocator))) { LOG_WARN("failed to init tablet status", K(ret)); - } else if (OB_FAIL(aux_tablet_info_.init(allocator))) { - LOG_WARN("failed to init aux tablet info", K(ret)); - } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, medium_info_list_.ptr_))) { - LOG_WARN("failed to alloc and new medium info list", K(ret)); - } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, auto_inc_seq_.ptr_))) { - LOG_WARN("failed to alloc and new auto inc seq", K(ret)); - } else if (OB_FAIL(medium_info_list_.ptr_->init(allocator))) { - LOG_WARN("failed to init medium info list", K(ret)); + } else if (OB_FAIL(set_tablet_status(allocator, tablet_status, data_type))) { + LOG_WARN("failed to set tablet status", K(ret)); } else { - set_mem_addr(); + auto_inc_seq_.addr_.set_none_addr(); + medium_info_list_.addr_.set_none_addr(); + aux_tablet_info_.uncommitted_kv_.addr_.set_none_addr(); + aux_tablet_info_.committed_kv_.addr_.set_none_addr(); + tablet_status_.uncommitted_kv_.addr_.set_mem_addr(0, sizeof(mds::MdsDumpKV)); + tablet_status_.committed_kv_.addr_.set_mem_addr(0, sizeof(mds::MdsDumpKV)); + is_inited_ = true; } return ret; } -int ObTabletMdsData::init( +int ObTabletMdsData::init_for_mds_table_dump( common::ObIAllocator &allocator, const ObTabletMdsData &mds_table_data, const ObTabletMdsData &base_data, @@ -158,208 +207,558 @@ int ObTabletMdsData::init( if (OB_UNLIKELY(is_inited_)) { ret = OB_INIT_TWICE; LOG_WARN("init twice", K(ret), K_(is_inited)); - } else if (OB_FAIL(tablet_status_.init(allocator))) { - LOG_WARN("failed to init tablet status", K(ret)); - } else if (OB_FAIL(aux_tablet_info_.init(allocator))) { - LOG_WARN("failed to init aux tablet info", K(ret)); - } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, medium_info_list_.ptr_))) { - LOG_WARN("failed to alloc and new medium info list", K(ret)); - } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, auto_inc_seq_.ptr_))) { - LOG_WARN("failed to alloc and new auto inc seq", K(ret)); - } else if (OB_FAIL(medium_info_list_.ptr_->init(allocator))) { - LOG_WARN("failed to init medium info list", K(ret)); - } - - if (OB_FAIL(ret)) { - } else if (OB_FAIL(fuse_mds_dump_node(allocator, mds_table_data.tablet_status_, base_data.tablet_status_, tablet_status_))) { - LOG_WARN("failed to fuse", K(ret)); - } else if (OB_FAIL(fuse_mds_dump_node(allocator, mds_table_data.aux_tablet_info_, base_data.aux_tablet_info_, aux_tablet_info_))) { - LOG_WARN("failed to fuse", K(ret)); - } else if (OB_FAIL(fuse_mds_dump_node(allocator, finish_medium_scn, mds_table_data.medium_info_list_, base_data.medium_info_list_, medium_info_list_))) { - LOG_WARN("failed to fuse", K(ret)); - } else if (OB_FAIL(fuse_mds_dump_node(allocator, mds_table_data.auto_inc_seq_, base_data.auto_inc_seq_, auto_inc_seq_))) { - LOG_WARN("failed to fuse", K(ret)); } else { - // always use base data to set extra medium info - extra_medium_info_.last_compaction_type_ = base_data.extra_medium_info_.last_compaction_type_; - extra_medium_info_.last_medium_scn_ = base_data.extra_medium_info_.last_medium_scn_; - extra_medium_info_.wait_check_flag_ = base_data.extra_medium_info_.wait_check_flag_; + if (OB_FAIL(init_single_complex_addr(allocator, mds_table_data.tablet_status_.uncommitted_kv_, base_data.tablet_status_.uncommitted_kv_, tablet_status_.uncommitted_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, mds_table_data.tablet_status_.committed_kv_, base_data.tablet_status_.committed_kv_, tablet_status_.committed_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, mds_table_data.aux_tablet_info_.uncommitted_kv_, base_data.aux_tablet_info_.uncommitted_kv_, aux_tablet_info_.uncommitted_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, mds_table_data.aux_tablet_info_.committed_kv_, base_data.aux_tablet_info_.committed_kv_, aux_tablet_info_.committed_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, mds_table_data.auto_inc_seq_, base_data.auto_inc_seq_, auto_inc_seq_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, mds_table_data.medium_info_list_, base_data.medium_info_list_, finish_medium_scn, medium_info_list_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(update_user_data_from_complex_addr(tablet_status_.committed_kv_, tablet_status_cache_))) { + LOG_WARN("failed to update user data cache", K(ret), "complex_addr", tablet_status_.committed_kv_); + } else if (OB_FAIL(update_user_data_from_complex_addr(aux_tablet_info_.committed_kv_, aux_tablet_info_cache_))) { + LOG_WARN("failed to update user data cache", K(ret), "complex_addr", aux_tablet_info_.committed_kv_); + } else { + // always use base data to set extra medium info + extra_medium_info_ = base_data.extra_medium_info_; + is_inited_ = true; + LOG_INFO("succeeded to init mds data", K(ret), + "mds_table_medium_info", mds_table_data.medium_info_list_, + "base_medium_info", base_data.medium_info_list_, + K(finish_medium_scn), K_(medium_info_list), K_(extra_medium_info)); + } - LOG_INFO("succeeded to init medium info list", K(ret), - "mds_table_medium_info", mds_table_data.medium_info_list_, - "base_medium_info", base_data.medium_info_list_, - K(finish_medium_scn), K_(medium_info_list), K_(extra_medium_info)); - } - - if (OB_FAIL(ret)) { - } else if (OB_FAIL(update_user_data_from_complex_addr(tablet_status_.committed_kv_, tablet_status_cache_))) { - LOG_WARN("failed to update user data cache", K(ret), "complex_addr", tablet_status_.committed_kv_); - } else if (OB_FAIL(update_user_data_from_complex_addr(aux_tablet_info_.committed_kv_, aux_tablet_info_cache_))) { - LOG_WARN("failed to update user data cache", K(ret), "complex_addr", aux_tablet_info_.committed_kv_); - } - - if (OB_SUCC(ret)) { - set_mem_addr(); - - is_inited_ = true; + if (OB_FAIL(ret)) { + reset(allocator); + } } return ret; } -int ObTabletMdsData::init( +int ObTabletMdsData::init_single_complex_addr( + common::ObIAllocator &allocator, + const ObTabletComplexAddr &mds_table_data, + const ObTabletComplexAddr &base_data, + ObTabletComplexAddr &fused_data) +{ + int ret = OB_SUCCESS; + fused_data.reset(); + mds::MdsDumpKV *&fused_data_ptr = fused_data.ptr_; + const mds::MdsDumpKV *mds_table_ptr = nullptr; + const mds::MdsDumpKV *base_ptr = nullptr; + + if (OB_FAIL(load_mds_dump_kv(allocator, mds_table_data, mds_table_ptr))) { + LOG_WARN("failed to load mds dump kv", K(ret)); + } else if (OB_FAIL(load_mds_dump_kv(allocator, base_data, base_ptr))) { + LOG_WARN("failed to load mds dump kv", K(ret)); + } else if (nullptr == mds_table_ptr && nullptr == base_ptr) { + // data in mds table and base is both empty, so set addr to NONE + fused_data.addr_.set_none_addr(); + } else { + if (nullptr == mds_table_ptr && nullptr != base_ptr) { + fused_data_ptr = const_cast(base_ptr); + } else if (nullptr != mds_table_ptr) { + // data in mds table is not empty, ignore data in base, use data in mds table as fused data + fused_data_ptr = const_cast(mds_table_ptr); + free_mds_dump_kv(allocator, base_ptr); + } + + if (OB_FAIL(ret)) { + fused_data_ptr = nullptr; + free_mds_dump_kv(allocator, mds_table_ptr); + free_mds_dump_kv(allocator, base_ptr); + } else { + fused_data.addr_.set_mem_addr(0, sizeof(mds::MdsDumpKV)); + } + } + + return ret; +} + +int ObTabletMdsData::init_single_complex_addr( + common::ObIAllocator &allocator, + const ObTabletComplexAddr &mds_table_data, + const ObTabletComplexAddr &base_data, + ObTabletComplexAddr &fused_data) +{ + int ret = OB_SUCCESS; + fused_data.reset(); + share::ObTabletAutoincSeq *&fused_data_ptr = fused_data.ptr_; + const share::ObTabletAutoincSeq *mds_table_ptr = nullptr; + const share::ObTabletAutoincSeq *base_ptr = nullptr; + + if (OB_FAIL(load_auto_inc_seq(allocator, mds_table_data, mds_table_ptr))) { + LOG_WARN("failed to load auto inc seq", K(ret), K(mds_table_data)); + } else if (OB_FAIL(load_auto_inc_seq(allocator, base_data, base_ptr))) { + LOG_WARN("failed to load auto inc seq", K(ret), K(base_data)); + } else if (nullptr == mds_table_ptr && nullptr == base_ptr) { + // both data in mds table and base is invalid, no need to fuse, set fused data to NONE + fused_data.addr_.set_none_addr(); + } else { + if (nullptr == mds_table_ptr && nullptr != base_ptr) { + fused_data_ptr = const_cast(base_ptr); + } else if (nullptr != mds_table_ptr) { + // data in mds table is not empty, ignore data in base, use data in mds table as fused data + fused_data_ptr = const_cast(mds_table_ptr); + free_auto_inc_seq(allocator, base_ptr); + } + + if (OB_FAIL(ret)) { + fused_data_ptr = nullptr; + free_auto_inc_seq(allocator, mds_table_ptr); + free_auto_inc_seq(allocator, base_ptr); + } else { + fused_data.addr_.set_mem_addr(0, sizeof(share::ObTabletAutoincSeq)); + } + } + + return ret; +} + +int ObTabletMdsData::init_single_complex_addr( + common::ObIAllocator &allocator, + const ObTabletComplexAddr &mds_table_data, + const ObTabletComplexAddr &base_data, + const int64_t finish_medium_scn, + ObTabletComplexAddr &fused_data) +{ + int ret = OB_SUCCESS; + fused_data.reset(); + ObTabletDumpedMediumInfo *&fused_data_ptr = fused_data.ptr_; + const ObTabletDumpedMediumInfo *mds_table_ptr = nullptr; + const ObTabletDumpedMediumInfo *base_ptr = nullptr; + + if (OB_FAIL(load_medium_info_list(allocator, mds_table_data, mds_table_ptr))) { + LOG_WARN("failed to load medium info list", K(ret), K(mds_table_data)); + } else if (OB_FAIL(load_medium_info_list(allocator, base_data, base_ptr))) { + LOG_WARN("failed to load medium info list", K(ret), K(base_data)); + } else if (nullptr == mds_table_ptr && nullptr == base_ptr) { + // data in mds table and base is both empty, set fused data to NONE + fused_data.addr_.set_none_addr(); + } else { + if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, fused_data_ptr))) { + LOG_WARN("failed to alloc and new", K(ret)); + } else if (nullptr == mds_table_ptr && nullptr != base_ptr) { + if (OB_FAIL(fused_data_ptr->init_for_evict_medium_info(allocator, finish_medium_scn, *base_ptr))) { + LOG_WARN("failed to init", K(ret)); + } + } else if (nullptr != mds_table_ptr && nullptr == base_ptr) { + if (OB_FAIL(fused_data_ptr->init_for_evict_medium_info(allocator, finish_medium_scn, *mds_table_ptr))) { + LOG_WARN("failed to init", K(ret)); + } + } else if (nullptr != mds_table_ptr && nullptr != base_ptr) { + if (OB_FAIL(fused_data_ptr->init_for_mds_table_dump(allocator, finish_medium_scn, *mds_table_ptr, *base_ptr))) { + LOG_WARN("failed to init", K(ret)); + } + } + + if (OB_FAIL(ret)) { + free_medium_info_list(allocator, fused_data_ptr); + fused_data_ptr = nullptr; + } else { + fused_data.addr_.set_mem_addr(0, sizeof(ObTabletDumpedMediumInfo)); + } + + // always free medium info list after usage + free_medium_info_list(allocator, mds_table_ptr); + free_medium_info_list(allocator, base_ptr); + } + + return ret; +} + +int ObTabletMdsData::init_for_evict_medium_info( common::ObIAllocator &allocator, const ObTabletMdsData &other, const int64_t finish_medium_scn, const ObMergeType merge_type) { int ret = OB_SUCCESS; - ObArenaAllocator arena_allocator("mds_data"); - const mds::MdsDumpKV *tablet_status_uncommitted_kv = nullptr; - const mds::MdsDumpKV *tablet_status_committed_kv = nullptr; - const mds::MdsDumpKV *aux_tablet_info_uncommitted_kv = nullptr; - const mds::MdsDumpKV *aux_tablet_info_committed_kv = nullptr; - const ObTabletDumpedMediumInfo *medium_info_list = nullptr; - const share::ObTabletAutoincSeq *auto_inc_seq = nullptr; - ObTabletMemberWrapper auto_inc_seq_wrapper; if (OB_UNLIKELY(is_inited_)) { ret = OB_INIT_TWICE; LOG_WARN("init twice", K(ret), K_(is_inited)); - } - - // load or fetch - if (OB_FAIL(ret)) { - } else if (OB_FAIL(load_mds_dump_kv(arena_allocator, other.tablet_status_.uncommitted_kv_, tablet_status_uncommitted_kv))) { - LOG_WARN("failed to load mds dump kv", K(ret)); - } else if (OB_FAIL(load_mds_dump_kv(arena_allocator, other.tablet_status_.committed_kv_, tablet_status_committed_kv))) { - LOG_WARN("failed to load mds dump kv", K(ret)); - } else if (OB_FAIL(load_mds_dump_kv(arena_allocator, other.aux_tablet_info_.uncommitted_kv_, aux_tablet_info_uncommitted_kv))) { - LOG_WARN("failed to load mds dump kv", K(ret)); - } else if (OB_FAIL(load_mds_dump_kv(arena_allocator, other.aux_tablet_info_.committed_kv_, aux_tablet_info_committed_kv))) { - LOG_WARN("failed to load mds dump kv", K(ret)); - } else if (OB_FAIL(load_medium_info_list(arena_allocator, other.medium_info_list_, medium_info_list))) { - LOG_WARN("failed to load medium info list", K(ret)); - } else if (OB_FAIL(fetch_auto_inc_seq(other.auto_inc_seq_, auto_inc_seq_wrapper))) { - LOG_WARN("failed to fetch auto inc seq", K(ret)); - } else if (OB_FAIL(auto_inc_seq_wrapper.get_member(auto_inc_seq))) { - LOG_WARN("ObTabletMemberWrapper get member failed", K(ret)); - } - - // do initialization - if (OB_FAIL(ret)) { - } else if (OB_FAIL(do_init(allocator, - tablet_status_uncommitted_kv, tablet_status_committed_kv, - aux_tablet_info_uncommitted_kv, aux_tablet_info_committed_kv, - auto_inc_seq))) { - LOG_WARN("failed to do init", K(ret)); - } else if (OB_FAIL(init_medium_info_list(allocator, medium_info_list, other.extra_medium_info_, - finish_medium_scn, merge_type))) { - LOG_WARN("failed to init medium info list", K(ret)); } else { - set_mem_addr(); - is_inited_ = true; - } + if (OB_FAIL(init_single_complex_addr(allocator, other.tablet_status_.uncommitted_kv_, tablet_status_.uncommitted_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, other.tablet_status_.committed_kv_, tablet_status_.committed_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, other.aux_tablet_info_.uncommitted_kv_, aux_tablet_info_.uncommitted_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, other.aux_tablet_info_.committed_kv_, aux_tablet_info_.committed_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, other.auto_inc_seq_, auto_inc_seq_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, other.medium_info_list_, finish_medium_scn, medium_info_list_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(update_user_data_from_complex_addr(tablet_status_.committed_kv_, tablet_status_cache_))) { + LOG_WARN("failed to update user data", K(ret), "complex_addr", tablet_status_.committed_kv_); + } else if (OB_FAIL(update_user_data_from_complex_addr(aux_tablet_info_.committed_kv_, aux_tablet_info_cache_))) { + LOG_WARN("failed to update user data", K(ret), "complex_addr", aux_tablet_info_.committed_kv_); + } else if (is_major_merge_type(merge_type)) { + extra_medium_info_.last_compaction_type_ = is_major_merge(merge_type) ? compaction::ObMediumCompactionInfo::MAJOR_COMPACTION : compaction::ObMediumCompactionInfo::MEDIUM_COMPACTION; + extra_medium_info_.last_medium_scn_ = finish_medium_scn; + extra_medium_info_.wait_check_flag_ = true; + } else { + extra_medium_info_ = other.extra_medium_info_; + } - ObTabletMdsData::free_mds_dump_kv(arena_allocator, tablet_status_uncommitted_kv); - ObTabletMdsData::free_mds_dump_kv(arena_allocator, tablet_status_committed_kv); - ObTabletMdsData::free_mds_dump_kv(arena_allocator, aux_tablet_info_uncommitted_kv); - ObTabletMdsData::free_mds_dump_kv(arena_allocator, aux_tablet_info_committed_kv); - ObTabletMdsData::free_medium_info_list(arena_allocator, medium_info_list); + if (OB_FAIL(ret)) { + reset(allocator); + } else { + is_inited_ = true; + LOG_INFO("succeeded to init mds data", K(ret), K(finish_medium_scn), + "src_medium_info_list", other.medium_info_list_, + "src_extra_medium_info", other.extra_medium_info_, + K_(medium_info_list), K_(extra_medium_info)); + } + } return ret; } -int ObTabletMdsData::init( +int ObTabletMdsData::init_single_complex_addr( + common::ObIAllocator &allocator, + const ObTabletComplexAddr &src_addr, + ObTabletComplexAddr &dst_addr) +{ + int ret = OB_SUCCESS; + dst_addr.reset(); + const mds::MdsDumpKV *ptr = nullptr; + + if (OB_FAIL(load_mds_dump_kv(allocator, src_addr, ptr))) { + LOG_WARN("failed to load mds dump kv", K(ret), K(src_addr)); + } else if (nullptr == ptr) { + dst_addr.addr_.set_none_addr(); + } else { + dst_addr.ptr_ = const_cast(ptr); + dst_addr.addr_.set_mem_addr(0, sizeof(mds::MdsDumpKV)); + } + + return ret; +} + +int ObTabletMdsData::init_single_complex_addr( + common::ObIAllocator &allocator, + const ObTabletComplexAddr &src_addr, + ObTabletComplexAddr &dst_addr) +{ + int ret = OB_SUCCESS; + dst_addr.reset(); + const share::ObTabletAutoincSeq *ptr = nullptr; + share::ObTabletAutoincSeq *&dst_data = dst_addr.ptr_; + + if (OB_FAIL(load_auto_inc_seq(allocator, src_addr, ptr))) { + LOG_WARN("failed to load auto inc seq", K(ret), K(src_addr)); + } else if (nullptr == ptr) { + // ptr is emtpy, no need to copy it, set dst addr to NONE + dst_addr.addr_.set_none_addr(); + } else { + dst_addr.ptr_ = const_cast(ptr); + dst_addr.addr_.set_mem_addr(0, sizeof(share::ObTabletAutoincSeq)); + } + + return ret; +} + +int ObTabletMdsData::init_single_complex_addr( + common::ObIAllocator &allocator, + const ObTabletComplexAddr &src_addr, + const int64_t finish_medium_scn, + ObTabletComplexAddr &dst_addr) +{ + int ret = OB_SUCCESS; + dst_addr.reset(); + const ObTabletDumpedMediumInfo *ptr = nullptr; + ObTabletDumpedMediumInfo *&dst_data = dst_addr.ptr_; + + if (OB_FAIL(load_medium_info_list(allocator, src_addr, ptr))) { + LOG_WARN("failed to load medium info list", K(ret), K(src_addr)); + } else if (nullptr == ptr) { + dst_addr.addr_.set_none_addr(); + } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, dst_data))) { + LOG_WARN("failed to alloc and new", K(ret)); + } else if (OB_FAIL(dst_data->init_for_evict_medium_info(allocator, finish_medium_scn, *ptr))) { + LOG_WARN("failed to init", K(ret)); + } else if (dst_data->medium_info_list_.empty()) { + // dst data is empty, so no need to keep it + free_medium_info_list(allocator, dst_data); + dst_data = nullptr; + dst_addr.addr_.set_none_addr(); + } else { + dst_addr.addr_.set_mem_addr(0, sizeof(ObTabletDumpedMediumInfo)); + } + + if (OB_FAIL(ret)) { + free_medium_info_list(allocator, dst_data); + dst_data = nullptr; + } + + // always free ptr after usage + free_medium_info_list(allocator, ptr); + + return ret; +} + +int ObTabletMdsData::init_by_full_memory_mds_data( common::ObIAllocator &allocator, const ObTabletFullMemoryMdsData &full_memory_mds_data) { int ret = OB_SUCCESS; - if (OB_FAIL(alloc_and_new(allocator))) { - LOG_WARN("failed to alloc and new", K(ret)); - } else if (OB_FAIL(tablet_status_.uncommitted_kv_.ptr_->assign(full_memory_mds_data.tablet_status_uncommitted_kv_, allocator))) { - LOG_WARN("failed to assign", K(ret)); - } else if (OB_FAIL(tablet_status_.committed_kv_.ptr_->assign(full_memory_mds_data.tablet_status_committed_kv_, allocator))) { - LOG_WARN("failed to assign", K(ret)); - } else if (OB_FAIL(aux_tablet_info_.uncommitted_kv_.ptr_->assign(full_memory_mds_data.aux_tablet_info_uncommitted_kv_, allocator))) { - LOG_WARN("failed to assign", K(ret)); - } else if (OB_FAIL(aux_tablet_info_.committed_kv_.ptr_->assign(full_memory_mds_data.aux_tablet_info_committed_kv_, allocator))) { - LOG_WARN("failed to assign", K(ret)); - } else if (OB_FAIL(auto_inc_seq_.ptr_->assign(allocator, full_memory_mds_data.auto_inc_seq_))) { - LOG_WARN("failed to assign auto inc seq", K(ret), "auto_inc_seq", full_memory_mds_data.auto_inc_seq_); - } else if (OB_FAIL(init_medium_info_list(allocator, &full_memory_mds_data.medium_info_list_.medium_info_list_, full_memory_mds_data.medium_info_list_.extra_medium_info_))) { - LOG_WARN("failed to init medium info list", K(ret)); - } else if (OB_FAIL(update_user_data_from_complex_addr(tablet_status_.committed_kv_, tablet_status_cache_))) { - LOG_WARN("failed to update user data cache", K(ret), "complex_addr", tablet_status_.committed_kv_); - } else if (OB_FAIL(update_user_data_from_complex_addr(aux_tablet_info_.committed_kv_, aux_tablet_info_cache_))) { - LOG_WARN("failed to update user data cache", K(ret), "complex_addr", aux_tablet_info_.committed_kv_); + if (OB_UNLIKELY(is_inited_)) { + ret = OB_INIT_TWICE; + LOG_WARN("init twice", K(ret), K_(is_inited)); } else { - set_mem_addr(); - is_inited_ = true; + if (OB_FAIL(init_single_complex_addr(allocator, full_memory_mds_data.tablet_status_uncommitted_kv_, tablet_status_.uncommitted_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, full_memory_mds_data.tablet_status_committed_kv_, tablet_status_.committed_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, full_memory_mds_data.aux_tablet_info_uncommitted_kv_, aux_tablet_info_.uncommitted_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, full_memory_mds_data.aux_tablet_info_committed_kv_, aux_tablet_info_.committed_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, full_memory_mds_data.auto_inc_seq_, auto_inc_seq_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, full_memory_mds_data.medium_info_list_.medium_info_list_, medium_info_list_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(update_user_data_from_complex_addr(tablet_status_.committed_kv_, tablet_status_cache_))) { + LOG_WARN("failed to update user data cache", K(ret), "complex_addr", tablet_status_.committed_kv_); + } else if (OB_FAIL(update_user_data_from_complex_addr(aux_tablet_info_.committed_kv_, aux_tablet_info_cache_))) { + LOG_WARN("failed to update user data cache", K(ret), "complex_addr", aux_tablet_info_.committed_kv_); + } else { + extra_medium_info_ = full_memory_mds_data.medium_info_list_.extra_medium_info_; + } + + if (OB_FAIL(ret)) { + reset(allocator); + } else { + is_inited_ = true; + LOG_INFO("succeeded to init mds data", K(ret), + "src_medium_info_list", full_memory_mds_data.medium_info_list_.medium_info_list_, + "src_extra_medium_info", full_memory_mds_data.medium_info_list_.extra_medium_info_, + K_(medium_info_list), K_(extra_medium_info)); + } } return ret; } -int ObTabletMdsData::init( +int ObTabletMdsData::init_single_complex_addr( + common::ObIAllocator &allocator, + const mds::MdsDumpKV &src_data, + ObTabletComplexAddr &dst_addr) +{ + int ret = OB_SUCCESS; + dst_addr.reset(); + mds::MdsDumpKV *&dst_data = dst_addr.ptr_; + const mds::MdsDumpNode &dump_node = src_data.v_; + + if (dump_node.user_data_.empty()) { + // src data is empty actually, dst should be set to NONE + dst_addr.addr_.set_none_addr(); + } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, dst_data))) { + LOG_WARN("failed to alloc and new", K(ret)); + } else if (OB_FAIL(dst_data->assign(src_data, allocator))) { + LOG_WARN("failed to copy", K(ret), K(src_data)); + } else { + dst_addr.addr_.set_mem_addr(0, sizeof(mds::MdsDumpKV)); + } + + if (OB_FAIL(ret)) { + free_mds_dump_kv(allocator, dst_data); + dst_data = nullptr; + } + + return ret; +} + +int ObTabletMdsData::init_single_complex_addr( + common::ObIAllocator &allocator, + const share::ObTabletAutoincSeq &src_data, + ObTabletComplexAddr &dst_addr) +{ + int ret = OB_SUCCESS; + dst_addr.reset(); + share::ObTabletAutoincSeq *&dst_data = dst_addr.ptr_; + + if (!src_data.is_valid()) { + // src data is invalid, dst should be set to NONE + dst_addr.addr_.set_none_addr(); + } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, dst_data))) { + LOG_WARN("failed to alloc and new", K(ret)); + } else if (OB_FAIL(dst_data->assign(allocator, src_data))) { + LOG_WARN("failed to copy", K(ret), K(src_data)); + } else { + dst_addr.addr_.set_mem_addr(0, sizeof(share::ObTabletAutoincSeq)); + } + + if (OB_FAIL(ret)) { + free_auto_inc_seq(allocator, dst_data); + dst_data = nullptr; + } + + return ret; +} + +int ObTabletMdsData::init_single_complex_addr( + common::ObIAllocator &allocator, + const ObTabletDumpedMediumInfo &src_data, + ObTabletComplexAddr &dst_addr) +{ + int ret = OB_SUCCESS; + dst_addr.reset(); + ObTabletDumpedMediumInfo *&dst_data = dst_addr.ptr_; + + if (!src_data.is_valid() || src_data.medium_info_list_.empty()) { + // src data is invalid or medium info list is empty, dst should be set to NONE + dst_addr.addr_.set_none_addr(); + } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, dst_data))) { + LOG_WARN("failed to alloc and new", K(ret)); + } else if (OB_FAIL(dst_data->assign(src_data, allocator))) { + LOG_WARN("failed to copy", K(ret)); + } else { + dst_addr.addr_.set_mem_addr(0, sizeof(ObTabletDumpedMediumInfo)); + } + + if (OB_FAIL(ret)) { + free_medium_info_list(allocator, dst_data); + dst_data = nullptr; + } + + return ret; +} + +int ObTabletMdsData::init_single_complex_addr_and_extra_info( + common::ObIAllocator &allocator, + const ObTabletComplexAddr &src_addr, + const compaction::ObExtraMediumInfo &src_addr_extra_info, + const ObTabletDumpedMediumInfo &src_data, + const compaction::ObExtraMediumInfo &src_data_extra_info, + const int64_t finish_medium_scn, + ObTabletComplexAddr &dst_addr, + compaction::ObExtraMediumInfo &dst_extra_info) +{ + int ret = OB_SUCCESS; + dst_addr.reset(); + const ObTabletDumpedMediumInfo *ptr = nullptr; + ObTabletDumpedMediumInfo *&dst_data = dst_addr.ptr_; + bool empty_data_from_src_data = (!src_data.is_valid() || src_data.medium_info_list_.empty()); + + if (OB_FAIL(load_medium_info_list(allocator, src_addr, ptr))) { + LOG_WARN("failed to load medium info list", K(ret), K(src_addr)); + } else if ((nullptr == ptr) && empty_data_from_src_data) { + dst_addr.addr_.set_none_addr(); + } else { + if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, dst_data))) { + LOG_WARN("failed to alloc and new", K(ret)); + } else if (nullptr == ptr && !empty_data_from_src_data) { + if (OB_FAIL(dst_data->init_for_evict_medium_info(allocator, finish_medium_scn, src_data))) { + LOG_WARN("failed to copy medium info", K(ret), K(finish_medium_scn)); + } + } else if ((nullptr != ptr) && empty_data_from_src_data) { + if (OB_FAIL(dst_data->init_for_evict_medium_info(allocator, finish_medium_scn, *ptr))) { + LOG_WARN("failed to copy medium info", K(ret), K(finish_medium_scn)); + } + } else if ((nullptr != ptr) && !empty_data_from_src_data) { + if (OB_FAIL(dst_data->init_for_mds_table_dump(allocator, finish_medium_scn, *ptr, src_data))) { + LOG_WARN("failed to copy medium info", K(ret), K(finish_medium_scn)); + } + } else { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected branch", K(ret), K(src_addr), KPC(ptr), K(src_data)); + } + + if (OB_FAIL(ret)) { + free_medium_info_list(allocator, dst_data); + dst_data = nullptr; + } else if (dst_data->medium_info_list_.empty()) { + free_medium_info_list(allocator, dst_data); + dst_data = nullptr; + dst_addr.addr_.set_none_addr(); + } else { + dst_addr.addr_.set_mem_addr(0, sizeof(ObTabletDumpedMediumInfo)); + } + } + + if (OB_FAIL(ret)) { + } else if (nullptr == ptr + || finish_medium_scn < src_addr_extra_info.last_medium_scn_ + || src_addr_extra_info.last_medium_scn_ < src_data_extra_info.last_medium_scn_) { + dst_extra_info.last_compaction_type_ = src_data_extra_info.last_compaction_type_; + dst_extra_info.last_medium_scn_ = src_data_extra_info.last_medium_scn_; + if (0 == src_data_extra_info.last_medium_scn_) { + dst_extra_info.wait_check_flag_ = false; + } else { + dst_extra_info.wait_check_flag_ = true; + } + } else { + dst_extra_info = src_addr_extra_info; + } + + // always free ptr after usage + free_medium_info_list(allocator, ptr); + + return ret; +} + +int ObTabletMdsData::init_for_merge_with_full_mds_data( common::ObIAllocator &allocator, const ObTabletMdsData &other, const ObTabletFullMediumInfo &full_memory_medium_info_list, const int64_t finish_medium_scn) { int ret = OB_SUCCESS; - ObArenaAllocator arena_allocator("mds_data"); - const mds::MdsDumpKV *tablet_status_uncommitted_kv = nullptr; - const mds::MdsDumpKV *tablet_status_committed_kv = nullptr; - const mds::MdsDumpKV *aux_tablet_info_uncommitted_kv = nullptr; - const mds::MdsDumpKV *aux_tablet_info_committed_kv = nullptr; - const ObTabletDumpedMediumInfo *medium_info_list = nullptr; - const share::ObTabletAutoincSeq *auto_inc_seq = nullptr; - ObTabletMemberWrapper auto_inc_seq_wrapper; if (OB_UNLIKELY(is_inited_)) { ret = OB_INIT_TWICE; LOG_WARN("init twice", K(ret), K_(is_inited)); - } - - // load or fetch - if (OB_FAIL(ret)) { - } else if (OB_FAIL(load_mds_dump_kv(arena_allocator, other.tablet_status_.uncommitted_kv_, tablet_status_uncommitted_kv))) { - LOG_WARN("failed to load mds dump kv", K(ret)); - } else if (OB_FAIL(load_mds_dump_kv(arena_allocator, other.tablet_status_.committed_kv_, tablet_status_committed_kv))) { - LOG_WARN("failed to load mds dump kv", K(ret)); - } else if (OB_FAIL(load_mds_dump_kv(arena_allocator, other.aux_tablet_info_.uncommitted_kv_, aux_tablet_info_uncommitted_kv))) { - LOG_WARN("failed to load mds dump kv", K(ret)); - } else if (OB_FAIL(load_mds_dump_kv(arena_allocator, other.aux_tablet_info_.committed_kv_, aux_tablet_info_committed_kv))) { - LOG_WARN("failed to load mds dump kv", K(ret)); - } else if (OB_FAIL(load_medium_info_list(arena_allocator, other.medium_info_list_, medium_info_list))) { - LOG_WARN("failed to load medium info list", K(ret)); - } else if (OB_FAIL(fetch_auto_inc_seq(other.auto_inc_seq_, auto_inc_seq_wrapper))) { - LOG_WARN("failed to fetch auto inc seq", K(ret)); - } else if (OB_FAIL(auto_inc_seq_wrapper.get_member(auto_inc_seq))) { - LOG_WARN("ObTabletMemberWrapper get member failed", K(ret)); - } - - // do initialization - if (OB_FAIL(ret)) { - } else if (OB_FAIL(do_init(allocator, - tablet_status_uncommitted_kv, tablet_status_committed_kv, - aux_tablet_info_uncommitted_kv, aux_tablet_info_committed_kv, - auto_inc_seq))) { - LOG_WARN("failed to do init", K(ret)); - } else if (OB_FAIL(init_medium_info_list(allocator, medium_info_list, full_memory_medium_info_list, other.extra_medium_info_, finish_medium_scn))) { - LOG_WARN("failed to init medium info list", K(ret)); } else { - set_mem_addr(); - is_inited_ = true; - } + if (OB_FAIL(init_single_complex_addr(allocator, other.tablet_status_.uncommitted_kv_, tablet_status_.uncommitted_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, other.tablet_status_.committed_kv_, tablet_status_.committed_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, other.aux_tablet_info_.uncommitted_kv_, aux_tablet_info_.uncommitted_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, other.aux_tablet_info_.committed_kv_, aux_tablet_info_.committed_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, other.auto_inc_seq_, auto_inc_seq_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(update_user_data_from_complex_addr(tablet_status_.committed_kv_, tablet_status_cache_))) { + LOG_WARN("failed to update user data cache", K(ret), "complex_addr", tablet_status_.committed_kv_); + } else if (OB_FAIL(update_user_data_from_complex_addr(aux_tablet_info_.committed_kv_, aux_tablet_info_cache_))) { + LOG_WARN("failed to update user data cache", K(ret), "complex_addr", aux_tablet_info_.committed_kv_); + } else if (OB_FAIL(init_single_complex_addr_and_extra_info( + allocator, + other.medium_info_list_, + other.extra_medium_info_, + full_memory_medium_info_list.medium_info_list_, + full_memory_medium_info_list.extra_medium_info_, + finish_medium_scn, + medium_info_list_, + extra_medium_info_))) { + LOG_WARN("failed to init single complex addr", K(ret), K(finish_medium_scn)); + } - ObTabletMdsData::free_mds_dump_kv(arena_allocator, tablet_status_uncommitted_kv); - ObTabletMdsData::free_mds_dump_kv(arena_allocator, tablet_status_committed_kv); - ObTabletMdsData::free_mds_dump_kv(arena_allocator, aux_tablet_info_uncommitted_kv); - ObTabletMdsData::free_mds_dump_kv(arena_allocator, aux_tablet_info_committed_kv); - ObTabletMdsData::free_medium_info_list(arena_allocator, medium_info_list); + if (OB_FAIL(ret)) { + reset(allocator); + } else { + is_inited_ = true; + LOG_INFO("succeeded to init mds data", K(ret), K(finish_medium_scn), + "other_memory_medium_info_list", other.medium_info_list_, + "other_memory_extra_medium_info", other.extra_medium_info_, + "full_memory_medium_info_list", full_memory_medium_info_list.medium_info_list_, + "full_memory_extra_medium_info", full_memory_medium_info_list.extra_medium_info_, + K_(medium_info_list), K_(extra_medium_info)); + } + } return ret; } @@ -369,62 +768,48 @@ int ObTabletMdsData::init_with_update_medium_info( const ObTabletMdsData &other) { int ret = OB_SUCCESS; - ObArenaAllocator arena_allocator("mds_data"); - const mds::MdsDumpKV *tablet_status_uncommitted_kv = nullptr; - const mds::MdsDumpKV *tablet_status_committed_kv = nullptr; - const mds::MdsDumpKV *aux_tablet_info_uncommitted_kv = nullptr; - const mds::MdsDumpKV *aux_tablet_info_committed_kv = nullptr; - const ObTabletDumpedMediumInfo *medium_info_list = nullptr; - const share::ObTabletAutoincSeq *auto_inc_seq = nullptr; - ObTabletMemberWrapper auto_inc_seq_wrapper; if (OB_UNLIKELY(is_inited_)) { ret = OB_INIT_TWICE; LOG_WARN("init twice", K(ret), K_(is_inited)); - } - - // load or fetch - if (OB_FAIL(ret)) { - } else if (OB_FAIL(load_mds_dump_kv(arena_allocator, other.tablet_status_.uncommitted_kv_, tablet_status_uncommitted_kv))) { - LOG_WARN("failed to load mds dump kv", K(ret)); - } else if (OB_FAIL(load_mds_dump_kv(arena_allocator, other.tablet_status_.committed_kv_, tablet_status_committed_kv))) { - LOG_WARN("failed to load mds dump kv", K(ret)); - } else if (OB_FAIL(load_mds_dump_kv(arena_allocator, other.aux_tablet_info_.uncommitted_kv_, aux_tablet_info_uncommitted_kv))) { - LOG_WARN("failed to load mds dump kv", K(ret)); - } else if (OB_FAIL(load_mds_dump_kv(arena_allocator, other.aux_tablet_info_.committed_kv_, aux_tablet_info_committed_kv))) { - LOG_WARN("failed to load mds dump kv", K(ret)); - } else if (OB_FAIL(load_medium_info_list(arena_allocator, other.medium_info_list_, medium_info_list))) { - LOG_WARN("failed to load medium info list", K(ret)); - } else if (OB_FAIL(fetch_auto_inc_seq(other.auto_inc_seq_, auto_inc_seq_wrapper))) { - LOG_WARN("failed to fetch auto inc seq", K(ret)); - } else if (OB_FAIL(auto_inc_seq_wrapper.get_member(auto_inc_seq))) { - LOG_WARN("ObTabletMemberWrapper get member failed", K(ret)); - } - - // do initialization - if (OB_FAIL(ret)) { - } else if (OB_FAIL(do_init(allocator, - tablet_status_uncommitted_kv, tablet_status_committed_kv, - aux_tablet_info_uncommitted_kv, aux_tablet_info_committed_kv, - auto_inc_seq))) { - LOG_WARN("failed to do init", K(ret)); - } else if (OB_FAIL(init_with_update_medium_info(allocator, medium_info_list, other.extra_medium_info_))) { - LOG_WARN("failed to init medium info list", K(ret)); } else { - set_mem_addr(); - is_inited_ = true; - } + if (OB_FAIL(init_single_complex_addr(allocator, other.tablet_status_.uncommitted_kv_, tablet_status_.uncommitted_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, other.tablet_status_.committed_kv_, tablet_status_.committed_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, other.aux_tablet_info_.uncommitted_kv_, aux_tablet_info_.uncommitted_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, other.aux_tablet_info_.committed_kv_, aux_tablet_info_.committed_kv_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(init_single_complex_addr(allocator, other.auto_inc_seq_, auto_inc_seq_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else if (OB_FAIL(update_user_data_from_complex_addr(tablet_status_.committed_kv_, tablet_status_cache_))) { + LOG_WARN("failed to update user data cache", K(ret), "complex_addr", tablet_status_.committed_kv_); + } else if (OB_FAIL(update_user_data_from_complex_addr(aux_tablet_info_.committed_kv_, aux_tablet_info_cache_))) { + LOG_WARN("failed to update user data cache", K(ret), "complex_addr", aux_tablet_info_.committed_kv_); + } else { + const int64_t finish_medium_scn = other.extra_medium_info_.last_medium_scn_; + if (OB_FAIL(init_single_complex_addr(allocator, other.medium_info_list_, finish_medium_scn, medium_info_list_))) { + LOG_WARN("failed to init single complex addr", K(ret)); + } else { + extra_medium_info_.last_compaction_type_ = other.extra_medium_info_.last_compaction_type_; + extra_medium_info_.last_medium_scn_ = other.extra_medium_info_.last_medium_scn_; + extra_medium_info_.wait_check_flag_ = false; + } + } - ObTabletMdsData::free_mds_dump_kv(arena_allocator, tablet_status_uncommitted_kv); - ObTabletMdsData::free_mds_dump_kv(arena_allocator, tablet_status_committed_kv); - ObTabletMdsData::free_mds_dump_kv(arena_allocator, aux_tablet_info_uncommitted_kv); - ObTabletMdsData::free_mds_dump_kv(arena_allocator, aux_tablet_info_committed_kv); - ObTabletMdsData::free_medium_info_list(arena_allocator, medium_info_list); + if (OB_FAIL(ret)) { + reset(allocator); + } else { + is_inited_ = true; + } + } return ret; } -int ObTabletMdsData::init_empty_shell(const ObTabletCreateDeleteMdsUserData &tablet_status) +int ObTabletMdsData::init_empty_shell( + const ObTabletCreateDeleteMdsUserData &tablet_status) { int ret = OB_SUCCESS; @@ -440,7 +825,6 @@ int ObTabletMdsData::init_empty_shell(const ObTabletCreateDeleteMdsUserData &tab aux_tablet_info_.committed_kv_.addr_.set_none_addr(); extra_medium_info_.reset(); medium_info_list_.addr_.set_none_addr(); - auto_inc_seq_.ptr_ = nullptr; auto_inc_seq_.addr_.set_none_addr(); is_inited_ = true; @@ -449,205 +833,41 @@ int ObTabletMdsData::init_empty_shell(const ObTabletCreateDeleteMdsUserData &tab return ret; } -int ObTabletMdsData::alloc_and_new(common::ObIAllocator &allocator) -{ - int ret = OB_SUCCESS; - - if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, tablet_status_.uncommitted_kv_.ptr_))) { - LOG_WARN("failed to alloc and new", K(ret)); - } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, tablet_status_.committed_kv_.ptr_))) { - LOG_WARN("failed to alloc and new", K(ret)); - } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, aux_tablet_info_.uncommitted_kv_.ptr_))) { - LOG_WARN("failed to alloc and new", K(ret)); - } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, aux_tablet_info_.committed_kv_.ptr_))) { - LOG_WARN("failed to alloc and new", K(ret)); - } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, medium_info_list_.ptr_))) { - LOG_WARN("failed to alloc and new", K(ret)); - } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, auto_inc_seq_.ptr_))) { - LOG_WARN("failed to alloc and new", K(ret)); - } - - return ret; -} - void ObTabletMdsData::set_mem_addr() { auto_inc_seq_.addr_.set_mem_addr(0, sizeof(share::ObTabletAutoincSeq)); medium_info_list_.addr_.set_mem_addr(0, sizeof(ObTabletDumpedMediumInfo)); - aux_tablet_info_.committed_kv_.addr_.set_mem_addr(0, sizeof(mds::MdsDumpKV)); aux_tablet_info_.uncommitted_kv_.addr_.set_mem_addr(0, sizeof(mds::MdsDumpKV)); - tablet_status_.committed_kv_.addr_.set_mem_addr(0, sizeof(mds::MdsDumpKV)); + aux_tablet_info_.committed_kv_.addr_.set_mem_addr(0, sizeof(mds::MdsDumpKV)); tablet_status_.uncommitted_kv_.addr_.set_mem_addr(0, sizeof(mds::MdsDumpKV)); + tablet_status_.committed_kv_.addr_.set_mem_addr(0, sizeof(mds::MdsDumpKV)); } -int ObTabletMdsData::do_init( +int ObTabletMdsData::init_single_mds_dump_kv( common::ObIAllocator &allocator, - const mds::MdsDumpKV *tablet_status_uncommitted_kv, - const mds::MdsDumpKV *tablet_status_committed_kv, - const mds::MdsDumpKV *aux_tablet_info_uncommitted_kv, - const mds::MdsDumpKV *aux_tablet_info_committed_kv, - const share::ObTabletAutoincSeq *auto_inc_seq) + const mds::MdsDumpKV *input_kv, + ObTabletComplexAddr &kv) { int ret = OB_SUCCESS; - if (OB_ISNULL(tablet_status_uncommitted_kv) - || OB_ISNULL(tablet_status_committed_kv) - || OB_ISNULL(aux_tablet_info_uncommitted_kv) - || OB_ISNULL(aux_tablet_info_committed_kv) - || OB_ISNULL(auto_inc_seq)) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("invalid args", K(ret), - KP(tablet_status_uncommitted_kv), KP(tablet_status_committed_kv), - KP(aux_tablet_info_uncommitted_kv), KP(aux_tablet_info_committed_kv), - KP(auto_inc_seq)); - } else if (OB_FAIL(alloc_and_new(allocator))) { + if (nullptr == input_kv) { + kv.ptr_ = nullptr; + kv.addr_.set_none_addr(); + } else if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, kv.ptr_))) { LOG_WARN("failed to alloc and new", K(ret)); - } else if (OB_FAIL(tablet_status_.uncommitted_kv_.ptr_->assign(*tablet_status_uncommitted_kv, allocator))) { - LOG_WARN("failed to assign tablet status uncommitted kv", K(ret)); - } else if (OB_FAIL(tablet_status_.committed_kv_.ptr_->assign(*tablet_status_committed_kv, allocator))) { - LOG_WARN("failed to assign tablet status committed kv", K(ret)); - } else if (OB_FAIL(aux_tablet_info_.uncommitted_kv_.ptr_->assign(*aux_tablet_info_uncommitted_kv, allocator))) { - LOG_WARN("failed to assign aux tablet info uncommitted kv", K(ret)); - } else if (OB_FAIL(aux_tablet_info_.committed_kv_.ptr_->assign(*aux_tablet_info_committed_kv, allocator))) { - LOG_WARN("failed to assign aux tablet info committed kv", K(ret)); - } else if (OB_FAIL(auto_inc_seq_.ptr_->assign(allocator, *auto_inc_seq))) { - LOG_WARN("failed to assign auto inc seq kv", K(ret)); - } else if (OB_FAIL(update_user_data_from_complex_addr(tablet_status_.committed_kv_, tablet_status_cache_))) { - LOG_WARN("failed to update user data", K(ret), "complex_addr", tablet_status_.committed_kv_); - } else if (OB_FAIL(update_user_data_from_complex_addr(aux_tablet_info_.committed_kv_, aux_tablet_info_cache_))) { - LOG_WARN("failed to update user data", K(ret), "complex_addr", aux_tablet_info_.committed_kv_); + } else if (OB_FAIL(kv.ptr_->assign(*input_kv, allocator))) { + LOG_WARN("failed to copy mds dump kv", K(ret)); + } else { + kv.addr_.set_mem_addr(0, sizeof(mds::MdsDumpKV)); } if (OB_FAIL(ret)) { - reset(); - } - - return ret; -} - -int ObTabletMdsData::init_medium_info_list( - common::ObIAllocator &allocator, - const ObTabletDumpedMediumInfo *old_medium_info_list, - const compaction::ObExtraMediumInfo &old_extra_medium_info, - const int64_t finish_medium_scn, - const ObMergeType merge_type) -{ - int ret = OB_SUCCESS; - ObTabletDumpedMediumInfo *cur_medium_info_list = medium_info_list_.ptr_; - - if (OB_ISNULL(cur_medium_info_list)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("medium info list is null", K(ret), KP(cur_medium_info_list)); - } else if (OB_FAIL(cur_medium_info_list->init(allocator))) { - LOG_WARN("failed to init medium info list", K(ret)); - } else if (nullptr == old_medium_info_list) { - // no need to copy, do nothing - extra_medium_info_.reset(); - } else if (OB_FAIL(copy_medium_info_list(finish_medium_scn, *old_medium_info_list, *cur_medium_info_list))) { - LOG_WARN("failed to copy medium info list", K(ret), K(finish_medium_scn), KPC(old_medium_info_list)); - } else if (is_major_merge_type(merge_type)) { - extra_medium_info_.last_compaction_type_ = is_major_merge(merge_type) ? compaction::ObMediumCompactionInfo::MAJOR_COMPACTION : compaction::ObMediumCompactionInfo::MEDIUM_COMPACTION; - extra_medium_info_.last_medium_scn_ = finish_medium_scn; - extra_medium_info_.wait_check_flag_ = true; - } else { - extra_medium_info_.last_compaction_type_ = old_extra_medium_info.last_compaction_type_; - extra_medium_info_.last_medium_scn_ = old_extra_medium_info.last_medium_scn_; - extra_medium_info_.wait_check_flag_ = old_extra_medium_info.wait_check_flag_; - } - - if (OB_SUCC(ret)) { - LOG_INFO("succeeded to init medium info list", K(ret), - KPC(old_medium_info_list), K(old_extra_medium_info), - K(finish_medium_scn), K(merge_type), - KPC(cur_medium_info_list), K_(extra_medium_info)); - } - - return ret; -} - -int ObTabletMdsData::init_medium_info_list( - common::ObIAllocator &allocator, - const ObTabletDumpedMediumInfo *old_medium_info_list, - const ObTabletFullMediumInfo &full_memory_medium_info_list, - const compaction::ObExtraMediumInfo &old_extra_medium_info, - const int64_t finish_medium_scn) -{ - int ret = OB_SUCCESS; - ObTabletDumpedMediumInfo *cur_medium_info_list = medium_info_list_.ptr_; - - if (OB_ISNULL(cur_medium_info_list)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("medium info list is null", K(ret), KP(cur_medium_info_list)); - } else if (OB_FAIL(cur_medium_info_list->init(allocator))) { - LOG_WARN("failed to init medium info list", K(ret)); - } else if (nullptr != old_medium_info_list - && OB_FAIL(copy_medium_info_list(finish_medium_scn, *old_medium_info_list, full_memory_medium_info_list.medium_info_list_, *cur_medium_info_list))) { - LOG_WARN("failed to copy medium info", K(ret)); - } else if (nullptr == old_medium_info_list - && OB_FAIL(copy_medium_info_list(finish_medium_scn, full_memory_medium_info_list.medium_info_list_, *cur_medium_info_list))) { - LOG_WARN("failed to copy medium info", K(ret)); - } else if (OB_FAIL(compaction::ObMediumListChecker::check_continue(cur_medium_info_list->medium_info_list_))) { - LOG_WARN("failed to check medium info continuity", K(ret), K(finish_medium_scn), KPC(cur_medium_info_list)); - } else { - /* - * finish_medium_scn = last_major->get_snapshot_version() - * if finish_medium_scn < old_extra_medium_info.last_medium_scn_, means local extra_medium_info is invalid, - * use input medium list to replace - */ - if (nullptr == old_medium_info_list - || finish_medium_scn < old_extra_medium_info.last_medium_scn_ - || old_extra_medium_info.last_medium_scn_ < full_memory_medium_info_list.extra_medium_info_.last_medium_scn_) { - extra_medium_info_.last_compaction_type_ = full_memory_medium_info_list.extra_medium_info_.last_compaction_type_; - extra_medium_info_.last_medium_scn_ = full_memory_medium_info_list.extra_medium_info_.last_medium_scn_; - if (0 == full_memory_medium_info_list.extra_medium_info_.last_medium_scn_) { - extra_medium_info_.wait_check_flag_ = false; - } else { - extra_medium_info_.wait_check_flag_ = true; - } - } else { - extra_medium_info_.last_compaction_type_ = old_extra_medium_info.last_compaction_type_; - extra_medium_info_.last_medium_scn_ = old_extra_medium_info.last_medium_scn_; - extra_medium_info_.wait_check_flag_ = old_extra_medium_info.wait_check_flag_; + if (nullptr != kv.ptr_) { + allocator.free(kv.ptr_); + kv.ptr_ = nullptr; } } - if (OB_SUCC(ret)) { - LOG_INFO("succeeded to init medium info list", K(ret), - KPC(old_medium_info_list), K(old_extra_medium_info), - K(full_memory_medium_info_list), K(finish_medium_scn), - KPC(cur_medium_info_list), K_(extra_medium_info)); - } - - return ret; -} - -int ObTabletMdsData::init_with_update_medium_info( - common::ObIAllocator &allocator, - const ObTabletDumpedMediumInfo *old_medium_info_list, - const compaction::ObExtraMediumInfo &old_extra_medium_info) -{ - int ret = OB_SUCCESS; - const int64_t finish_medium_scn = old_extra_medium_info.last_medium_scn_; - ObTabletDumpedMediumInfo *cur_medium_info_list = medium_info_list_.ptr_; - - if (OB_ISNULL(cur_medium_info_list)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("medium info list is null", K(ret), KP(cur_medium_info_list)); - } else if (OB_FAIL(cur_medium_info_list->init(allocator))) { - LOG_WARN("failed to init medium info list", K(ret)); - } else if (OB_FAIL(copy_medium_info_list(finish_medium_scn, *old_medium_info_list, *cur_medium_info_list))) { - LOG_WARN("failed to copy medium info", K(ret)); - } else { - extra_medium_info_.last_compaction_type_ = old_extra_medium_info.last_compaction_type_; - extra_medium_info_.last_medium_scn_ = old_extra_medium_info.last_medium_scn_; - extra_medium_info_.wait_check_flag_ = false; - } - - if (OB_SUCC(ret)) { - LOG_INFO("succeeded to init medium info list", K(ret), KPC(old_medium_info_list), K(old_extra_medium_info), - KPC(cur_medium_info_list), K_(extra_medium_info)); - } - return ret; } @@ -765,170 +985,29 @@ int ObTabletMdsData::copy_medium_info_list( return ret; } -int ObTabletMdsData::fuse_mds_dump_node( - common::ObIAllocator &allocator, - const ObTabletComplexAddr &mds_table_data, - const ObTabletComplexAddr &base_data, - ObTabletComplexAddr &fused_data) -{ - int ret = OB_SUCCESS; - - if (OB_UNLIKELY(!fused_data.is_memory_object())) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("fused data must be memory object", K(ret), K(fused_data)); - } else if (OB_UNLIKELY(!mds_table_data.is_memory_object())) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("mds table data is not in memory", K(ret), K(mds_table_data)); - } else if (OB_UNLIKELY(!base_data.is_valid())) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("base data is invalid", K(ret), K(base_data)); - } else { - const mds::MdsDumpKV *mds_dump_kv = mds_table_data.ptr_; - const common::ObString &mds_user_data = mds_dump_kv->v_.user_data_; - - if (mds_user_data.empty()) { - // mds data in mds table is empty, use that in base data - ObArenaAllocator arena_allocator("mds_reader"); - char *buf = nullptr; - int64_t len = 0; - int64_t pos = 0; - if (base_data.is_memory_object()) { - if (OB_FAIL(fused_data.ptr_->assign(*base_data.ptr_, allocator))) { - LOG_WARN("failed to copy", K(ret), K(base_data)); - } - } else if (OB_FAIL(ObTabletObjLoadHelper::read_from_addr(arena_allocator, base_data.addr_, buf, len))) { - LOG_WARN("failed to read mds data from block addr", K(ret)); - } else if (OB_FAIL(fused_data.ptr_->deserialize(allocator, buf, len, pos))) { - LOG_WARN("failed to deserialize", K(ret)); - } - } else { - // mds data in mds table is valid, just copy it - if (OB_FAIL(fused_data.ptr_->assign(*mds_dump_kv, allocator))) { - LOG_WARN("failed to copy", K(ret), KPC(mds_dump_kv)); - } - } - } - - return ret; -} - -int ObTabletMdsData::fuse_mds_dump_node( - common::ObIAllocator &allocator, - const ObTabletMdsDumpStruct &mds_table_data, - const ObTabletMdsDumpStruct &base_data, - ObTabletMdsDumpStruct &fused_data) -{ - int ret = OB_SUCCESS; - const ObTabletComplexAddr &mds_uncommitted_kv = mds_table_data.uncommitted_kv_; - const ObTabletComplexAddr &mds_committed_kv = mds_table_data.committed_kv_; - const ObTabletComplexAddr &base_uncommitted_kv = base_data.uncommitted_kv_; - const ObTabletComplexAddr &base_committed_kv = base_data.committed_kv_; - - if (OB_FAIL(fuse_mds_dump_node(allocator, mds_uncommitted_kv, base_uncommitted_kv, fused_data.uncommitted_kv_))) { - LOG_WARN("failed to fuse complex addr", K(ret)); - } else if (OB_FAIL(fuse_mds_dump_node(allocator, mds_committed_kv, base_committed_kv, fused_data.committed_kv_))) { - LOG_WARN("failed to fuse complex addr", K(ret)); - } - - return ret; -} - -int ObTabletMdsData::fuse_mds_dump_node( - common::ObIAllocator &allocator, - const ObTabletComplexAddr &mds_table_data, - const ObTabletComplexAddr &base_data, - ObTabletComplexAddr &fused_data) -{ - int ret = OB_SUCCESS; - - if (OB_UNLIKELY(!fused_data.is_memory_object())) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("fused data must be memory object", K(ret), K(fused_data)); - } else if (OB_UNLIKELY(!mds_table_data.is_memory_object())) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("mds table data is not in memory", K(ret), K(mds_table_data)); - } else if (OB_UNLIKELY(!base_data.is_valid())) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("base data is invalid", K(ret), K(base_data)); - } else { - const share::ObTabletAutoincSeq *mds_table_auto_inc_seq = mds_table_data.ptr_; - - if (mds_table_auto_inc_seq->is_valid()) { - if (OB_FAIL(fused_data.ptr_->assign(allocator, *mds_table_auto_inc_seq))) { - LOG_WARN("failed to assign", K(ret), KPC(mds_table_auto_inc_seq)); - } - } else { - // auto inc seq in mds table is not valid, use that in base data - ObTabletMemberWrapper auto_inc_seq_wrapper; - const share::ObTabletAutoincSeq *auto_inc_seq = nullptr; - if (OB_FAIL(fetch_auto_inc_seq(base_data, auto_inc_seq_wrapper))) { - LOG_WARN("failed to fetch auto inc seq", K(ret), K(base_data)); - } else if (OB_FAIL(auto_inc_seq_wrapper.get_member(auto_inc_seq))) { - LOG_WARN("failed to get member", K(ret)); - } else if (OB_FAIL(fused_data.ptr_->assign(allocator, *auto_inc_seq))) { - LOG_WARN("failed to assign", K(ret), KPC(auto_inc_seq)); - } - } - } - - return ret; -} - -int ObTabletMdsData::fuse_mds_dump_node( - common::ObIAllocator &allocator, - const int64_t finish_medium_scn, - const ObTabletComplexAddr &mds_table_data, - const ObTabletComplexAddr &base_data, - ObTabletComplexAddr &fused_data) -{ - int ret = OB_SUCCESS; - - if (OB_UNLIKELY(!fused_data.is_memory_object())) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("fused data must be memory object", K(ret), K(fused_data)); - } else if (OB_UNLIKELY(!mds_table_data.is_memory_object())) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("mds table data is not in memory", K(ret), K(mds_table_data)); - } else if (OB_UNLIKELY(!base_data.is_valid())) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("base data is invalid", K(ret), K(base_data)); - } else { - const ObTabletDumpedMediumInfo *mds_table_medium_info_list = mds_table_data.ptr_; - const ObTabletDumpedMediumInfo *base_medium_info_list = base_data.ptr_; - ObTabletDumpedMediumInfo *fused_medium_info_list = fused_data.ptr_; - - if (OB_FAIL(load_medium_info_list(allocator, base_data, base_medium_info_list))) { - LOG_WARN("failed to laod medium info list", K(ret), K(base_data)); - } else if (OB_ISNULL(base_medium_info_list)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected error, base medium info list is null", K(ret), KP(base_medium_info_list)); - } else if (OB_FAIL(copy_medium_info_list(finish_medium_scn, *base_medium_info_list, *fused_medium_info_list))) { - LOG_WARN("failed to copy base medium info list", K(ret)); - } else if (OB_FAIL(copy_medium_info_list(finish_medium_scn, *mds_table_medium_info_list, *fused_medium_info_list))) { - LOG_WARN("failed to copy mds table medium info list", K(ret)); - } - - ObTabletMdsData::free_medium_info_list(allocator, base_medium_info_list); - } - - return ret; -} - int ObTabletMdsData::load_mds_dump_kv( common::ObIAllocator &allocator, const ObTabletComplexAddr &complex_addr, const mds::MdsDumpKV *&kv) { int ret = OB_SUCCESS; + kv = nullptr; mds::MdsDumpKV *ptr = nullptr; - if (OB_UNLIKELY(!complex_addr.is_valid() || complex_addr.is_none_object())) { + 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()) { - if (OB_FAIL(ptr->assign(*complex_addr.ptr_, allocator))) { + const mds::MdsDumpKV *src_kv = complex_addr.ptr_; + if (src_kv->v_.user_data_.empty()) { + free_mds_dump_kv(allocator, ptr); + ptr = nullptr; + LOG_INFO("read empty user data", K(ret), K(complex_addr)); + } else if (OB_FAIL(ptr->assign(*src_kv, allocator))) { LOG_WARN("failed to copy mds dump kv", K(ret)); } } else if (complex_addr.is_disk_object()) { @@ -941,6 +1020,16 @@ int ObTabletMdsData::load_mds_dump_kv( LOG_WARN("failed to read from addr", K(ret), K(addr)); } else if (OB_FAIL(ptr->deserialize(allocator, buf, len, pos))) { LOG_WARN("failed to deserialize", K(ret)); + } else { + // for compat logic + // if user data is empty, we consider that nothing is read from disk, + // and ptr should be set to null + const mds::MdsDumpNode &dump_node = ptr->v_; + if (dump_node.user_data_.empty()) { + free_mds_dump_kv(allocator, ptr); + ptr = nullptr; + LOG_INFO("read empty user data", K(ret), K(complex_addr)); + } } } else { ret = OB_ERR_UNEXPECTED; @@ -964,24 +1053,32 @@ int ObTabletMdsData::load_medium_info_list( const ObTabletDumpedMediumInfo *&medium_info_list) { int ret = OB_SUCCESS; + medium_info_list = nullptr; ObTabletDumpedMediumInfo *ptr = nullptr; 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_none_object()) { - if (OB_FAIL(ptr->init(allocator))) { - LOG_WARN("failed to init medium info list", K(ret)); - } } else if (complex_addr.is_memory_object()) { - if (OB_FAIL(ptr->assign(*complex_addr.ptr_, allocator))) { + const ObTabletDumpedMediumInfo *src_medium_info = complex_addr.ptr_; + if (src_medium_info->medium_info_list_.empty()) { + free_medium_info_list(allocator, ptr); + ptr = nullptr; + LOG_INFO("read empty medium info", K(ret), K(complex_addr)); + } else if (OB_FAIL(ptr->assign(*src_medium_info, allocator))) { LOG_INFO("failed to copy medium info list", K(ret)); } } else if (complex_addr.is_disk_object()) { if (OB_FAIL(read_medium_info(allocator, complex_addr.addr_, ptr->medium_info_list_))) { LOG_WARN("failed to read medium info", K(ret), "addr", complex_addr.addr_); + } else if (ptr->medium_info_list_.empty()) { + free_medium_info_list(allocator, ptr); + ptr = nullptr; + LOG_INFO("read empty medium info", K(ret), K(complex_addr)); } else { std::sort(ptr->medium_info_list_.begin(), ptr->medium_info_list_.end(), ObTabletDumpedMediumInfo::compare); @@ -1004,6 +1101,69 @@ int ObTabletMdsData::load_medium_info_list( return ret; } +int ObTabletMdsData::load_auto_inc_seq( + common::ObIAllocator &allocator, + const ObTabletComplexAddr &complex_addr, + const share::ObTabletAutoincSeq *&auto_inc_seq) +{ + int ret = OB_SUCCESS; + auto_inc_seq = nullptr; + share::ObTabletAutoincSeq *ptr = nullptr; + + 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 share::ObTabletAutoincSeq *src_auto_inc_seq = complex_addr.ptr_; + if (!src_auto_inc_seq->is_valid()) { + free_auto_inc_seq(allocator, ptr); + ptr = nullptr; + LOG_INFO("read empty auto inc seq", K(ret), K(complex_addr)); + } else if (OB_FAIL(ptr->assign(allocator, *src_auto_inc_seq))) { + LOG_WARN("failed to copy auto inc seq", K(ret)); + } + } else if (complex_addr.is_disk_object()) { + ObTabletMemberWrapper wrapper; + ObStorageMetaHandle handle; + ObStorageMetaKey meta_key(MTL_ID(), complex_addr.addr_); + const ObTablet *tablet = nullptr; // no use here + const share::ObTabletAutoincSeq *auto_inc_seq_cache = nullptr; + if (OB_FAIL(OB_STORE_CACHE.get_storage_meta_cache().get_meta(ObStorageMetaValue::MetaType::AUTO_INC_SEQ, + meta_key, handle, tablet))) { + LOG_WARN("get meta failed", K(ret), K(meta_key)); + } else if (OB_FAIL(wrapper.set_cache_handle(handle))) { + LOG_WARN("wrapper set cache handle failed", K(ret), K(meta_key), K(complex_addr)); + } else if (OB_ISNULL(auto_inc_seq_cache = wrapper.get_member())) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected null member", K(ret)); + } else if (!auto_inc_seq_cache->is_valid()) { + // no need to copy + free_auto_inc_seq(allocator, ptr); + ptr = nullptr; + LOG_INFO("empty auto inc seq", K(ret)); + } else if (OB_FAIL(ptr->assign(allocator, *auto_inc_seq_cache))) { + LOG_WARN("failed to copy", K(ret)); + } + } else { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected complex addr type", K(ret), K(complex_addr)); + } + + if (OB_FAIL(ret)) { + if (nullptr != ptr) { + allocator.free(ptr); + } + } else { + auto_inc_seq = ptr; + } + + return ret; +} + void ObTabletMdsData::free_mds_dump_kv( common::ObIAllocator &allocator, const mds::MdsDumpKV *kv) @@ -1014,6 +1174,16 @@ void ObTabletMdsData::free_mds_dump_kv( } } +void ObTabletMdsData::free_auto_inc_seq( + common::ObIAllocator &allocator, + const share::ObTabletAutoincSeq *auto_inc_seq) +{ + if (nullptr != auto_inc_seq) { + auto_inc_seq->share::ObTabletAutoincSeq::~ObTabletAutoincSeq(); + allocator.free(const_cast(auto_inc_seq)); + } +} + void ObTabletMdsData::free_medium_info_list( common::ObIAllocator &allocator, const ObTabletDumpedMediumInfo *medium_info_list) @@ -1076,32 +1246,6 @@ int ObTabletMdsData::read_medium_info( return ret; } -int ObTabletMdsData::fetch_auto_inc_seq( - const ObTabletComplexAddr &auto_inc_seq_addr, - ObTabletMemberWrapper &wrapper) -{ - int ret = OB_SUCCESS; - - if (OB_UNLIKELY(!auto_inc_seq_addr.is_valid())) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("invalid auto inc seq addr", K(ret)); - } else if (auto_inc_seq_addr.is_memory_object()) { - wrapper.set_member(auto_inc_seq_addr.get_ptr()); - } else { - ObStorageMetaHandle handle; - ObStorageMetaKey meta_key(MTL_ID(), auto_inc_seq_addr.addr_); - const ObTablet *tablet = nullptr; // no use here - if (OB_FAIL(OB_STORE_CACHE.get_storage_meta_cache().get_meta(ObStorageMetaValue::MetaType::AUTO_INC_SEQ, - meta_key, handle, tablet))) { - LOG_WARN("get meta failed", K(ret), K(meta_key)); - } else if (OB_FAIL(wrapper.set_cache_handle(handle))) { - LOG_WARN("wrapper set cache handle failed", K(ret), K(meta_key), K(auto_inc_seq_addr)); - } - } - - return ret; -} - int ObTabletMdsData::build_mds_data( common::ObArenaAllocator &allocator, const share::ObTabletAutoincSeq &auto_inc_seq, @@ -1125,7 +1269,7 @@ int ObTabletMdsData::build_mds_data( const compaction::ObMediumCompactionInfoList::MediumInfoList &medium_info_list = info_list.get_list(); if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, mds_data.medium_info_list_.ptr_))) { LOG_WARN("failed to alloc and new mda data medium info list", K(ret)); - } else if (OB_FAIL(mds_data.medium_info_list_.ptr_->init(allocator))) { + } else if (OB_FAIL(mds_data.medium_info_list_.ptr_->init_for_first_creation(allocator))) { LOG_WARN("failed to init mda data medium info list", K(ret)); } @@ -1375,7 +1519,7 @@ int ObTabletMdsData::build_auto_inc_seq( } int ObTabletMdsData::set_tablet_status( - ObArenaAllocator *allocator, + common::ObIAllocator &allocator, const ObTabletStatus::Status &tablet_status, const ObTabletMdsUserDataType &data_type) { @@ -1385,7 +1529,7 @@ int ObTabletMdsData::set_tablet_status( user_data.data_type_ = data_type; const int64_t length = user_data.get_serialize_size(); - char *buffer = static_cast(allocator->alloc(length)); + char *buffer = static_cast(allocator.alloc(length)); int64_t pos = 0; if (OB_ISNULL(buffer)) { ret = OB_ALLOCATE_MEMORY_FAILED; @@ -1396,13 +1540,13 @@ int ObTabletMdsData::set_tablet_status( LOG_WARN("failed to assign tablet status cache", K(ret)); } else { mds::MdsDumpNode &node = tablet_status_.committed_kv_.get_ptr()->v_; - node.allocator_ = allocator; + node.allocator_ = &allocator; node.user_data_.assign(buffer, length); } if (OB_FAIL(ret)) { if (nullptr != buffer) { - allocator->free(buffer); + allocator.free(buffer); } } return ret; diff --git a/src/storage/tablet/ob_tablet_mds_data.h b/src/storage/tablet/ob_tablet_mds_data.h index d3689d348..271a9a3dc 100644 --- a/src/storage/tablet/ob_tablet_mds_data.h +++ b/src/storage/tablet/ob_tablet_mds_data.h @@ -18,6 +18,7 @@ #include "lib/string/ob_string.h" #include "share/ob_tablet_autoincrement_param.h" #include "storage/compaction/ob_compaction_util.h" +#include "storage/compaction/ob_extra_medium_info.h" #include "storage/multi_data_source/adapter_define/mds_dump_node.h" #include "storage/tablet/ob_tablet_complex_addr.h" #include "storage/tablet/ob_tablet_member_wrapper.h" @@ -35,7 +36,6 @@ namespace compaction class ObMediumCompactionInfoKey; class ObMediumCompactionInfo; class ObMediumCompactionInfoList; -class ObExtraMediumInfo; } namespace storage @@ -71,21 +71,25 @@ public: ObTabletMdsData &operator=(const ObTabletMdsData&) = delete; public: void reset(); - int init(common::ObIAllocator &allocator); - int init( + int init_for_first_creation(common::ObIAllocator &allocator); + int init_with_tablet_status( + common::ObIAllocator &allocator, + const ObTabletStatus::Status &tablet_status, + const ObTabletMdsUserDataType &data_type); + int init_by_full_memory_mds_data( common::ObIAllocator &allocator, const ObTabletFullMemoryMdsData &full_memory_mds_data); - int init( + int init_for_mds_table_dump( common::ObIAllocator &allocator, const ObTabletMdsData &mds_table_data, const ObTabletMdsData &base_data, const int64_t finish_medium_scn); - int init( + int init_for_evict_medium_info( common::ObIAllocator &allocator, const ObTabletMdsData &other, const int64_t finish_medium_scn, const ObMergeType merge_type = ObMergeType::MERGE_TYPE_MAX); - int init( + int init_for_merge_with_full_mds_data( common::ObIAllocator &allocator, const ObTabletMdsData &other, const ObTabletFullMediumInfo &full_memory_medium_info_list, @@ -93,11 +97,8 @@ public: int init_with_update_medium_info( common::ObIAllocator &allocator, const ObTabletMdsData &other); - int init_empty_shell(const ObTabletCreateDeleteMdsUserData &tablet_status); - int set_tablet_status( - ObArenaAllocator *allocator, - const ObTabletStatus::Status &tablet_status, - const ObTabletMdsUserDataType &data_type); + int init_empty_shell( + const ObTabletCreateDeleteMdsUserData &tablet_status); bool is_valid() const; void set_mem_addr(); public: @@ -122,15 +123,19 @@ public: common::ObIAllocator &allocator, const ObTabletComplexAddr &complex_addr, const ObTabletDumpedMediumInfo *&medium_info_list); + static int load_auto_inc_seq( + common::ObIAllocator &allocator, + const ObTabletComplexAddr &complex_addr, + const share::ObTabletAutoincSeq *&auto_inc_seq); static void free_mds_dump_kv( common::ObIAllocator &allocator, const mds::MdsDumpKV *kv); + static void free_auto_inc_seq( + common::ObIAllocator &allocator, + const share::ObTabletAutoincSeq *auto_inc_seq); static void free_medium_info_list( common::ObIAllocator &allocator, const ObTabletDumpedMediumInfo *medium_info_list); - static int fetch_auto_inc_seq( - const ObTabletComplexAddr &auto_inc_seq_addr, - ObTabletMemberWrapper &wrapper); static int build_tablet_status( common::ObArenaAllocator &allocator, const ObTabletTxMultiSourceDataUnit &tx_data, @@ -156,50 +161,60 @@ public: const compaction::ObMediumCompactionInfoList &info_list, ObTabletMdsData &mds_data); private: - int alloc_and_new(common::ObIAllocator &allocator); - int do_init( + void reset(common::ObIAllocator &allocator); + int set_tablet_status( common::ObIAllocator &allocator, - const mds::MdsDumpKV *tablet_status_uncommitted_kv, - const mds::MdsDumpKV *tablet_status_committed_kv, - const mds::MdsDumpKV *aux_tablet_info_uncommitted_kv, - const mds::MdsDumpKV *aux_tablet_info_committed_kv, - const share::ObTabletAutoincSeq *auto_inc_seq); - int init_medium_info_list( + const ObTabletStatus::Status &tablet_status, + const ObTabletMdsUserDataType &data_type); + static int init_single_complex_addr( common::ObIAllocator &allocator, - const ObTabletDumpedMediumInfo *old_medium_info_list, - const compaction::ObExtraMediumInfo &old_extra_medium_info, - const int64_t finish_medium_scn = 0, - const ObMergeType merge_type = ObMergeType::MERGE_TYPE_MAX); - int init_medium_info_list( + const ObTabletComplexAddr &src_addr, + ObTabletComplexAddr &dst_addr); + static int init_single_complex_addr( common::ObIAllocator &allocator, - const ObTabletDumpedMediumInfo *old_medium_info_list, - const ObTabletFullMediumInfo &full_memory_medium_info_list, - const compaction::ObExtraMediumInfo &old_extra_medium_info, - const int64_t finish_medium_scn); - int init_with_update_medium_info( + const ObTabletComplexAddr &src_addr, + ObTabletComplexAddr &dst_addr); + static int init_single_complex_addr( common::ObIAllocator &allocator, - const ObTabletDumpedMediumInfo *old_medium_info_list, - const compaction::ObExtraMediumInfo &old_extra_medium_info); - static int fuse_mds_dump_node( + const ObTabletComplexAddr &src_addr, + const int64_t finish_medium_scn, + ObTabletComplexAddr &dst_addr); + static int init_single_complex_addr( + common::ObIAllocator &allocator, + const mds::MdsDumpKV &src_data, + ObTabletComplexAddr &dst_addr); + static int init_single_complex_addr( + common::ObIAllocator &allocator, + const share::ObTabletAutoincSeq &src_data, + ObTabletComplexAddr &dst_addr); + static int init_single_complex_addr( + common::ObIAllocator &allocator, + const ObTabletDumpedMediumInfo &src_data, + ObTabletComplexAddr &dst_addr); + static int init_single_complex_addr_and_extra_info( + common::ObIAllocator &allocator, + const ObTabletComplexAddr &src_addr, + const compaction::ObExtraMediumInfo &src_addr_extra_info, + const ObTabletDumpedMediumInfo &src_data, + const compaction::ObExtraMediumInfo &src_data_extra_info, + const int64_t finish_medium_scn, + ObTabletComplexAddr &dst_addr, + compaction::ObExtraMediumInfo &dst_extra_info); + static int init_single_complex_addr( common::ObIAllocator &allocator, const ObTabletComplexAddr &mds_table_data, const ObTabletComplexAddr &base_data, ObTabletComplexAddr &fused_data); - static int fuse_mds_dump_node( - common::ObIAllocator &allocator, - const ObTabletMdsDumpStruct &mds_table_data, - const ObTabletMdsDumpStruct &base_data, - ObTabletMdsDumpStruct &fused_data); - static int fuse_mds_dump_node( + static int init_single_complex_addr( common::ObIAllocator &allocator, const ObTabletComplexAddr &mds_table_data, const ObTabletComplexAddr &base_data, ObTabletComplexAddr &fused_data); - static int fuse_mds_dump_node( + static int init_single_complex_addr( common::ObIAllocator &allocator, - const int64_t finish_medium_scn, const ObTabletComplexAddr &mds_table_data, const ObTabletComplexAddr &base_data, + const int64_t finish_medium_scn, ObTabletComplexAddr &fused_data); static int read_medium_info( common::ObIAllocator &allocator, @@ -214,6 +229,10 @@ private: const ObTabletDumpedMediumInfo &input_medium_info_list1, const ObTabletDumpedMediumInfo &input_medium_info_list2, ObTabletDumpedMediumInfo &medium_info_list); + static int init_single_mds_dump_kv( + common::ObIAllocator &allocator, + const mds::MdsDumpKV *input_kv, + ObTabletComplexAddr &kv); template static int update_user_data_from_complex_addr( const ObTabletComplexAddr &complex_addr, @@ -238,9 +257,11 @@ int ObTabletMdsData::update_user_data_from_complex_addr( { int ret = common::OB_SUCCESS; - if (OB_UNLIKELY(!complex_addr.is_memory_object())) { + if (OB_UNLIKELY(!complex_addr.is_memory_object() && !complex_addr.is_none_object())) { ret = common::OB_INVALID_ARGUMENT; - STORAGE_LOG(WARN, "complex addr is not memory type", K(ret), K(complex_addr)); + STORAGE_LOG(WARN, "complex addr is not memory or none type", K(ret), K(complex_addr)); + } else if (complex_addr.is_none_object()) { + // do nothing } else { const mds::MdsDumpKV *kv = complex_addr.ptr_; const common::ObString &str = kv->v_.user_data_; diff --git a/src/storage/tablet/ob_tablet_mds_node_dump_operator.cpp b/src/storage/tablet/ob_tablet_mds_node_dump_operator.cpp index 33cedaae4..91e1a9caa 100644 --- a/src/storage/tablet/ob_tablet_mds_node_dump_operator.cpp +++ b/src/storage/tablet/ob_tablet_mds_node_dump_operator.cpp @@ -18,6 +18,7 @@ #include "share/ob_tablet_autoincrement_param.h" #include "storage/tablet/ob_tablet_mds_data.h" #include "storage/tablet/ob_tablet_create_delete_mds_user_data.h" +#include "storage/tablet/ob_tablet_obj_load_helper.h" #include "storage/multi_data_source/adapter_define/mds_dump_node.h" #include "storage/multi_data_source/compile_utility/mds_dummy_key.h" #include "storage/multi_data_source/mds_table_handle.h" @@ -43,6 +44,8 @@ int ObTabletDumpMdsNodeOperator::dump>::value; const mds::MdsDumpKey &key = kv.k_; const mds::MdsDumpNode &node = kv.v_; + ObTabletComplexAddr &uncommitted_tablet_status = mds_data_.tablet_status_.uncommitted_kv_; + ObTabletComplexAddr &committed_tablet_status = mds_data_.tablet_status_.committed_kv_; if (table_id == key.mds_table_id_ && unit_id == key.mds_unit_id_) { const mds::TwoPhaseCommitState &state = node.status_.get_state(); @@ -51,13 +54,29 @@ int ObTabletDumpMdsNodeOperator::dumpassign(kv, allocator_))) { - LOG_WARN("failed to copy mds dump kv", K(ret)); + { + if (!uncommitted_tablet_status.is_memory_object()) { + if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator_, uncommitted_tablet_status.ptr_))) { + LOG_WARN("failed to alloc and new", K(ret)); + } + } + if (OB_FAIL(ret)) { + } else if (OB_FAIL(uncommitted_tablet_status.ptr_->assign(kv, allocator_))) { + LOG_WARN("failed to copy mds dump kv", K(ret)); + } } break; case mds::TwoPhaseCommitState::ON_COMMIT: - if (OB_FAIL(mds_data_.tablet_status_.committed_kv_.ptr_->assign(kv, allocator_))) { - LOG_WARN("failed to copy mds dump kv", K(ret)); + { + if (!committed_tablet_status.is_memory_object()) { + if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator_, committed_tablet_status.ptr_))) { + LOG_WARN("failed to alloc and new", K(ret)); + } + } + if (OB_FAIL(ret)) { + } else if (OB_FAIL(committed_tablet_status.ptr_->assign(kv, allocator_))) { + LOG_WARN("failed to copy mds dump kv", K(ret)); + } } break; case mds::TwoPhaseCommitState::STATE_END: @@ -82,6 +101,8 @@ int ObTabletDumpMdsNodeOperator::dump constexpr uint8_t unit_id = mds::TupleTypeIdx>::value; const mds::MdsDumpKey &key = kv.k_; const mds::MdsDumpNode &node = kv.v_; + ObTabletComplexAddr &uncommitted_aux_tablet_info = mds_data_.aux_tablet_info_.uncommitted_kv_; + ObTabletComplexAddr &committed_aux_tablet_info = mds_data_.aux_tablet_info_.committed_kv_; if (table_id == key.mds_table_id_ && unit_id == key.mds_unit_id_) { const mds::TwoPhaseCommitState &state = node.status_.get_state(); @@ -90,13 +111,29 @@ int ObTabletDumpMdsNodeOperator::dump case mds::TwoPhaseCommitState::BEFORE_PREPARE: case mds::TwoPhaseCommitState::ON_ABORT: case mds::TwoPhaseCommitState::ON_PREPARE: - if (OB_FAIL(mds_data_.aux_tablet_info_.uncommitted_kv_.ptr_->assign(kv, allocator_))) { - LOG_WARN("failed to copy mds dump kv", K(ret)); + { + if (!uncommitted_aux_tablet_info.is_memory_object()) { + if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator_, uncommitted_aux_tablet_info.ptr_))) { + LOG_WARN("failed to alloc and new", K(ret)); + } + } + if (OB_FAIL(ret)) { + } else if (OB_FAIL(uncommitted_aux_tablet_info.ptr_->assign(kv, allocator_))) { + LOG_WARN("failed to copy mds dump kv", K(ret)); + } } break; case mds::TwoPhaseCommitState::ON_COMMIT: - if (OB_FAIL(mds_data_.aux_tablet_info_.committed_kv_.ptr_->assign(kv, allocator_))) { - LOG_WARN("failed to copy mds dump kv", K(ret)); + { + if (!committed_aux_tablet_info.is_memory_object()) { + if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator_, committed_aux_tablet_info.ptr_))) { + LOG_WARN("failed to alloc and new", K(ret)); + } + } + if (OB_FAIL(ret)) { + } else if (OB_FAIL(committed_aux_tablet_info.ptr_->assign(kv, allocator_))) { + LOG_WARN("failed to copy mds dump kv", K(ret)); + } } break; case mds::TwoPhaseCommitState::STATE_END: @@ -121,16 +158,23 @@ int ObTabletDumpMdsNodeOperator::dump( constexpr uint8_t unit_id = mds::TupleTypeIdx>::value; const mds::MdsDumpKey &key = kv.k_; const mds::MdsDumpNode &node = kv.v_; + ObTabletComplexAddr &auto_inc_seq = mds_data_.auto_inc_seq_; if (table_id == key.mds_table_id_ && unit_id == key.mds_unit_id_) { const mds::TwoPhaseCommitState &state = node.status_.get_state(); const common::ObString &user_data = kv.v_.user_data_; int64_t pos = 0; - share::ObTabletAutoincSeq *auto_inc_seq = mds_data_.auto_inc_seq_.ptr_; if (OB_UNLIKELY(state != mds::TwoPhaseCommitState::ON_COMMIT)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("invalid state", K(ret), K(state)); - } else if (OB_FAIL(auto_inc_seq->deserialize(allocator_, user_data.ptr(), user_data.length(), pos))) { + } else if (!auto_inc_seq.is_memory_object()) { + if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator_, auto_inc_seq.ptr_))) { + LOG_WARN("failed to alloc and new", K(ret)); + } + } + + if (OB_FAIL(ret)) { + } else if (OB_FAIL(auto_inc_seq.ptr_->deserialize(allocator_, user_data.ptr(), user_data.length(), pos))) { LOG_WARN("failed to deserialize", K(ret)); } else { dumped = true; @@ -148,14 +192,23 @@ int ObTabletDumpMdsNodeOperator::dump>::value; const mds::MdsDumpKey &key = kv.k_; const mds::MdsDumpNode &node = kv.v_; + ObTabletComplexAddr &medium_info_list = mds_data_.medium_info_list_; if (table_id == key.mds_table_id_ && unit_id == key.mds_unit_id_) { const mds::TwoPhaseCommitState &state = node.status_.get_state(); - ObTabletDumpedMediumInfo *medium_info_list = mds_data_.medium_info_list_.ptr_; if (OB_UNLIKELY(state != mds::TwoPhaseCommitState::ON_COMMIT)) { ret = OB_SUCCESS; LOG_WARN("invalid state", K(ret), K(state)); - } else if (OB_FAIL(medium_info_list->append(key, node))) { + } else if (!medium_info_list.is_memory_object()) { + if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator_, medium_info_list.ptr_))) { + LOG_WARN("failed to alloc and new", K(ret)); + } else if (OB_FAIL(medium_info_list.ptr_->init_for_first_creation(allocator_))) { + LOG_WARN("failed to init medium info list", K(ret)); + } + } + + if (OB_FAIL(ret)) { + } else if (OB_FAIL(medium_info_list.ptr_->append(key, node))) { LOG_WARN("failed to copy mds dump node", K(ret)); } else { dumped = true; diff --git a/src/storage/tablet/ob_tablet_medium_info_reader.cpp b/src/storage/tablet/ob_tablet_medium_info_reader.cpp index 676195739..cae85c5df 100644 --- a/src/storage/tablet/ob_tablet_medium_info_reader.cpp +++ b/src/storage/tablet/ob_tablet_medium_info_reader.cpp @@ -46,35 +46,32 @@ ObTabletMediumInfoReader::~ObTabletMediumInfoReader() int ObTabletMediumInfoReader::init(common::ObArenaAllocator &allocator) { int ret = OB_SUCCESS; + const share::ObLSID &ls_id = tablet_.get_tablet_meta().ls_id_; + const common::ObTabletID &tablet_id = tablet_.get_tablet_meta().tablet_id_; if (OB_UNLIKELY(is_inited_)) { ret = OB_INIT_TWICE; - LOG_WARN("init twice", K(ret), K_(is_inited)); + LOG_WARN("init twice", K(ret), K(ls_id), K(tablet_id), K_(is_inited)); } else { mds::MdsTableHandle mds_table; const ObTabletDumpedMediumInfo *dumped_medium_info = nullptr; if (OB_FAIL(tablet_.inner_get_mds_table(mds_table, false/*not_exist_create*/))) { if (OB_ENTRY_NOT_EXIST != ret) { - LOG_WARN("failed to get mds table", K(ret)); + LOG_WARN("failed to get mds table", K(ret), K(ls_id), K(tablet_id)); } else { mds_end_ = true; // no mds table, directly iter end ret = OB_SUCCESS; - LOG_DEBUG("no mds table", K(ret), K_(mds_end)); + LOG_DEBUG("no mds table", K(ret), K(ls_id), K(tablet_id), K_(mds_end)); } } else if (OB_FAIL(mds_iter_.init(mds_table))) { - LOG_WARN("failed to init mds iter", K(ret)); + LOG_WARN("failed to init mds iter", K(ret), K(ls_id), K(tablet_id)); } if (OB_FAIL(ret)) { } else if (OB_FAIL(ObTabletMdsData::load_medium_info_list(allocator, tablet_.mds_data_.medium_info_list_, dumped_medium_info))) { - LOG_WARN("failed to load medium info list", K(ret), - "ls_id", tablet_.get_tablet_meta().ls_id_, - "tablet_id", tablet_.get_tablet_meta().tablet_id_); - } else if (OB_ISNULL(dumped_medium_info)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected error, medium info is null", K(ret), KP(dumped_medium_info)); - } else if (OB_FAIL(dump_iter_.init(allocator, *dumped_medium_info))) { - LOG_WARN("failed to init dumped iter", K(ret)); + LOG_WARN("failed to load medium info list", K(ret), K(ls_id), K(tablet_id)); + } else if (OB_FAIL(dump_iter_.init(allocator, dumped_medium_info))) { + LOG_WARN("failed to init dumped iter", K(ret), K(ls_id), K(tablet_id)); } else { allocator_ = &allocator; } diff --git a/src/storage/tablet/ob_tablet_persister.cpp b/src/storage/tablet/ob_tablet_persister.cpp index dd7af3bc4..98335352a 100644 --- a/src/storage/tablet/ob_tablet_persister.cpp +++ b/src/storage/tablet/ob_tablet_persister.cpp @@ -69,6 +69,12 @@ void ObTabletTransformArg::reset() auto_inc_seq_addr_.reset(); tablet_status_cache_.reset(); aux_tablet_info_cache_.reset(); + ddl_kvs_ = nullptr; + ddl_kv_count_ = 0; + for (int64_t i = 0; i < MAX_MEMSTORE_CNT; ++i) { + memtables_[i] = nullptr; + } + memtable_count_ = 0; } bool ObTabletTransformArg::is_valid() const @@ -92,7 +98,7 @@ int ObTabletPersister::persist_and_transform_tablet( { TIMEGUARD_INIT(STORAGE, 10_ms); int ret = OB_SUCCESS; - common::ObArenaAllocator allocator(common::ObMemAttr(MTL_ID(), "PesistTranf")); + common::ObArenaAllocator allocator(common::ObMemAttr(MTL_ID(), "PATF")); common::ObSEArray tablet_meta_write_ctxs; common::ObSEArray sstable_meta_write_ctxs; @@ -176,13 +182,13 @@ int ObTabletPersister::convert_tablet_to_mem_arg( } return ret; } + int ObTabletPersister::convert_tablet_to_disk_arg( common::ObArenaAllocator &allocator, const ObTablet &tablet, common::ObIArray &tablet_meta_write_ctxs, common::ObIArray &sstable_meta_write_ctxs, ObTabletPoolType &type, - ObTabletMemberWrapper &auto_inc_seq, ObTabletTransformArg &arg) { TIMEGUARD_INIT(STORAGE, 10_ms); @@ -191,18 +197,7 @@ int ObTabletPersister::convert_tablet_to_disk_arg( common::ObSEArray write_infos; // fetch member wrapper - ObTabletMemberWrapper table_store; - // fetch member function - FetchTableStore fetch_table_store = - std::bind(&ObTablet::fetch_table_store, &tablet, _1); - FetchAutoincSeq fetch_auto_inc_seq = - std::bind(&ObTabletMdsData::fetch_auto_inc_seq, std::cref(tablet.mds_data_.auto_inc_seq_), _1); - - // load member - const ObStorageSchema *storage_schema = nullptr; - // load member function - LoadStorageSchema load_storage_schema = - std::bind(&ObTablet::load_storage_schema, &tablet, _1, _2); + ObTabletMemberWrapper table_store_wrapper; // load new mds data const ObTabletComplexAddr &uncommitted_tablet_status_addr = tablet.mds_data_.tablet_status_.uncommitted_kv_; @@ -219,40 +214,36 @@ int ObTabletPersister::convert_tablet_to_disk_arg( LOG_WARN("fail to assign tablet meta", K(ret), K(tablet)); } else if (FALSE_IT(arg.rowkey_read_info_ptr_ = tablet.rowkey_read_info_)) { } else if (FALSE_IT(arg.extra_medium_info_ = tablet.mds_data_.extra_medium_info_)) { - } else if (CLICK_FAIL(fetch_wrapper_and_write_info(allocator, fetch_table_store, table_store, write_infos, sstable_meta_write_ctxs))) { - LOG_WARN("fail to fetch table store wrapper and write info", K(ret)); - } else if (CLICK_FAIL(fetch_wrapper_and_write_info( - allocator, fetch_auto_inc_seq, auto_inc_seq, write_infos, tablet_meta_write_ctxs))) { - LOG_WARN("fail to fetch auto inc seq wrapper and write info", K(ret)); - } else if (FALSE_IT(arg.auto_inc_seq_ptr_ = auto_inc_seq.get_member())) { + } else if (CLICK_FAIL(fetch_table_store_and_write_info(tablet, allocator, table_store_wrapper, write_infos, sstable_meta_write_ctxs))) { + LOG_WARN("fail to fetch table store and write info", K(ret)); + } else if (CLICK_FAIL(load_auto_inc_seq_and_write_info(allocator, tablet.mds_data_.auto_inc_seq_, arg.auto_inc_seq_ptr_, write_infos, arg.auto_inc_seq_addr_))) { + LOG_WARN("fail to load auto inc seq and write info", K(ret)); } else if (FALSE_IT(arg.ddl_kvs_ = tablet.ddl_kvs_)) { } else if (FALSE_IT(arg.ddl_kv_count_ = tablet.ddl_kv_count_)) { } else if (FALSE_IT(arg.memtable_count_ = tablet.memtable_count_)) { } else if (OB_ISNULL(MEMCPY(arg.memtables_, tablet.memtables_, sizeof(arg.memtables_)))) { ret = OB_ERR_UNEXPECTED; LOG_WARN("fail to memcpy memtables", K(ret), KP(arg.memtables_), KP(tablet.memtables_)); - } else if (CLICK_FAIL(load_member_and_write_info( - allocator, load_storage_schema, storage_schema, write_infos))) { - LOG_WARN("fail to load storage schema and write info", K(ret)); - } else if (CLICK_FAIL(load_dump_kv_and_fill_write_info(allocator, uncommitted_tablet_status_addr, write_infos))) { + } else if (CLICK_FAIL(load_storage_schema_and_fill_write_info(tablet, allocator, write_infos))) { + LOG_WARN("fail to load storage schema and fill write info", K(ret)); + } else if (CLICK_FAIL(load_dump_kv_and_fill_write_info(allocator, uncommitted_tablet_status_addr, write_infos, arg.tablet_status_uncommitted_kv_addr_))) { LOG_WARN("fail to load tablet status uncommitted kv", K(ret), K(uncommitted_tablet_status_addr)); - } else if (CLICK_FAIL(load_dump_kv_and_fill_write_info(allocator, committed_tablet_status_addr, write_infos))) { + } else if (CLICK_FAIL(load_dump_kv_and_fill_write_info(allocator, committed_tablet_status_addr, write_infos, arg.tablet_status_committed_kv_addr_))) { LOG_WARN("fail to load tablet status committed kv", K(ret), K(committed_tablet_status_addr)); - } else if (CLICK_FAIL(load_dump_kv_and_fill_write_info(allocator, uncommitted_aux_tablet_info_addr, write_infos))) { + } else if (CLICK_FAIL(load_dump_kv_and_fill_write_info(allocator, uncommitted_aux_tablet_info_addr, write_infos, arg.aux_tablet_info_uncommitted_kv_addr_))) { LOG_WARN("fail to load aux tablet info uncommitted kv", K(ret), K(uncommitted_aux_tablet_info_addr)); - } else if (CLICK_FAIL(load_dump_kv_and_fill_write_info(allocator, committed_aux_tablet_info_addr, write_infos))) { + } else if (CLICK_FAIL(load_dump_kv_and_fill_write_info(allocator, committed_aux_tablet_info_addr, write_infos, arg.aux_tablet_info_committed_kv_addr_))) { LOG_WARN("fail to load aux tablet info committed kv", K(ret), K(committed_aux_tablet_info_addr)); } else if (CLICK_FAIL(write_and_fill_args(write_infos, arg, tablet_meta_write_ctxs))) { - LOG_WARN("fail to write and fill address", K(ret), K(write_infos), K(auto_inc_seq)); - } else if (CLICK_FAIL(load_medium_info_list_and_write(allocator, medium_info_list_addr, arg.medium_info_list_addr_, tablet_meta_write_ctxs))) { + LOG_WARN("fail to write and fill address", K(ret)); + } else if (CLICK_FAIL(load_medium_info_list_and_write(allocator, medium_info_list_addr, tablet_meta_write_ctxs, arg.medium_info_list_addr_))) { LOG_WARN("fail to load medium info list and write", K(ret), K(medium_info_list_addr)); } else { - const int64_t try_cache_size = tablet.get_try_cache_size() + table_store.get_member()->get_deep_copy_size(); + const int64_t try_cache_size = tablet.get_try_cache_size() + table_store_wrapper.get_member()->get_deep_copy_size(); if (try_cache_size > ObTenantMetaMemMgr::NORMAL_TABLET_POOL_SIZE) { type = ObTabletPoolType::TP_LARGE; } } - ObTablet::free_storage_schema(allocator, storage_schema); return ret; } @@ -266,7 +257,6 @@ int ObTabletPersister::persist_and_fill_tablet( { TIMEGUARD_INIT(STORAGE, 10_ms); int ret = OB_SUCCESS; - common::ObSEArray write_infos; ObTabletTransformArg arg; const ObTabletMeta &tablet_meta = old_tablet.get_tablet_meta(); @@ -280,13 +270,14 @@ int ObTabletPersister::persist_and_fill_tablet( LOG_WARN("fail to conver tablet to mem arg", K(ret), K(old_tablet)); } } else if (CLICK_FAIL(convert_tablet_to_disk_arg( - allocator, old_tablet, tablet_meta_write_ctxs, sstable_meta_write_ctxs, type, auto_inc_seq, arg))) { + allocator, old_tablet, tablet_meta_write_ctxs, sstable_meta_write_ctxs, type, arg))) { LOG_WARN("fail to conver tablet to disk arg", K(ret), K(old_tablet)); } else if (old_tablet.get_try_cache_size() > ObTenantMetaMemMgr::NORMAL_TABLET_POOL_SIZE) { try_smaller_pool = false; } - if (CLICK() && FAILEDx(acquire_tablet(type, key, try_smaller_pool, new_handle))) { + if (OB_FAIL(ret)) { + } else if (CLICK_FAIL(acquire_tablet(type, key, try_smaller_pool, new_handle))) { LOG_WARN("fail to acquire tablet", K(ret), K(key), K(type)); } else if (CLICK_FAIL(transform(arg, new_handle.get_buf(), new_handle.get_buf_len()))) { LOG_WARN("fail to transform old tablet", K(ret), K(arg), K(new_handle), K(type)); @@ -366,17 +357,14 @@ int ObTabletPersister::persist_4k_tablet(common::ObArenaAllocator &allocator, Ob TIMEGUARD_INIT(STORAGE, 10_ms); int ret = OB_SUCCESS; ObTablet *new_tablet = new_handle.get_obj(); - ObTenantCheckpointSlogHandler *ckpt_slog_hanlder = MTL(ObTenantCheckpointSlogHandler*); + ObTenantCheckpointSlogHandler *ckpt_slog_handler = MTL(ObTenantCheckpointSlogHandler*); common::ObSEArray write_infos; ObSharedBlockWriteHandle handle; ObSharedBlocksWriteCtx write_ctx; if (CLICK_FAIL(fill_write_info(allocator, new_tablet, write_infos))) { LOG_WARN("fail to fill write info", K(ret), KPC(new_tablet)); - } else if (OB_ISNULL(ckpt_slog_hanlder)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected error, ckpt slog handler is nullptr", K(ret), KP(ckpt_slog_hanlder)); - } else if (CLICK_FAIL(ckpt_slog_hanlder->get_shared_block_reader_writer().async_write(write_infos.at(0), handle))) { - LOG_WARN("fail to async write", K(ret), K(write_infos)); + } else if (CLICK_FAIL(ckpt_slog_handler->get_shared_block_reader_writer().async_write(write_infos.at(0), handle))) { + LOG_WARN("fail to async write", K(ret), "write_info", write_infos.at(0)); } else if (CLICK_FAIL(handle.get_write_ctx(write_ctx))) { LOG_WARN("fail to batch get address", K(ret), K(handle)); } else if (FALSE_IT(new_tablet->set_tablet_addr(write_ctx.addr_))) { @@ -410,8 +398,7 @@ int ObTabletPersister::convert_arg_to_tablet( tablet.mds_data_.tablet_status_.committed_kv_.addr_ = arg.tablet_status_committed_kv_addr_; tablet.mds_data_.aux_tablet_info_.uncommitted_kv_.addr_ = arg.aux_tablet_info_uncommitted_kv_addr_; tablet.mds_data_.aux_tablet_info_.committed_kv_.addr_ = arg.aux_tablet_info_committed_kv_addr_; - tablet.mds_data_.extra_medium_info_.info_ = arg.extra_medium_info_.info_; - tablet.mds_data_.extra_medium_info_.last_medium_scn_ = arg.extra_medium_info_.last_medium_scn_; + tablet.mds_data_.extra_medium_info_ = arg.extra_medium_info_; tablet.mds_data_.medium_info_list_.addr_ = arg.medium_info_list_addr_; tablet.mds_data_.auto_inc_seq_.addr_ = arg.auto_inc_seq_addr_; tablet.mds_data_.is_inited_ = true; @@ -526,6 +513,7 @@ int ObTabletPersister::transform( if (OB_SUCC(ret)) { if (OB_ISNULL(arg.auto_inc_seq_ptr_)) { tiny_tablet->mds_data_.auto_inc_seq_.ptr_ = nullptr; + tiny_tablet->mds_data_.auto_inc_seq_.addr_.set_none_addr(); } else { LOG_DEBUG("TINY TABLET: tablet + rowkey_read_info + tablet store", KP(buf), K(start_pos), K(remain)); ObIStorageMetaObj *auto_inc_obj = nullptr; @@ -590,11 +578,11 @@ int ObTabletPersister::fetch_and_persist_sstable( ret = OB_SUCCESS; } if (OB_SUCC(ret) && write_infos.count() > 0) { - ObTenantCheckpointSlogHandler *ckpt_slog_hanlder = MTL(ObTenantCheckpointSlogHandler*); - if (OB_ISNULL(ckpt_slog_hanlder)) { + ObTenantCheckpointSlogHandler *ckpt_slog_handler = MTL(ObTenantCheckpointSlogHandler*); + if (OB_ISNULL(ckpt_slog_handler)) { ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected error, ckpt slog handler is nullptr", K(ret), KP(ckpt_slog_hanlder)); - } else if (OB_FAIL(ckpt_slog_hanlder->get_shared_block_reader_writer().async_batch_write(write_infos, handle))) { + LOG_WARN("unexpected error, ckpt slog handler is nullptr", K(ret), KP(ckpt_slog_handler)); + } else if (OB_FAIL(ckpt_slog_handler->get_shared_block_reader_writer().async_batch_write(write_infos, handle))) { LOG_WARN("fail to batch async write", K(ret), K(write_infos)); } else if (OB_FAIL(handle.batch_get_write_ctx(write_ctxs))) { LOG_WARN("fail to batch get addr", K(ret), K(handle)); @@ -624,8 +612,8 @@ int ObTabletPersister::write_and_fill_args( common::ObIArray &meta_write_ctxs) { int ret = OB_SUCCESS; - ObTenantCheckpointSlogHandler *ckpt_slog_hanlder = MTL(ObTenantCheckpointSlogHandler*); - ObSharedBlockReaderWriter &reader_writer = ckpt_slog_hanlder->get_shared_block_reader_writer(); + ObTenantCheckpointSlogHandler *ckpt_slog_handler = MTL(ObTenantCheckpointSlogHandler*); + ObSharedBlockReaderWriter &reader_writer = ckpt_slog_handler->get_shared_block_reader_writer(); ObSharedBlockBatchHandle handle; ObMetaDiskAddr* addr[] = { // NOTE: The order must be the same as the batch async write. &arg.table_store_addr_, @@ -636,29 +624,43 @@ int ObTabletPersister::write_and_fill_args( &arg.aux_tablet_info_uncommitted_kv_addr_, &arg.aux_tablet_info_committed_kv_addr_, }; - common::ObSEArray write_ctxs; - if (OB_UNLIKELY(sizeof(addr)/sizeof(addr[0]) != write_infos.count())) { + constexpr int64_t total_addr_cnt = sizeof(addr) / sizeof(addr[0]); + int64_t none_addr_cnt = 0; + for (int64_t i = 0; i < total_addr_cnt; ++i) { + if (addr[i]->is_none()) { + ++none_addr_cnt; + } + } + + common::ObSEArray write_ctxs; + if (OB_UNLIKELY(total_addr_cnt != write_infos.count() + none_addr_cnt)) { ret = OB_INVALID_ARGUMENT; - LOG_WARN("invalid arguments", K(ret), "write info count", write_infos.count(), K(write_infos)); - } else if (OB_ISNULL(ckpt_slog_hanlder)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected error, ckpt slog handler is nullptr", K(ret), KP(ckpt_slog_hanlder)); - } else if (OB_FAIL(ckpt_slog_hanlder->get_shared_block_reader_writer().async_batch_write(write_infos, handle))) { - LOG_WARN("fail to batch async write", K(ret), K(write_infos)); + LOG_WARN("invalid arguments", K(ret), K(total_addr_cnt), "write_info_count", write_infos.count(), K(none_addr_cnt)); + } else if (OB_FAIL(reader_writer.async_batch_write(write_infos, handle))) { + LOG_WARN("fail to batch async write", K(ret)); } else if (OB_FAIL(handle.batch_get_write_ctx(write_ctxs))) { LOG_WARN("fail to batch get addr", K(ret), K(handle)); - } else if (OB_UNLIKELY(sizeof(addr)/sizeof(addr[0]) != write_ctxs.count())) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("invalid arguments", K(ret), "write ctx count", write_ctxs.count(), K(write_ctxs), K(handle)); + } else if (OB_UNLIKELY(write_infos.count() != write_ctxs.count())) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("write ctx count does not equal to write info count", K(ret), + "write_info_count", write_infos.count(), + "write_ctx_count", write_ctxs.count(), + K(write_ctxs), K(handle)); } else { - for (int64_t i = 0; OB_SUCC(ret) && i < write_ctxs.count(); ++i) { - if (OB_UNLIKELY(!write_ctxs.at(i).is_valid())) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected invalid addr", K(ret), K(i), K(write_ctxs.at(i)), K(handle)); - } else if (OB_FAIL(meta_write_ctxs.push_back(write_ctxs.at(i)))) { - LOG_WARN("fail to push write ctx to array", K(ret), K(i), K(write_ctxs.at(i))); + int64_t pos = 0; + for (int64_t i = 0; OB_SUCC(ret) && i < total_addr_cnt; ++i) { + if (addr[i]->is_none()) { + // skip none addr } else { - *addr[i] = write_ctxs.at(i).addr_; + const ObSharedBlocksWriteCtx &write_ctx = write_ctxs.at(pos++); + if (OB_UNLIKELY(!write_ctx.is_valid())) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected write ctx", K(ret), K(i), K(write_ctx), K(handle)); + } else if (OB_FAIL(meta_write_ctxs.push_back(write_ctx))) { + LOG_WARN("fail to push write ctx to array", K(ret), K(i), K(write_ctx)); + } else { + *addr[i] = write_ctx.addr_; + } } } } @@ -669,20 +671,21 @@ int ObTabletPersister::write_and_fill_args( int ObTabletPersister::load_dump_kv_and_fill_write_info( common::ObArenaAllocator &allocator, const ObTabletComplexAddr &complex_addr, - common::ObIArray &write_infos) + common::ObIArray &write_infos, + ObMetaDiskAddr &addr) { int ret = OB_SUCCESS; const mds::MdsDumpKV *kv = nullptr; - if (complex_addr.addr_.is_none()) { - // do nothing - } else if (OB_FAIL(ObTabletMdsData::load_mds_dump_kv(allocator, complex_addr, kv))) { + if (OB_FAIL(ObTabletMdsData::load_mds_dump_kv(allocator, complex_addr, kv))) { LOG_WARN("fail to load mds dump kv", K(ret), K(complex_addr)); - } else if (OB_ISNULL(kv)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected error, kv is null", K(ret), KP(kv)); - } else if (OB_FAIL(fill_write_info(allocator, kv, write_infos))) { - LOG_WARN("fail to fill write info", K(ret), KPC(kv)); + } else if (nullptr == kv) { + // read nothing from complex addr, so disk addr is set to NONE + addr.set_none_addr(); + } else { + if (OB_FAIL(fill_write_info(allocator, kv, write_infos))) { + LOG_WARN("fail to fill write info", K(ret), KPC(kv)); + } } ObTabletMdsData::free_mds_dump_kv(allocator, kv); @@ -693,19 +696,20 @@ int ObTabletPersister::load_dump_kv_and_fill_write_info( int ObTabletPersister::load_medium_info_list_and_write( common::ObArenaAllocator &allocator, const ObTabletComplexAddr &complex_addr, - ObMetaDiskAddr &addr, - common::ObIArray &meta_write_ctxs) + common::ObIArray &meta_write_ctxs, + ObMetaDiskAddr &addr) { int ret = OB_SUCCESS; const ObTabletDumpedMediumInfo *medium_info_list = nullptr; if (OB_FAIL(ObTabletMdsData::load_medium_info_list(allocator, complex_addr, medium_info_list))) { LOG_WARN("fail to load medium info list", K(ret), K(complex_addr)); - } else if (OB_ISNULL(medium_info_list)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected error, medium info list is null", K(ret), KP(medium_info_list)); - } else if (OB_FAIL(link_write_medium_info_list(*medium_info_list, addr, meta_write_ctxs))) { - LOG_WARN("failed to link write medium info list", K(ret)); + } else if (nullptr == medium_info_list) { + addr.set_none_addr(); + } else { + if (OB_FAIL(link_write_medium_info_list(medium_info_list, meta_write_ctxs, addr))) { + LOG_WARN("failed to link write medium info list", K(ret)); + } } ObTabletMdsData::free_medium_info_list(allocator, medium_info_list); @@ -714,68 +718,76 @@ int ObTabletPersister::load_medium_info_list_and_write( } int ObTabletPersister::link_write_medium_info_list( - const ObTabletDumpedMediumInfo &medium_info_list, - ObMetaDiskAddr &addr, - common::ObIArray &meta_write_ctxs) + const ObTabletDumpedMediumInfo *medium_info_list, + common::ObIArray &meta_write_ctxs, + ObMetaDiskAddr &addr) { int ret = OB_SUCCESS; - ObTenantCheckpointSlogHandler *ckpt_slog_hanlder = MTL(ObTenantCheckpointSlogHandler*); - ObSharedBlockReaderWriter &reader_writer = ckpt_slog_hanlder->get_shared_block_reader_writer(); + ObTenantCheckpointSlogHandler *ckpt_slog_handler = MTL(ObTenantCheckpointSlogHandler*); + ObSharedBlockReaderWriter &reader_writer = ckpt_slog_handler->get_shared_block_reader_writer(); common::ObArenaAllocator arena_allocator(common::ObMemAttr(MTL_ID(), "serializer")); ObSharedBlockWriteInfo write_info; ObSharedBlockLinkHandle write_handle; - const common::ObIArray &array = medium_info_list.medium_info_list_; - for (int64_t i = 0; OB_SUCC(ret) && i < array.count(); ++i) { - const compaction::ObMediumCompactionInfo *medium_info = array.at(i); - if (OB_ISNULL(medium_info)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected error, medium info is null", K(ret), K(i), KP(medium_info)); - } else { - const int64_t size = medium_info->get_serialize_size(); - - if (0 == size) { - LOG_INFO("medium info serialize size is 0, just skip", K(ret)); + if (nullptr == medium_info_list) { + // no need to do link write, just return NONE addr + addr.set_none_addr(); + } else { + const common::ObIArray &array = medium_info_list->medium_info_list_; + for (int64_t i = 0; OB_SUCC(ret) && i < array.count(); ++i) { + const compaction::ObMediumCompactionInfo *medium_info = array.at(i); + if (OB_ISNULL(medium_info)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected error, medium info is null", K(ret), K(i), KP(medium_info)); } else { - int64_t pos = 0; - char *buffer = static_cast(arena_allocator.alloc(size)); - if (OB_ISNULL(buffer)) { - ret = OB_ALLOCATE_MEMORY_FAILED; - LOG_WARN("failed to alloc memory", K(ret), K(size)); - } else if (OB_FAIL(medium_info->serialize(buffer, size, pos))) { - LOG_WARN("failed to serialize medium info", K(ret)); - } else { - write_info.reset(); - write_info.buffer_ = buffer; - write_info.offset_ = 0; - write_info.size_ = size; - write_info.io_desc_.set_wait_event(ObWaitEventIds::DB_FILE_COMPACT_WRITE); - if (OB_FAIL(reader_writer.async_link_write(write_info, write_handle))) { - LOG_WARN("failed to do async link write", K(ret), K(write_info)); - } else if (OB_UNLIKELY(!write_handle.is_valid())) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected error, write handle is invalid", K(ret), K(write_handle)); - } - } + const int64_t size = medium_info->get_serialize_size(); - if (nullptr != buffer) { - arena_allocator.free(buffer); + if (0 == size) { + LOG_INFO("medium info serialize size is 0, just skip", K(ret)); + } else { + int64_t pos = 0; + char *buffer = static_cast(arena_allocator.alloc(size)); + if (OB_ISNULL(buffer)) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_WARN("failed to alloc memory", K(ret), K(size)); + } else if (OB_FAIL(medium_info->serialize(buffer, size, pos))) { + LOG_WARN("failed to serialize medium info", K(ret)); + } else { + write_info.reset(); + write_info.buffer_ = buffer; + write_info.offset_ = 0; + write_info.size_ = size; + write_info.io_desc_.set_wait_event(ObWaitEventIds::DB_FILE_COMPACT_WRITE); + if (OB_FAIL(reader_writer.async_link_write(write_info, write_handle))) { + LOG_WARN("failed to do async link write", K(ret), K(write_info)); + } else if (OB_UNLIKELY(!write_handle.is_valid())) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected error, write handle is invalid", K(ret), K(write_handle)); + } + } + + if (nullptr != buffer) { + arena_allocator.free(buffer); + } } } } - } - if (OB_FAIL(ret)) { - } else if (array.empty()) { - addr.set_none_addr(); - } else { - ObSharedBlocksWriteCtx write_ctx; - if (OB_FAIL(write_handle.get_write_ctx(write_ctx))) { - LOG_WARN("failed to get write ctx", K(ret), K(write_handle)); - } else if (OB_FAIL(meta_write_ctxs.push_back(write_ctx))) { - LOG_WARN("failed to push back write ctx", K(ret), K(write_ctx)); + if (OB_FAIL(ret)) { + } else if (array.empty()) { + addr.set_none_addr(); } else { - addr = write_ctx.addr_; + ObSharedBlocksWriteCtx write_ctx; + if (OB_FAIL(write_handle.get_write_ctx(write_ctx))) { + LOG_WARN("failed to get write ctx", K(ret), K(write_handle)); + } else if (OB_UNLIKELY(!write_ctx.is_valid())) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("write ctx is invalid", K(ret), K(write_ctx)); + } else if (OB_FAIL(meta_write_ctxs.push_back(write_ctx))) { + LOG_WARN("failed to push back write ctx", K(ret), K(write_ctx)); + } else { + addr = write_ctx.addr_; + } } } @@ -847,5 +859,80 @@ int ObTabletPersister::transform_tablet_memory_footprint( return ret; } +int ObTabletPersister::fetch_table_store_and_write_info( + const ObTablet &tablet, + common::ObArenaAllocator &allocator, + ObTabletMemberWrapper &wrapper, + common::ObIArray &write_infos, + common::ObIArray &meta_write_ctxs) +{ + int ret = OB_SUCCESS; + ObTabletTableStore new_table_store; + const ObTabletTableStore *table_store = nullptr; + ObTableStoreIterator table_iter; + if (OB_FAIL(tablet.fetch_table_store(wrapper))) { + LOG_WARN("fail to fetch table store", K(ret)); + } else if (OB_FAIL(wrapper.get_member(table_store))) { + LOG_WARN("fail to get table store from wrapper", K(ret), K(wrapper)); + } else if (OB_FAIL(table_store->get_all_sstable(table_iter))) { + LOG_WARN("fail to get all sstable iterator", K(ret), KPC(table_store)); + } else if (OB_FAIL(fetch_and_persist_sstable(allocator, table_iter, new_table_store, meta_write_ctxs))) { + LOG_WARN("fail to fetch and persist sstable", K(ret), K(table_iter)); + } else if (OB_FAIL(fill_write_info(allocator, &new_table_store, write_infos))) { + LOG_WARN("fail to fill table store write info", K(ret), K(new_table_store)); + } + return ret; +} + +int ObTabletPersister::load_auto_inc_seq_and_write_info( + common::ObArenaAllocator &allocator, + const ObTabletComplexAddr &complex_addr, + const share::ObTabletAutoincSeq *&auto_inc_seq, + common::ObIArray &write_infos, + ObMetaDiskAddr &addr) +{ + int ret = OB_SUCCESS; + auto_inc_seq = nullptr; + const share::ObTabletAutoincSeq *ptr = nullptr; + + if (OB_UNLIKELY(!complex_addr.is_valid())) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid args", K(ret), K(complex_addr)); + } else if (OB_FAIL(ObTabletMdsData::load_auto_inc_seq(allocator, complex_addr, ptr))) { + LOG_WARN("failed to load auto inc seq", K(ret), K(complex_addr)); + } else if (nullptr == ptr) { + addr.set_none_addr(); + } else if (OB_FAIL(fill_write_info(allocator, ptr, write_infos))) { + LOG_WARN("fail to fill empty write info", K(ret)); + } else { + auto_inc_seq = ptr; + } + + if (OB_FAIL(ret)) { + ObTabletMdsData::free_auto_inc_seq(allocator, ptr); + } + + return ret; +} + +int ObTabletPersister::load_storage_schema_and_fill_write_info( + const ObTablet &tablet, + common::ObArenaAllocator &allocator, + common::ObIArray &write_infos) +{ + int ret = OB_SUCCESS; + const ObStorageSchema *storage_schema = nullptr; + if (OB_FAIL(tablet.load_storage_schema(allocator, storage_schema))) { + LOG_WARN("fail to load storage schema", K(ret)); + } else if (OB_ISNULL(storage_schema)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("storage schema is null", K(ret), KP(storage_schema)); + } else if (OB_FAIL(fill_write_info(allocator, storage_schema, write_infos))) { + LOG_WARN("fail to fill write info", K(ret), KP(storage_schema)); + } + ObTablet::free_storage_schema(allocator, storage_schema); + return ret; +} + } // end namespace storage } // end namespace oceanbase diff --git a/src/storage/tablet/ob_tablet_persister.h b/src/storage/tablet/ob_tablet_persister.h index 64d22fa9a..db5e8ebe8 100644 --- a/src/storage/tablet/ob_tablet_persister.h +++ b/src/storage/tablet/ob_tablet_persister.h @@ -90,12 +90,6 @@ public: const ObTablet &old_tablet, char *buf, const int64_t len); -private: - using FetchTableStore = std::function &)>; - using FetchAutoincSeq = std::function &)>; - using LoadStorageSchema = std::function; - using LoadMediumInfoList = std::function; - using LoadMdsDumpKV = std::function; private: static int check_tablet_meta_ids( const common::ObIArray &tablet_meta_write_ctxs, @@ -115,7 +109,6 @@ private: common::ObIArray &tablet_meta_write_ctxs, common::ObIArray &sstable_meta_write_ctxs, ObTabletPoolType &type, - ObTabletMemberWrapper &auto_inc_seq, ObTabletTransformArg &arg); static int convert_arg_to_tablet( const ObTabletTransformArg &arg, @@ -142,32 +135,36 @@ private: ObTableStoreIterator &table_iter, ObTabletTableStore &new_table_store, common::ObIArray &meta_write_ctxs); - template - static int fetch_wrapper_and_write_info( + static int load_auto_inc_seq_and_write_info( common::ObArenaAllocator &allocator, - Fetch &fetch, - ObTabletMemberWrapper &wrapper, + const ObTabletComplexAddr &complex_addr, + const share::ObTabletAutoincSeq *&auto_inc_seq, + common::ObIArray &write_infos, + ObMetaDiskAddr &addr); + static int fetch_table_store_and_write_info( + const ObTablet &tablet, + common::ObArenaAllocator &allocator, + ObTabletMemberWrapper &wrapper, common::ObIArray &write_infos, common::ObIArray &meta_write_ctxs); - template - static int load_member_and_write_info( + static int load_storage_schema_and_fill_write_info( + const ObTablet &tablet, common::ObArenaAllocator &allocator, - Load &load, - T *&t, common::ObIArray &write_infos); static int load_dump_kv_and_fill_write_info( common::ObArenaAllocator &allocator, const ObTabletComplexAddr &complex_addr, - common::ObIArray &write_infos); + common::ObIArray &write_infos, + ObMetaDiskAddr &addr); static int load_medium_info_list_and_write( common::ObArenaAllocator &allocator, const ObTabletComplexAddr &complex_addr, - ObMetaDiskAddr &addr, - common::ObIArray &meta_write_ctxs); + common::ObIArray &meta_write_ctxs, + ObMetaDiskAddr &addr); static int link_write_medium_info_list( - const ObTabletDumpedMediumInfo &medium_info_list, - ObMetaDiskAddr &addr, - common::ObIArray &meta_write_ctxs); + const ObTabletDumpedMediumInfo *medium_info_list, + common::ObIArray &meta_write_ctxs, + ObMetaDiskAddr &addr); template static int fill_write_info( common::ObArenaAllocator &allocator, @@ -191,78 +188,6 @@ private: ObTabletTableStore *&table_store); }; -template -int ObTabletPersister::fetch_wrapper_and_write_info( - common::ObArenaAllocator &allocator, - Fetch &fetch, - ObTabletMemberWrapper &wrapper, - common::ObIArray &write_infos, - common::ObIArray &meta_write_ctxs) -{ - UNUSED(meta_write_ctxs); - int ret = common::OB_SUCCESS; - const T *member = nullptr; - if (OB_FAIL(fetch(wrapper))) { - STORAGE_LOG(WARN, "fail to fetch tablet wrapper", K(ret)); - } else if (OB_FAIL(wrapper.get_member(member))) { - STORAGE_LOG(WARN, "fail to get tablet member", K(ret), K(wrapper)); - } else if (OB_ISNULL(member)) { - ret = common::OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "unexpected error, member is nullptr", K(ret), KP(member)); - } else if (OB_FAIL(fill_write_info(allocator, member, write_infos))) { - STORAGE_LOG(WARN, "fail to fill write info", K(ret), KP(member)); - } - return ret; -}; - -template <> -inline int ObTabletPersister::fetch_wrapper_and_write_info( - common::ObArenaAllocator &allocator, - FetchTableStore &fetch, - ObTabletMemberWrapper &wrapper, - common::ObIArray &write_infos, - common::ObIArray &meta_write_ctxs) -{ - int ret = common::OB_SUCCESS; - ObTabletTableStore new_table_store; - const ObTabletTableStore *table_store = nullptr; - ObTableStoreIterator table_iter; - if (OB_FAIL(fetch(wrapper))) { - STORAGE_LOG(WARN, "fail to fetch table store", K(ret)); - } else if (OB_FAIL(wrapper.get_member(table_store))) { - STORAGE_LOG(WARN, "fail to get table store from wrapper", K(ret), K(wrapper)); - } else if (OB_ISNULL(table_store)) { - ret = common::OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "unexpected error, table store is nullptr", K(ret), KP(table_store)); - } else if (OB_FAIL(table_store->get_all_sstable(table_iter))) { - STORAGE_LOG(WARN, "fail to get all sstable iterator", K(ret), KPC(table_store)); - } else if (OB_FAIL(fetch_and_persist_sstable(allocator, table_iter, new_table_store, meta_write_ctxs))) { - STORAGE_LOG(WARN, "fail to fetch and persist sstable", K(ret), K(table_iter)); - } else if (OB_FAIL(fill_write_info(allocator, &new_table_store, write_infos))) { - STORAGE_LOG(WARN, "fail to fill table store write info", K(ret), K(new_table_store)); - } - return ret; -} - -template -int ObTabletPersister::load_member_and_write_info( - common::ObArenaAllocator &allocator, - Load &load, - T *&t, - common::ObIArray &write_infos) -{ - int ret = common::OB_SUCCESS; - if (OB_FAIL(load(allocator, t))) { - STORAGE_LOG(WARN, "fail to load tablet member", K(ret)); - } else if (OB_ISNULL(t)) { - ret = common::OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "unexpected error, t is nullptr", K(ret), KP(t)); - } else if (OB_FAIL(fill_write_info(allocator, t, write_infos))) { - STORAGE_LOG(WARN, "fail to fill write info", K(ret), KP(t)); - } - return ret; -} - template int ObTabletPersister::fill_write_info( common::ObArenaAllocator &allocator, @@ -270,9 +195,10 @@ int ObTabletPersister::fill_write_info( common::ObIArray &write_infos) { int ret = common::OB_SUCCESS; + if (OB_ISNULL(t)) { - ret = common::OB_ERR_UNEXPECTED; - STORAGE_LOG(WARN, "unexpected error, tablet member is nullptr", K(ret), KP(t)); + ret = common::OB_INVALID_ARGUMENT; + STORAGE_LOG(WARN, "invalid args", K(ret), KP(t)); } else { const int64_t size = t->get_serialize_size(); char *buf = static_cast(allocator.alloc(size)); diff --git a/unittest/storage/test_tablet_dumped_medium_info.cpp b/unittest/storage/test_tablet_dumped_medium_info.cpp index 2eb727330..e1ecfae4c 100644 --- a/unittest/storage/test_tablet_dumped_medium_info.cpp +++ b/unittest/storage/test_tablet_dumped_medium_info.cpp @@ -94,7 +94,7 @@ TEST_F(TestTabletDumpedMediumInfo, overlap) compaction::ObMediumCompactionInfo *info = nullptr; ObTabletDumpedMediumInfo input_medium_info1; - ret = input_medium_info1.init(allocator); + ret = input_medium_info1.init_for_first_creation(allocator); ASSERT_EQ(OB_SUCCESS, ret); APPEND_MEDIUM_INFO(input_medium_info1, allocator, 5, 4, true, info); @@ -102,7 +102,7 @@ TEST_F(TestTabletDumpedMediumInfo, overlap) APPEND_MEDIUM_INFO(input_medium_info1, allocator, 7, 6, true, info); ObTabletDumpedMediumInfo input_medium_info2; - ret = input_medium_info2.init(allocator); + ret = input_medium_info2.init_for_first_creation(allocator); ASSERT_EQ(OB_SUCCESS, ret); APPEND_MEDIUM_INFO(input_medium_info2, allocator, 2, 1, true, info); @@ -112,7 +112,7 @@ TEST_F(TestTabletDumpedMediumInfo, overlap) APPEND_MEDIUM_INFO(input_medium_info1, allocator, 6, 5, true, info); ObTabletDumpedMediumInfo result; - ret = result.init(allocator); + ret = result.init_for_first_creation(allocator); ASSERT_EQ(OB_SUCCESS, ret); const int64_t finish_medium_scn = 3; @@ -136,7 +136,7 @@ TEST_F(TestTabletDumpedMediumInfo, no_overlap) compaction::ObMediumCompactionInfo *info = nullptr; ObTabletDumpedMediumInfo input_medium_info1; - ret = input_medium_info1.init(allocator); + ret = input_medium_info1.init_for_first_creation(allocator); ASSERT_EQ(OB_SUCCESS, ret); APPEND_MEDIUM_INFO(input_medium_info1, allocator, 5, 4, true, info); @@ -144,7 +144,7 @@ TEST_F(TestTabletDumpedMediumInfo, no_overlap) APPEND_MEDIUM_INFO(input_medium_info1, allocator, 7, 6, true, info); ObTabletDumpedMediumInfo input_medium_info2; - ret = input_medium_info2.init(allocator); + ret = input_medium_info2.init_for_first_creation(allocator); ASSERT_EQ(OB_SUCCESS, ret); APPEND_MEDIUM_INFO(input_medium_info2, allocator, 2, 1, true, info); @@ -152,7 +152,7 @@ TEST_F(TestTabletDumpedMediumInfo, no_overlap) { ObTabletDumpedMediumInfo result; - ret = result.init(allocator); + ret = result.init_for_first_creation(allocator); ASSERT_EQ(OB_SUCCESS, ret); const int64_t finish_medium_scn = 1; @@ -172,7 +172,7 @@ TEST_F(TestTabletDumpedMediumInfo, no_overlap) APPEND_MEDIUM_INFO(input_medium_info2, allocator, 4, 3, true, info); { ObTabletDumpedMediumInfo result; - ret = result.init(allocator); + ret = result.init_for_first_creation(allocator); ASSERT_EQ(OB_SUCCESS, ret); const int64_t finish_medium_scn = 1; @@ -198,7 +198,7 @@ TEST_F(TestTabletDumpedMediumInfo, overlap_and_filter) compaction::ObMediumCompactionInfo *info = nullptr; ObTabletDumpedMediumInfo input_medium_info1; - ret = input_medium_info1.init(allocator); + ret = input_medium_info1.init_for_first_creation(allocator); ASSERT_EQ(OB_SUCCESS, ret); APPEND_MEDIUM_INFO(input_medium_info1, allocator, 5, 4, true, info); @@ -206,7 +206,7 @@ TEST_F(TestTabletDumpedMediumInfo, overlap_and_filter) APPEND_MEDIUM_INFO(input_medium_info1, allocator, 7, 6, true, info); ObTabletDumpedMediumInfo input_medium_info2; - ret = input_medium_info2.init(allocator); + ret = input_medium_info2.init_for_first_creation(allocator); ASSERT_EQ(OB_SUCCESS, ret); APPEND_MEDIUM_INFO(input_medium_info2, allocator, 2, 1, true, info); @@ -216,7 +216,7 @@ TEST_F(TestTabletDumpedMediumInfo, overlap_and_filter) APPEND_MEDIUM_INFO(input_medium_info1, allocator, 6, 5, true, info); ObTabletDumpedMediumInfo result; - ret = result.init(allocator); + ret = result.init_for_first_creation(allocator); ASSERT_EQ(OB_SUCCESS, ret); const int64_t finish_medium_scn = 6; @@ -236,7 +236,7 @@ TEST_F(TestTabletDumpedMediumInfo, no_overlap_and_filter) compaction::ObMediumCompactionInfo *info = nullptr; ObTabletDumpedMediumInfo input_medium_info1; - ret = input_medium_info1.init(allocator); + ret = input_medium_info1.init_for_first_creation(allocator); ASSERT_EQ(OB_SUCCESS, ret); APPEND_MEDIUM_INFO(input_medium_info1, allocator, 5, 4, true, info); @@ -244,7 +244,7 @@ TEST_F(TestTabletDumpedMediumInfo, no_overlap_and_filter) APPEND_MEDIUM_INFO(input_medium_info1, allocator, 7, 6, true, info); ObTabletDumpedMediumInfo input_medium_info2; - ret = input_medium_info2.init(allocator); + ret = input_medium_info2.init_for_first_creation(allocator); ASSERT_EQ(OB_SUCCESS, ret); APPEND_MEDIUM_INFO(input_medium_info2, allocator, 2, 1, true, info); @@ -252,7 +252,7 @@ TEST_F(TestTabletDumpedMediumInfo, no_overlap_and_filter) APPEND_MEDIUM_INFO(input_medium_info2, allocator, 4, 3, true, info); ObTabletDumpedMediumInfo result; - ret = result.init(allocator); + ret = result.init_for_first_creation(allocator); ASSERT_EQ(OB_SUCCESS, ret); const int64_t finish_medium_scn = 7; @@ -271,21 +271,21 @@ TEST_F(TestTabletDumpedMediumInfo, standby_cluster) compaction::ObMediumCompactionInfo *info = nullptr; ObTabletDumpedMediumInfo input_medium_info1; - ret = input_medium_info1.init(allocator); + ret = input_medium_info1.init_for_first_creation(allocator); ASSERT_EQ(OB_SUCCESS, ret); APPEND_MEDIUM_INFO(input_medium_info1, allocator, 7, 5, false, info); APPEND_MEDIUM_INFO(input_medium_info1, allocator, 9, 8, false, info); ObTabletDumpedMediumInfo input_medium_info2; - ret = input_medium_info2.init(allocator); + ret = input_medium_info2.init_for_first_creation(allocator); ASSERT_EQ(OB_SUCCESS, ret); APPEND_MEDIUM_INFO(input_medium_info2, allocator, 2, 1, false, info); APPEND_MEDIUM_INFO(input_medium_info2, allocator, 4, 2, false, info); ObTabletDumpedMediumInfo result; - ret = result.init(allocator); + ret = result.init_for_first_creation(allocator); ASSERT_EQ(OB_SUCCESS, ret); const int64_t finish_medium_scn = 3; @@ -307,7 +307,7 @@ TEST_F(TestTabletDumpedMediumInfo, mds_table_dump) compaction::ObMediumCompactionInfo *info = nullptr; ObTabletDumpedMediumInfo input_medium_info1; - ret = input_medium_info1.init(allocator); + ret = input_medium_info1.init_for_first_creation(allocator); ASSERT_EQ(OB_SUCCESS, ret); ObTabletComplexAddr mds_table_data; mds_table_data.ptr_ = &input_medium_info1; @@ -316,7 +316,7 @@ TEST_F(TestTabletDumpedMediumInfo, mds_table_dump) APPEND_MEDIUM_INFO(input_medium_info1, allocator, 9, 7, false, info); ObTabletDumpedMediumInfo input_medium_info2; - ret = input_medium_info2.init(allocator); + ret = input_medium_info2.init_for_first_creation(allocator); ASSERT_EQ(OB_SUCCESS, ret); ObTabletComplexAddr base_data; base_data.ptr_ = &input_medium_info2; @@ -326,19 +326,17 @@ TEST_F(TestTabletDumpedMediumInfo, mds_table_dump) APPEND_MEDIUM_INFO(input_medium_info2, allocator, 6, 4, false, info); APPEND_MEDIUM_INFO(input_medium_info2, allocator, 7, 6, false, info); - ObTabletDumpedMediumInfo result; - ret = result.init(allocator); ASSERT_EQ(OB_SUCCESS, ret); ObTabletComplexAddr result_data; - result_data.ptr_ = &result; + ObTabletDumpedMediumInfo *&result = result_data.ptr_; const int64_t finish_medium_scn = 4; - ret = ObTabletMdsData::fuse_mds_dump_node(allocator, finish_medium_scn, mds_table_data, base_data, result_data); + ret = ObTabletMdsData::init_single_complex_addr(allocator, mds_table_data, base_data, finish_medium_scn, result_data); ASSERT_EQ(OB_SUCCESS, ret); - ASSERT_EQ(3, result.medium_info_list_.count()); - ASSERT_EQ(6, result.medium_info_list_.at(0)->medium_snapshot_); - ASSERT_EQ(7, result.medium_info_list_.at(1)->medium_snapshot_); - ASSERT_EQ(9, result.medium_info_list_.at(2)->medium_snapshot_); + ASSERT_EQ(3, result->medium_info_list_.count()); + ASSERT_EQ(6, result->medium_info_list_.at(0)->medium_snapshot_); + ASSERT_EQ(7, result->medium_info_list_.at(1)->medium_snapshot_); + ASSERT_EQ(9, result->medium_info_list_.at(2)->medium_snapshot_); } } // namespace unittest } // namespace oceanbase diff --git a/unittest/storage/test_tablet_helper.h b/unittest/storage/test_tablet_helper.h index 9283d28a9..2e15ffa9d 100644 --- a/unittest/storage/test_tablet_helper.h +++ b/unittest/storage/test_tablet_helper.h @@ -19,14 +19,15 @@ #include "lib/ob_errno.h" #include "lib/oblog/ob_log_module.h" #include "share/ob_rpc_struct.h" +#include "share/scn.h" #include "storage/tx/ob_trans_define.h" #include "storage/ls/ob_ls_tablet_service.h" #include "storage/ls/ob_ls.h" -#include "share/scn.h" #include "storage/meta_mem/ob_tenant_meta_mem_mgr.h" +#include "storage/tablet/ob_tablet_create_delete_helper.h" +#include "storage/tablet/ob_tablet_obj_load_helper.h" #include "storage/tablet/ob_tablet_slog_helper.h" #include "storage/init_basic_struct.h" -#include "storage/tablet/ob_tablet_create_delete_helper.h" namespace oceanbase { @@ -112,12 +113,9 @@ inline int TestTabletHelper::create_tablet( ObTabletCreateSSTableParam param; prepare_sstable_param(tablet_id, table_schema, param); - void *buff = nullptr; ObSSTable *sstable = nullptr; - if (OB_ISNULL(buff = allocator.alloc(sizeof(ObSSTable)))) { - ret = OB_ALLOCATE_MEMORY_FAILED; - STORAGE_LOG(WARN, "fail to allocate memory", K(ret)); - } else if (FALSE_IT(sstable = new (buff) ObSSTable())) { + if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, sstable))) { + STORAGE_LOG(WARN, "fail to alloc and new", K(ret)); } else if (OB_FAIL(ObTabletCreateDeleteHelper::create_sstable(param, allocator, *sstable))) { STORAGE_LOG(WARN, "failed to acquire sstable", K(ret)); } else if (OB_FAIL(ObSSTableMergeRes::fill_column_checksum_for_empty_major(param.column_cnt_, param.column_checksums_))) { @@ -145,13 +143,17 @@ inline int TestTabletHelper::create_tablet( if (tablet_status == ObTabletStatus::Status::DELETED) { data.delete_commit_scn_ = SCN::base_scn(); } + + ObTabletComplexAddr &tablet_status_committed_kv = tablet_handle.get_obj()->mds_data_.tablet_status_.committed_kv_; const int64_t data_serialize_size = data.get_serialize_size(); int64_t pos = 0; char *buf = static_cast(t3m->full_tablet_creator_.get_allocator().alloc(data_serialize_size)); if (OB_FAIL(data.serialize(buf, data_serialize_size, pos))) { STORAGE_LOG(WARN, "data serialize failed", K(ret), K(data_serialize_size), K(pos)); + } else if (ObTabletObjLoadHelper::alloc_and_new(*tablet_handle.get_allocator(), tablet_status_committed_kv.ptr_)) { + STORAGE_LOG(WARN, "failed to alloc and new", K(ret)); } else { - tablet_handle.get_obj()->mds_data_.tablet_status_.committed_kv_.get_ptr()->v_.user_data_.assign(buf, data_serialize_size); + tablet_status_committed_kv.ptr_->v_.user_data_.assign(buf, data_serialize_size); } }