From 6e1811678e6e22c4acd7e73eb3e1ecc3ff86db97 Mon Sep 17 00:00:00 2001 From: hiddenbomb Date: Thu, 31 Aug 2023 12:10:35 +0000 Subject: [PATCH] refine tablet init functions & refactor code struct --- .../storage/test_ls_migration_param.cpp | 6 +- .../test_ls_tablet_info_writer_and_reader.cpp | 2 +- .../storage/test_tenant_meta_mem_mgr.cpp | 10 +-- src/storage/CMakeLists.txt | 2 + src/storage/ls/ob_ls_tablet_service.cpp | 26 +++---- .../ob_batch_create_tablet_pretty_arg.cpp | 62 ++++++++++++++++ .../ob_batch_create_tablet_pretty_arg.h | 42 +++++++++++ src/storage/tablet/ob_tablet.cpp | 14 ++-- src/storage/tablet/ob_tablet.h | 12 +-- .../tablet/ob_tablet_create_delete_helper.cpp | 42 ----------- .../tablet/ob_tablet_create_delete_helper.h | 11 --- .../tablet/ob_tablet_create_mds_helper.cpp | 73 +------------------ .../ob_tablet_create_replay_executor.cpp | 66 +++++++++++++++++ .../tablet/ob_tablet_create_replay_executor.h | 59 +++++++++++++++ unittest/storage/test_compaction_policy.cpp | 2 +- unittest/storage/test_tablet_helper.h | 4 +- 16 files changed, 272 insertions(+), 161 deletions(-) create mode 100644 src/storage/tablet/ob_batch_create_tablet_pretty_arg.cpp create mode 100644 src/storage/tablet/ob_batch_create_tablet_pretty_arg.h create mode 100644 src/storage/tablet/ob_tablet_create_replay_executor.cpp create mode 100644 src/storage/tablet/ob_tablet_create_replay_executor.h diff --git a/mittest/mtlenv/storage/test_ls_migration_param.cpp b/mittest/mtlenv/storage/test_ls_migration_param.cpp index 2af2ff373e..681ab25953 100644 --- a/mittest/mtlenv/storage/test_ls_migration_param.cpp +++ b/mittest/mtlenv/storage/test_ls_migration_param.cpp @@ -241,7 +241,7 @@ TEST_F(TestLSMigrationParam, test_migrate_tablet_param) store_flag.set_with_major_sstable(); SCN scn; scn.convert_from_ts(ObTimeUtility::current_time()); - ret = src_handle.get_obj()->init(allocator_, src_key.ls_id_, src_key.tablet_id_, src_key.tablet_id_, + ret = src_handle.get_obj()->init_for_first_time_creation(allocator_, src_key.ls_id_, src_key.tablet_id_, src_key.tablet_id_, scn, 2022, table_schema, lib::Worker::CompatMode::MYSQL, store_flag, nullptr, ls_handle.get_ls()->get_freezer()); ASSERT_EQ(common::OB_SUCCESS, ret); @@ -259,7 +259,7 @@ TEST_F(TestLSMigrationParam, test_migrate_tablet_param) ret = t3m->create_tmp_tablet(WashTabletPriority::WTP_HIGH, dst_key, allocator_, ls_handle, dst_handle); ASSERT_EQ(common::OB_SUCCESS, ret); - ret = dst_handle.get_obj()->init(allocator_, tablet_param, false, ls_handle.get_ls()->get_freezer()); + ret = dst_handle.get_obj()->init_with_migrate_param(allocator_, tablet_param, false, ls_handle.get_ls()->get_freezer()); ASSERT_EQ(common::OB_SUCCESS, ret); const ObTabletMeta &src_meta = src_handle.get_obj()->get_tablet_meta(); @@ -303,7 +303,7 @@ TEST_F(TestLSMigrationParam, test_migration_param_compat) store_flag.set_with_major_sstable(); SCN scn; scn.convert_from_ts(ObTimeUtility::current_time()); - ret = src_handle.get_obj()->init(allocator_, src_key.ls_id_, src_key.tablet_id_, src_key.tablet_id_, + ret = src_handle.get_obj()->init_for_first_time_creation(allocator_, src_key.ls_id_, src_key.tablet_id_, src_key.tablet_id_, scn, 2022, table_schema, lib::Worker::CompatMode::MYSQL, store_flag, nullptr, ls_handle.get_ls()->get_freezer()); ASSERT_EQ(common::OB_SUCCESS, ret); diff --git a/mittest/mtlenv/storage/test_ls_tablet_info_writer_and_reader.cpp b/mittest/mtlenv/storage/test_ls_tablet_info_writer_and_reader.cpp index 1c29e0e594..28f0481695 100644 --- a/mittest/mtlenv/storage/test_ls_tablet_info_writer_and_reader.cpp +++ b/mittest/mtlenv/storage/test_ls_tablet_info_writer_and_reader.cpp @@ -160,7 +160,7 @@ void TestLSTabletInfoWR::fill_tablet_meta() store_flag.set_with_major_sstable(); SCN scn; scn.convert_from_ts(ObTimeUtility::current_time()); - ret = src_handle.get_obj()->init(arena_allocator_, src_key.ls_id_, src_key.tablet_id_, src_key.tablet_id_, + ret = src_handle.get_obj()->init_for_first_time_creation(arena_allocator_, src_key.ls_id_, src_key.tablet_id_, src_key.tablet_id_, scn, 2022, table_schema, lib::Worker::CompatMode::MYSQL, store_flag, nullptr/*empty sstable*/, ls_handle.get_ls()->get_freezer()); ASSERT_EQ(common::OB_SUCCESS, ret); diff --git a/mittest/mtlenv/storage/test_tenant_meta_mem_mgr.cpp b/mittest/mtlenv/storage/test_tenant_meta_mem_mgr.cpp index 7fdf8a8958..c53a01d2bf 100644 --- a/mittest/mtlenv/storage/test_tenant_meta_mem_mgr.cpp +++ b/mittest/mtlenv/storage/test_tenant_meta_mem_mgr.cpp @@ -692,7 +692,7 @@ TEST_F(TestTenantMetaMemMgr, test_wash_tablet) ObTabletID empty_tablet_id; ObTabletTableStoreFlag store_flag; store_flag.set_with_major_sstable(); - ret = tablet->init(allocator_, ls_id_, tablet_id, tablet_id, + ret = tablet->init_for_first_time_creation(allocator_, ls_id_, tablet_id, tablet_id, create_scn, create_scn.get_val_for_tx(), table_schema, lib::Worker::CompatMode::MYSQL, store_flag, &sstable, &freezer); ASSERT_EQ(common::OB_SUCCESS, ret); @@ -790,7 +790,7 @@ TEST_F(TestTenantMetaMemMgr, test_wash_inner_tablet) ObTabletID empty_tablet_id; ObTabletTableStoreFlag store_flag; store_flag.set_with_major_sstable(); - ret = tablet->init(allocator_, ls_id_, tablet_id, tablet_id, + ret = tablet->init_for_first_time_creation(allocator_, ls_id_, tablet_id, tablet_id, create_scn, create_scn.get_val_for_tx(), table_schema, lib::Worker::CompatMode::MYSQL, store_flag, &sstable, &freezer); ASSERT_EQ(common::OB_SUCCESS, ret); @@ -893,7 +893,7 @@ TEST_F(TestTenantMetaMemMgr, test_wash_no_sstable_tablet) ObTabletID empty_tablet_id; ObTabletTableStoreFlag store_flag; store_flag.set_with_major_sstable(); - ret = tablet->init(allocator_, ls_id_, tablet_id, tablet_id, + ret = tablet->init_for_first_time_creation(allocator_, ls_id_, tablet_id, tablet_id, create_scn, create_scn.get_val_for_tx(), table_schema, lib::Worker::CompatMode::MYSQL, store_flag, nullptr, &freezer); ASSERT_EQ(common::OB_SUCCESS, ret); @@ -1077,7 +1077,7 @@ TEST_F(TestTenantMetaMemMgr, test_get_tablet_with_allocator) ObTabletID empty_tablet_id; ObTabletTableStoreFlag store_flag; store_flag.set_with_major_sstable(); - ret = tablet->init(allocator_, ls_id_, tablet_id, tablet_id, + ret = tablet->init_for_first_time_creation(allocator_, ls_id_, tablet_id, tablet_id, create_scn, create_scn.get_val_for_tx(), table_schema, lib::Worker::CompatMode::MYSQL, store_flag, &sstable, &freezer); ASSERT_EQ(common::OB_SUCCESS, ret); @@ -1199,7 +1199,7 @@ TEST_F(TestTenantMetaMemMgr, test_wash_mem_tablet) ObTabletID empty_tablet_id; ObTabletTableStoreFlag store_flag; store_flag.set_with_major_sstable(); - ret = tablet->init(allocator_, ls_id_, tablet_id, tablet_id, + ret = tablet->init_for_first_time_creation(allocator_, ls_id_, tablet_id, tablet_id, create_scn, create_scn.get_val_for_tx(), table_schema, lib::Worker::CompatMode::MYSQL, store_flag, &sstable, &freezer); ASSERT_EQ(common::OB_SUCCESS, ret); diff --git a/src/storage/CMakeLists.txt b/src/storage/CMakeLists.txt index f5e9b233df..118a7a9f7c 100755 --- a/src/storage/CMakeLists.txt +++ b/src/storage/CMakeLists.txt @@ -187,12 +187,14 @@ ob_set_subtarget(ob_storage backup ) ob_set_subtarget(ob_storage tablet + tablet/ob_batch_create_tablet_pretty_arg.cpp tablet/ob_full_tablet_creator.cpp tablet/ob_tablet_binding_helper.cpp tablet/ob_tablet_binding_replay_executor.cpp tablet/ob_tablet_common.cpp tablet/ob_tablet_complex_addr.cpp tablet/ob_tablet_create_delete_helper.cpp + tablet/ob_tablet_create_replay_executor.cpp tablet/ob_tablet_create_sstable_param.cpp tablet/ob_tablet_ddl_info.cpp tablet/ob_tablet_id_set.cpp diff --git a/src/storage/ls/ob_ls_tablet_service.cpp b/src/storage/ls/ob_ls_tablet_service.cpp index d84036a1f5..c875d8d369 100755 --- a/src/storage/ls/ob_ls_tablet_service.cpp +++ b/src/storage/ls/ob_ls_tablet_service.cpp @@ -840,7 +840,7 @@ int ObLSTabletService::rebuild_tablet_with_old( } else if (OB_FAIL(ObTabletCreateDeleteHelper::acquire_tmp_tablet(key, allocator, tmp_tablet_hdl))) { LOG_WARN("fail to acquire temporary tablet", K(ret), K(key)); } else if (FALSE_IT(tmp_tablet = tmp_tablet_hdl.get_obj())) { - } else if (OB_FAIL(tmp_tablet->init(allocator, mig_tablet_param, true/*is_update*/, freezer))) { + } else if (OB_FAIL(tmp_tablet->init_with_migrate_param(allocator, mig_tablet_param, true/*is_update*/, freezer))) { LOG_WARN("failed to init tablet", K(ret), K(mig_tablet_param)); } else if (FALSE_IT(tmp_tablet->set_next_tablet_guard(tablet_guard))) { } else if (FALSE_IT(time_guard.click("InitTablet"))) { @@ -887,7 +887,7 @@ int ObLSTabletService::migrate_update_tablet( } else if (OB_FAIL(ObTabletCreateDeleteHelper::acquire_tmp_tablet(key, allocator, tmp_tablet_hdl))) { LOG_WARN("fail to acquire temporary tablet", K(ret), K(key)); } else if (FALSE_IT(new_tablet = tmp_tablet_hdl.get_obj())) { - } else if (OB_FAIL(new_tablet->init(allocator, mig_tablet_param, true/*is_update*/, freezer))) { + } else if (OB_FAIL(new_tablet->init_with_migrate_param(allocator, mig_tablet_param, true/*is_update*/, freezer))) { LOG_WARN("failed to init tablet", K(ret), K(mig_tablet_param)); } else if (FALSE_IT(time_guard.click("InitTablet"))) { } else if (OB_FAIL(ObTabletPersister::persist_and_transform_tablet(*new_tablet, new_tablet_hdl))) { @@ -928,7 +928,7 @@ int ObLSTabletService::migrate_create_tablet( if (OB_FAIL(ObTabletCreateDeleteHelper::create_tmp_tablet(key, allocator, tmp_tablet_hdl))) { LOG_WARN("fail to create temporary tablet", K(ret), K(key)); - } else if (OB_FAIL(tmp_tablet_hdl.get_obj()->init(allocator, mig_tablet_param, false/*is_update*/, freezer))) { + } else if (OB_FAIL(tmp_tablet_hdl.get_obj()->init_with_migrate_param(allocator, mig_tablet_param, false/*is_update*/, freezer))) { LOG_WARN("fail to init tablet", K(ret), K(mig_tablet_param)); } else if (FALSE_IT(time_guard.click("InitTablet"))) { } else if (OB_FAIL(ObTabletPersister::persist_and_transform_tablet(*tmp_tablet_hdl.get_obj(), tablet_handle))) { @@ -1092,7 +1092,7 @@ int ObLSTabletService::update_tablet_table_store( if (OB_FAIL(ObTabletCreateDeleteHelper::acquire_tmp_tablet(key, allocator, tmp_tablet_hdl))) { LOG_WARN("fail to acquire temporary tablet", K(ret), K(key)); } else if (FALSE_IT(tmp_tablet = tmp_tablet_hdl.get_obj())) { - } else if (OB_FAIL(tmp_tablet->init(allocator, tables, *old_tablet))) { + } else if (OB_FAIL(tmp_tablet->init_for_defragment(allocator, tables, *old_tablet))) { LOG_WARN("fail to init new tablet", K(ret), KPC(old_tablet)); } else if (FALSE_IT(time_guard.click("InitTablet"))) { } else if (OB_FAIL(ObTabletPersister::persist_and_transform_tablet(*tmp_tablet, new_tablet_hdl))) { @@ -1157,7 +1157,7 @@ int ObLSTabletService::update_tablet_table_store( ObTenantMetaMemMgr *t3m = MTL(ObTenantMetaMemMgr*); ObTablet *old_tablet = old_tablet_hdl.get_obj(); ObMetaDiskAddr disk_addr; - if (OB_FAIL(tmp_tablet->init(allocator, param, *old_tablet))) { + if (OB_FAIL(tmp_tablet->init_for_merge(allocator, param, *old_tablet))) { LOG_WARN("failed to init tablet", K(ret), K(param), KPC(old_tablet)); } else if (FALSE_IT(time_guard.click("InitNew"))) { } else if (OB_FAIL(ObTabletPersister::persist_and_transform_tablet(*tmp_tablet, new_tablet_hdl))) { @@ -1441,7 +1441,7 @@ int ObLSTabletService::build_new_tablet_from_mds_table( } else { LOG_WARN("failed to read mds table", K(ret), K(key)); } - } else if (CLICK_FAIL(tmp_tablet->init(allocator, *old_tablet, flush_scn, mds_data, old_tablet->mds_data_))) { + } else if (CLICK_FAIL(tmp_tablet->init_for_mds_table_dump(allocator, *old_tablet, flush_scn, mds_data, old_tablet->mds_data_))) { LOG_WARN("failed to init tablet", K(ret), KPC(old_tablet), K(flush_scn)); } else if (CLICK_FAIL(ObTabletPersister::persist_and_transform_tablet(*tmp_tablet, new_tablet_handle))) { LOG_WARN("fail to persist and transform tablet", K(ret), KPC(tmp_tablet), K(new_tablet_handle)); @@ -1999,8 +1999,8 @@ int ObLSTabletService::create_tablet( sstable = &new_sstable; } if (OB_FAIL(ret)) { - } else if (OB_FAIL(tablet->init(*allocator, ls_id, tablet_id, data_tablet_id, create_scn, snapshot_version, - table_schema, compat_mode, table_store_flag, sstable, freezer))) { + } else if (OB_FAIL(tablet->init_for_first_time_creation(*allocator, ls_id, tablet_id, data_tablet_id, + create_scn, snapshot_version, table_schema, compat_mode, table_store_flag, sstable, freezer))) { LOG_WARN("failed to init tablet", K(ret), K(ls_id), K(tablet_id), K(data_tablet_id), K(create_scn), K(snapshot_version), K(table_schema), K(compat_mode), K(table_store_flag)); } else if (OB_FAIL(t3m->compare_and_swap_tablet(key, tablet_handle, tablet_handle))) { @@ -2066,8 +2066,8 @@ int ObLSTabletService::create_inner_tablet( sstable = &new_sstable; } if (OB_FAIL(ret)) { - } else if (OB_FAIL(tmp_tablet->init(allocator, ls_id, tablet_id, data_tablet_id, create_scn, snapshot_version, - table_schema, compat_mode, table_store_flag, sstable, freezer))) { + } else if (OB_FAIL(tmp_tablet->init_for_first_time_creation(allocator, ls_id, tablet_id, data_tablet_id, + create_scn, snapshot_version, table_schema, compat_mode, table_store_flag, sstable, freezer))) { LOG_WARN("failed to init tablet", K(ret), K(ls_id), K(tablet_id), K(data_tablet_id), K(create_scn), K(snapshot_version), K(table_schema), K(compat_mode), K(table_store_flag)); @@ -2147,7 +2147,7 @@ int ObLSTabletService::create_transfer_in_tablet( || OB_ISNULL(allocator = tablet_handle.get_allocator())) { ret = OB_ERR_UNEXPECTED; LOG_ERROR("new tablet is null", K(ret), KP(tablet), KP(allocator), K(tablet_handle)); - } else if (OB_FAIL(tablet->init(*allocator, tablet_meta, false/*is_update*/, freezer))) { + } else if (OB_FAIL(tablet->init_with_migrate_param(*allocator, tablet_meta, false/*is_update*/, freezer))) { LOG_WARN("failed to init tablet", K(ret), K(ls_id), K(tablet_meta)); } else if (OB_FAIL(t3m->compare_and_swap_tablet(key, tablet_handle, tablet_handle))) { LOG_WARN("failed to compare and swap tablet", K(ret), K(key), K(tablet_handle)); @@ -2203,7 +2203,7 @@ int ObLSTabletService::create_empty_shell_tablet( ObFreezer *freezer = ls_->get_freezer(); ObTablet *new_tablet = tablet_handle.get_obj(); ObMetaDiskAddr disk_addr; - if (OB_FAIL(new_tablet->init(*tablet_handle.get_allocator(), param, false/*is_update*/, freezer))) { + if (OB_FAIL(new_tablet->init_with_migrate_param(*tablet_handle.get_allocator(), param, false/*is_update*/, freezer))) { LOG_WARN("failed to init tablet", K(ret), K(param)); } else if (OB_FAIL(ObTabletSlogHelper::write_empty_shell_tablet_slog(new_tablet, disk_addr))) { LOG_WARN("fail to write update tablet slog", K(ret), K(ls_id), K(tablet_id)); @@ -3417,7 +3417,7 @@ int ObLSTabletService::build_ha_tablet_new_table_store( if (OB_FAIL(ObTabletCreateDeleteHelper::acquire_tmp_tablet(key, allocator, tmp_tablet_handle))) { LOG_WARN("failed to acquire tablet", K(ret), K(key)); } else if (FALSE_IT(tmp_tablet = tmp_tablet_handle.get_obj())) { - } else if (OB_FAIL(tmp_tablet->init(allocator, param, *old_tablet))) { + } else if (OB_FAIL(tmp_tablet->init_for_sstable_replace(allocator, param, *old_tablet))) { LOG_WARN("failed to init tablet", K(ret), KPC(old_tablet)); } else if (FALSE_IT(time_guard.click("InitTablet"))) { } else if (OB_FAIL(ObTabletPersister::persist_and_transform_tablet(*tmp_tablet, new_tablet_handle))) { diff --git a/src/storage/tablet/ob_batch_create_tablet_pretty_arg.cpp b/src/storage/tablet/ob_batch_create_tablet_pretty_arg.cpp new file mode 100644 index 0000000000..ad224e3404 --- /dev/null +++ b/src/storage/tablet/ob_batch_create_tablet_pretty_arg.cpp @@ -0,0 +1,62 @@ +/** + * 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 "storage/tablet/ob_batch_create_tablet_pretty_arg.h" +#include "lib/utility/ob_print_utils.h" +#include "share/ob_rpc_struct.h" + +using namespace oceanbase::obrpc; + +namespace oceanbase +{ +namespace storage +{ +ObBatchCreateTabletPrettyArg::ObBatchCreateTabletPrettyArg(const ObBatchCreateTabletArg &arg) + : arg_(arg) +{ +} + +int64_t ObBatchCreateTabletPrettyArg::to_string(char *buf, const int64_t buf_len) const +{ + int64_t pos = 0; + if (OB_ISNULL(buf) || OB_UNLIKELY(buf_len <= 0)) { + // do nothing + } else { + J_OBJ_START(); + J_KV("ls_id", arg_.id_, + "major_frozen_scn", arg_.major_frozen_scn_, + "total_tablet_cnt", arg_.get_tablet_count()); + J_COMMA(); + + BUF_PRINTF("tablets"); + J_COLON(); + J_OBJ_START(); + for (int64_t i = 0; i < arg_.tablets_.count(); ++i) { + const ObCreateTabletInfo &info = arg_.tablets_.at(i); + ObCurTraceId::TraceId *trace_id = ObCurTraceId::get_trace_id(); + J_NEWLINE(); + BUF_PRINTF("[%ld] [", GETTID()); + BUF_PRINTO(PC(trace_id)); + BUF_PRINTF("] "); + J_KV("data_tablet_id", info.data_tablet_id_, + "tablet_ids", info.tablet_ids_, + "compat_mode", info.compat_mode_, + "is_create_bind_hidden_tablets", info.is_create_bind_hidden_tablets_); + } + J_NEWLINE(); + J_OBJ_END(); + J_OBJ_END(); + } + return pos; +} +} // namespace storage +} // namespace oceanbase \ No newline at end of file diff --git a/src/storage/tablet/ob_batch_create_tablet_pretty_arg.h b/src/storage/tablet/ob_batch_create_tablet_pretty_arg.h new file mode 100644 index 0000000000..38ae061b2e --- /dev/null +++ b/src/storage/tablet/ob_batch_create_tablet_pretty_arg.h @@ -0,0 +1,42 @@ +/** + * 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. + */ + +#ifndef OCEANBASE_STORAGE_OB_BATCH_CREATE_TABLET_PRETTY_ARG +#define OCEANBASE_STORAGE_OB_BATCH_CREATE_TABLET_PRETTY_ARG + +#include + +namespace oceanbase +{ +namespace obrpc +{ +struct ObBatchCreateTabletArg; +} + +namespace storage +{ +class ObBatchCreateTabletPrettyArg +{ +public: + ObBatchCreateTabletPrettyArg(const obrpc::ObBatchCreateTabletArg &arg); + ~ObBatchCreateTabletPrettyArg() = default; + ObBatchCreateTabletPrettyArg(const ObBatchCreateTabletPrettyArg&) = delete; + ObBatchCreateTabletPrettyArg &operator=(const ObBatchCreateTabletPrettyArg&) = delete; +public: + int64_t to_string(char *buf, const int64_t buf_len) const; +private: + const obrpc::ObBatchCreateTabletArg &arg_; +}; +} // namespace storage +} // namespace oceanbase + +#endif // OCEANBASE_STORAGE_OB_BATCH_CREATE_TABLET_PRETTY_ARG diff --git a/src/storage/tablet/ob_tablet.cpp b/src/storage/tablet/ob_tablet.cpp index 0bef46026a..3d116471f4 100755 --- a/src/storage/tablet/ob_tablet.cpp +++ b/src/storage/tablet/ob_tablet.cpp @@ -184,7 +184,7 @@ void ObTablet::reset() is_inited_ = false; } -int ObTablet::init( +int ObTablet::init_for_first_time_creation( common::ObArenaAllocator &allocator, const share::ObLSID &ls_id, const common::ObTabletID &tablet_id, @@ -264,7 +264,7 @@ int ObTablet::init( return ret; } -int ObTablet::init( +int ObTablet::init_for_merge( common::ObArenaAllocator &allocator, const ObUpdateTableStoreParam ¶m, const ObTablet &old_tablet) @@ -370,7 +370,7 @@ int ObTablet::init( return ret; } -int ObTablet::init( +int ObTablet::init_for_mds_table_dump( common::ObArenaAllocator &allocator, const ObTablet &old_tablet, const share::SCN &flush_scn, @@ -434,14 +434,14 @@ int ObTablet::init( set_next_tablet_guard(old_tablet.next_tablet_guard_); } is_inited_ = true; - LOG_INFO("succeeded to init tablet for dump mds table", K(ret), K(old_tablet), K(flush_scn), KPC(this), K(mds_table_data), K(base_data)); + LOG_INFO("succeeded to init tablet for mds table dump", K(ret), K(old_tablet), K(flush_scn), KPC(this), K(mds_table_data), K(base_data)); } ObTablet::free_storage_schema(tmp_arena_allocator, old_storage_schema); return ret; } -int ObTablet::init( +int ObTablet::init_with_migrate_param( common::ObArenaAllocator &allocator, const ObMigrationTabletParam ¶m, const bool is_update, @@ -530,7 +530,7 @@ int ObTablet::init( return ret; } -int ObTablet::init( +int ObTablet::init_for_defragment( common::ObArenaAllocator &allocator, const ObIArray &tables, const ObTablet &old_tablet) @@ -608,7 +608,7 @@ int ObTablet::init( return ret; } -int ObTablet::init( +int ObTablet::init_for_sstable_replace( common::ObArenaAllocator &allocator, const ObBatchUpdateTableStoreParam ¶m, const ObTablet &old_tablet) diff --git a/src/storage/tablet/ob_tablet.h b/src/storage/tablet/ob_tablet.h index 4d47252655..c01a38d15d 100755 --- a/src/storage/tablet/ob_tablet.h +++ b/src/storage/tablet/ob_tablet.h @@ -145,7 +145,7 @@ public: public: // first time create tablet - int init( + int init_for_first_time_creation( common::ObArenaAllocator &allocator, const share::ObLSID &ls_id, const common::ObTabletID &tablet_id, @@ -158,25 +158,25 @@ public: blocksstable::ObSSTable *sstable, ObFreezer *freezer); // dump/merge build new multi version tablet - int init( + int init_for_merge( common::ObArenaAllocator &allocator, const ObUpdateTableStoreParam ¶m, const ObTablet &old_tablet); // dump/merge mds table to tablet_meta - int init( + int init_for_mds_table_dump( common::ObArenaAllocator &allocator, const ObTablet &old_tablet, const share::SCN &flush_scn, const ObTabletMdsData &mds_table_data, const ObTabletMdsData &base_data); // transfer build new tablet - int init( + int init_with_migrate_param( common::ObArenaAllocator &allocator, const ObMigrationTabletParam ¶m, const bool is_update, ObFreezer *freezer); //batch update table store with range cut - int init( + int init_for_sstable_replace( common::ObArenaAllocator &allocator, const ObBatchUpdateTableStoreParam ¶m, const ObTablet &old_tablet); @@ -185,7 +185,7 @@ public: common::ObArenaAllocator &allocator, const ObTablet &old_tablet); // batch replace sstables without data modification - int init( + int init_for_defragment( common::ObArenaAllocator &allocator, const ObIArray &tables, const ObTablet &old_tablet); diff --git a/src/storage/tablet/ob_tablet_create_delete_helper.cpp b/src/storage/tablet/ob_tablet_create_delete_helper.cpp index 4c34ac8046..14655fcccd 100755 --- a/src/storage/tablet/ob_tablet_create_delete_helper.cpp +++ b/src/storage/tablet/ob_tablet_create_delete_helper.cpp @@ -38,7 +38,6 @@ #define USING_LOG_PREFIX STORAGE -using namespace oceanbase::obrpc; using namespace oceanbase::common; using namespace oceanbase::share; using namespace oceanbase::share::schema; @@ -665,46 +664,5 @@ int ObTabletCreateDeleteHelper::build_create_sstable_param( return ret; } - -ObSimpleBatchCreateTabletArg::ObSimpleBatchCreateTabletArg(const ObBatchCreateTabletArg &arg) - : arg_(arg) -{ -} - -int64_t ObSimpleBatchCreateTabletArg::to_string(char *buf, const int64_t buf_len) const -{ - int64_t pos = 0; - if (OB_ISNULL(buf) || OB_UNLIKELY(buf_len <= 0)) { - // do nothing - } else { - J_OBJ_START(); - J_NAME("ObSimpleBatchCreateTabletArg"); - J_COLON(); - J_KV("id", arg_.id_, - "major_frozen_scn", arg_.major_frozen_scn_, - "total_tablet_cnt", arg_.get_tablet_count()); - J_COMMA(); - - BUF_PRINTF("tablets"); - J_COLON(); - J_OBJ_START(); - for (int64_t i = 0; i < arg_.tablets_.count(); ++i) { - const ObCreateTabletInfo &info = arg_.tablets_.at(i); - ObCurTraceId::TraceId *trace_id = ObCurTraceId::get_trace_id(); - J_NEWLINE(); - BUF_PRINTF("[%ld] [", GETTID()); - BUF_PRINTO(PC(trace_id)); - BUF_PRINTF("] "); - J_KV("data_tablet_id", info.data_tablet_id_, - "tablet_ids", info.tablet_ids_, - "compat_mode", info.compat_mode_, - "is_create_bind_hidden_tablets", info.is_create_bind_hidden_tablets_); - } - J_NEWLINE(); - J_OBJ_END(); - J_OBJ_END(); - } - return pos; -} } // namespace storage } // namespace oceanbase diff --git a/src/storage/tablet/ob_tablet_create_delete_helper.h b/src/storage/tablet/ob_tablet_create_delete_helper.h index 0182c311f2..10fa2268e8 100644 --- a/src/storage/tablet/ob_tablet_create_delete_helper.h +++ b/src/storage/tablet/ob_tablet_create_delete_helper.h @@ -212,17 +212,6 @@ int ObTabletCreateDeleteHelper::process_for_old_mds( } return ret; }; - -class ObSimpleBatchCreateTabletArg -{ -public: - ObSimpleBatchCreateTabletArg(const obrpc::ObBatchCreateTabletArg &arg); - ~ObSimpleBatchCreateTabletArg() = default; -public: - int64_t to_string(char *buf, const int64_t buf_len) const; -private: - const obrpc::ObBatchCreateTabletArg &arg_; -}; } // namespace storage } // namespace oceanbase diff --git a/src/storage/tablet/ob_tablet_create_mds_helper.cpp b/src/storage/tablet/ob_tablet_create_mds_helper.cpp index 88c453e831..edb91c7520 100644 --- a/src/storage/tablet/ob_tablet_create_mds_helper.cpp +++ b/src/storage/tablet/ob_tablet_create_mds_helper.cpp @@ -22,14 +22,15 @@ #include "storage/meta_mem/ob_tenant_meta_mem_mgr.h" #include "storage/meta_mem/ob_tablet_map_key.h" #include "storage/meta_mem/ob_tablet_handle.h" +#include "storage/tablet/ob_batch_create_tablet_pretty_arg.h" #include "storage/tablet/ob_tablet_create_delete_helper.h" #include "storage/tablet/ob_tablet_create_delete_mds_user_data.h" +#include "storage/tablet/ob_tablet_create_replay_executor.h" #include "storage/tx_storage/ob_ls_handle.h" #include "storage/tx_storage/ob_ls_service.h" -#include "logservice/replayservice/ob_tablet_replay_executor.h" #define USING_LOG_PREFIX MDS -#define PRETTY_ARG(arg) (ObSimpleBatchCreateTabletArg(arg)) +#define PRETTY_ARG(arg) (ObBatchCreateTabletPrettyArg(arg)) using namespace oceanbase::common; using namespace oceanbase::share; @@ -39,74 +40,6 @@ namespace oceanbase { namespace storage { -class ObTabletCreateReplayExecutor final : public logservice::ObTabletReplayExecutor -{ -public: - ObTabletCreateReplayExecutor(); - - int init( - mds::BufferCtx &user_ctx, - const share::SCN &scn, - const bool for_old_mds); - -protected: - bool is_replay_update_tablet_status_() const override - { - return true; - } - - int do_replay_(ObTabletHandle &tablet_handle) override; - - virtual bool is_replay_update_mds_table_() const override - { - return true; - } - -private: - mds::BufferCtx *user_ctx_; - share::SCN scn_; - bool for_old_mds_; -}; - - -ObTabletCreateReplayExecutor::ObTabletCreateReplayExecutor() - :logservice::ObTabletReplayExecutor(), user_ctx_(nullptr) -{} - -int ObTabletCreateReplayExecutor::init( - mds::BufferCtx &user_ctx, - const share::SCN &scn, - const bool for_old_mds) -{ - int ret = OB_SUCCESS; - if (OB_UNLIKELY(is_inited_)) { - ret = OB_INIT_TWICE; - LOG_WARN("tablet create replay executor init twice", KR(ret), K_(is_inited)); - } else if (OB_UNLIKELY(!scn.is_valid())) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("get invalid argument", KR(ret), K(scn)); - } else { - user_ctx_ = &user_ctx; - scn_ = scn; - is_inited_ = true; - for_old_mds_ = for_old_mds; - } - return ret; -} - -int ObTabletCreateReplayExecutor::do_replay_(ObTabletHandle &tablet_handle) -{ - int ret = OB_SUCCESS; - mds::MdsCtx &user_ctx = static_cast(*user_ctx_); - ObTabletCreateDeleteMdsUserData user_data(ObTabletStatus::NORMAL, ObTabletMdsUserDataType::CREATE_TABLET); - - if (OB_FAIL(replay_to_mds_table_(tablet_handle, user_data, user_ctx, scn_, for_old_mds_))) { - LOG_WARN("failed to replay to tablet", K(ret)); - } - - return ret; -} - int ObTabletCreateMdsHelper::on_commit_for_old_mds( const char* buf, const int64_t len, diff --git a/src/storage/tablet/ob_tablet_create_replay_executor.cpp b/src/storage/tablet/ob_tablet_create_replay_executor.cpp new file mode 100644 index 0000000000..bf1619b39d --- /dev/null +++ b/src/storage/tablet/ob_tablet_create_replay_executor.cpp @@ -0,0 +1,66 @@ +/** + * 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 "storage/tablet/ob_tablet_create_replay_executor.h" +#include "lib/ob_errno.h" +#include "lib/oblog/ob_log_module.h" +#include "lib/utility/ob_print_utils.h" +#include "storage/multi_data_source/buffer_ctx.h" +#include "storage/tablet/ob_tablet_create_delete_mds_user_data.h" + +#define USING_LOG_PREFIX STORAGE + +namespace oceanbase +{ +namespace storage +{ +ObTabletCreateReplayExecutor::ObTabletCreateReplayExecutor() + : logservice::ObTabletReplayExecutor(), + user_ctx_(nullptr) +{ +} + +int ObTabletCreateReplayExecutor::init( + mds::BufferCtx &user_ctx, + const share::SCN &scn, + const bool for_old_mds) +{ + int ret = OB_SUCCESS; + if (OB_UNLIKELY(is_inited_)) { + ret = OB_INIT_TWICE; + LOG_WARN("tablet create replay executor init twice", KR(ret), K_(is_inited)); + } else if (OB_UNLIKELY(!scn.is_valid())) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("get invalid argument", KR(ret), K(scn)); + } else { + user_ctx_ = &user_ctx; + scn_ = scn; + is_inited_ = true; + for_old_mds_ = for_old_mds; + } + return ret; +} + +int ObTabletCreateReplayExecutor::do_replay_(ObTabletHandle &tablet_handle) +{ + int ret = OB_SUCCESS; + mds::MdsCtx &user_ctx = static_cast(*user_ctx_); + ObTabletCreateDeleteMdsUserData user_data(ObTabletStatus::NORMAL, ObTabletMdsUserDataType::CREATE_TABLET); + + if (OB_FAIL(replay_to_mds_table_(tablet_handle, user_data, user_ctx, scn_, for_old_mds_))) { + LOG_WARN("failed to replay to tablet", K(ret)); + } + + return ret; +} +} // namespace storage +} // namespace oceanbase \ No newline at end of file diff --git a/src/storage/tablet/ob_tablet_create_replay_executor.h b/src/storage/tablet/ob_tablet_create_replay_executor.h new file mode 100644 index 0000000000..cfa8b86dec --- /dev/null +++ b/src/storage/tablet/ob_tablet_create_replay_executor.h @@ -0,0 +1,59 @@ +/** + * 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. + */ + +#ifndef OCEANBASE_STORAGE_OB_TABLET_REPLAY_EXECUTOR +#define OCEANBASE_STORAGE_OB_TABLET_REPLAY_EXECUTOR + +#include "logservice/replayservice/ob_tablet_replay_executor.h" +#include "share/scn.h" + +namespace oceanbase +{ +namespace storage +{ +namespace mds +{ +class BufferCtx; +} + +class ObTabletCreateReplayExecutor final : public logservice::ObTabletReplayExecutor +{ +public: + ObTabletCreateReplayExecutor(); + + int init( + mds::BufferCtx &user_ctx, + const share::SCN &scn, + const bool for_old_mds); + +protected: + bool is_replay_update_tablet_status_() const override + { + return true; + } + + int do_replay_(ObTabletHandle &tablet_handle) override; + + virtual bool is_replay_update_mds_table_() const override + { + return true; + } + +private: + mds::BufferCtx *user_ctx_; + share::SCN scn_; + bool for_old_mds_; +}; +} // namespace storage +} // namespace oceanbase + +#endif // OCEANBASE_STORAGE_OB_TABLET_REPLAY_EXECUTOR diff --git a/unittest/storage/test_compaction_policy.cpp b/unittest/storage/test_compaction_policy.cpp index c276fbca28..4ab9f5a10a 100644 --- a/unittest/storage/test_compaction_policy.cpp +++ b/unittest/storage/test_compaction_policy.cpp @@ -402,7 +402,7 @@ int TestCompactionPolicy::mock_tablet( } else if (OB_FAIL(ObTabletCreateDeleteHelper::create_tmp_tablet(key, allocator, tablet_handle))) { LOG_WARN("failed to acquire tablet", K(ret), K(key)); } else if (FALSE_IT(tablet = tablet_handle.get_obj())) { - } else if (OB_FAIL(tablet->init(allocator, ls_id, tablet_id, tablet_id, + } else if (OB_FAIL(tablet->init_for_first_time_creation(allocator, ls_id, tablet_id, tablet_id, SCN::min_scn(), snapshot_version, table_schema, compat_mode, table_store_flag, nullptr, ls_handle.get_ls()->get_freezer()))) { LOG_WARN("failed to init tablet", K(ret), K(ls_id), K(tablet_id), K(snapshot_version), K(table_schema), K(compat_mode)); diff --git a/unittest/storage/test_tablet_helper.h b/unittest/storage/test_tablet_helper.h index 0e6e87dbab..9283d28a98 100644 --- a/unittest/storage/test_tablet_helper.h +++ b/unittest/storage/test_tablet_helper.h @@ -132,11 +132,11 @@ inline int TestTabletHelper::create_tablet( const ObTabletMapKey key(ls_id, tablet_id); if (OB_FAIL(t3m->create_msd_tablet(WashTabletPriority::WTP_HIGH, key, ls_handle, tablet_handle))) { STORAGE_LOG(WARN, "t3m acquire tablet failed", K(ret), K(ls_id), K(tablet_id)); - } else if (OB_FAIL(tablet_handle.get_obj()->init( + } else if (OB_FAIL(tablet_handle.get_obj()->init_for_first_time_creation( *tablet_handle.get_allocator(), ls_id, tablet_id, tablet_id, share::SCN::base_scn(), snapshot_version, table_schema, compat_mode, store_flag, sstable, freezer))){ - STORAGE_LOG(WARN, "tablet init failed", K(ret), K(ls_id), K(tablet_id)); + STORAGE_LOG(WARN, "failed to init tablet", K(ret), K(ls_id), K(tablet_id)); } else if (ObTabletStatus::Status::MAX != tablet_status) { ObTabletCreateDeleteMdsUserData data; data.tablet_status_ = tablet_status;