From 399f70309095a438763167e183d19b83a5421cf2 Mon Sep 17 00:00:00 2001 From: obdev Date: Thu, 27 Oct 2022 01:05:37 +0000 Subject: [PATCH] Fix ls migration copy sstable data do not match tablet meta bug --- .../high_availability/ob_ls_migration.cpp | 5 +- .../ob_physical_copy_task.cpp | 14 ++- .../high_availability/ob_physical_copy_task.h | 4 +- .../ob_storage_ha_reader.cpp | 71 ++++++++++++-- .../high_availability/ob_storage_ha_reader.h | 8 ++ .../ob_storage_ha_tablet_builder.cpp | 60 ++++++++++-- .../ob_storage_ha_tablet_builder.h | 10 +- .../ob_tablet_group_restore.cpp | 6 +- src/storage/ob_storage_rpc.cpp | 10 +- src/storage/ob_storage_rpc.h | 3 +- src/storage/ob_storage_struct.cpp | 13 ++- src/storage/ob_storage_struct.h | 5 +- src/storage/tablet/ob_tablet.cpp | 14 +-- src/storage/tablet/ob_tablet.h | 6 ++ src/storage/tablet/ob_tablet_meta.cpp | 92 +++++++++++++++++++ src/storage/tablet/ob_tablet_meta.h | 15 +++ 16 files changed, 293 insertions(+), 43 deletions(-) diff --git a/src/storage/high_availability/ob_ls_migration.cpp b/src/storage/high_availability/ob_ls_migration.cpp index 6adb33a1a..090180e9a 100644 --- a/src/storage/high_availability/ob_ls_migration.cpp +++ b/src/storage/high_availability/ob_ls_migration.cpp @@ -2537,6 +2537,7 @@ int ObTabletMigrationTask::generate_tablet_copy_finish_task_( ObLS *ls = nullptr; ObTabletMigrationDag *tablet_migration_dag = nullptr; observer::ObIMetaReport *reporter = GCTX.ob_service_; + const ObMigrationTabletParam *src_tablet_meta = nullptr; if (!is_inited_) { ret = OB_NOT_INIT; @@ -2546,7 +2547,9 @@ int ObTabletMigrationTask::generate_tablet_copy_finish_task_( LOG_WARN("failed to alloc tablet copy finish task", K(ret), KPC(ctx_)); } else if (OB_FAIL(tablet_migration_dag->get_ls(ls))) { LOG_WARN("failed to get ls", K(ret), KPC(ctx_)); - } else if (OB_FAIL(tablet_copy_finish_task->init(copy_tablet_ctx_->tablet_id_, ls, reporter))) { + } else if (OB_FAIL(ctx_->ha_table_info_mgr_.get_tablet_meta(copy_tablet_ctx_->tablet_id_, src_tablet_meta))) { + LOG_WARN("failed to get src tablet meta", K(ret), KPC(copy_tablet_ctx_)); + } else if (OB_FAIL(tablet_copy_finish_task->init(copy_tablet_ctx_->tablet_id_, ls, reporter, src_tablet_meta))) { LOG_WARN("failed to init tablet copy finish task", K(ret), KPC(ctx_), KPC(copy_tablet_ctx_)); } return ret; diff --git a/src/storage/high_availability/ob_physical_copy_task.cpp b/src/storage/high_availability/ob_physical_copy_task.cpp index e666dfa70..75973bbbc 100644 --- a/src/storage/high_availability/ob_physical_copy_task.cpp +++ b/src/storage/high_availability/ob_physical_copy_task.cpp @@ -1069,7 +1069,8 @@ ObTabletCopyFinishTask::ObTabletCopyFinishTask() ls_(nullptr), reporter_(nullptr), ha_dag_(nullptr), - tables_handle_() + tables_handle_(), + src_tablet_meta_(nullptr) { } @@ -1081,20 +1082,23 @@ ObTabletCopyFinishTask::~ObTabletCopyFinishTask() int ObTabletCopyFinishTask::init( const common::ObTabletID &tablet_id, ObLS *ls, - observer::ObIMetaReport *reporter) + observer::ObIMetaReport *reporter, + const ObMigrationTabletParam *src_tablet_meta) { int ret = OB_SUCCESS; if (is_inited_) { ret = OB_INIT_TWICE; LOG_WARN("tablet copy finish task init twice", K(ret)); - } else if (!tablet_id.is_valid() || OB_ISNULL(ls) || OB_ISNULL(reporter)) { + } else if (!tablet_id.is_valid() || OB_ISNULL(ls) || OB_ISNULL(reporter) || OB_ISNULL(src_tablet_meta)) { ret = OB_INVALID_ARGUMENT; - LOG_WARN("init tablet copy finish task get invalid argument", K(ret), K(tablet_id), KP(ls), KP(reporter)); + LOG_WARN("init tablet copy finish task get invalid argument", K(ret), K(tablet_id), KP(ls), + KP(reporter), KP(src_tablet_meta)); } else { tablet_id_ = tablet_id; ls_ = ls; reporter_ = reporter; ha_dag_ = static_cast(this->get_dag()); + src_tablet_meta_ = src_tablet_meta; is_inited_ = true; } return ret; @@ -1199,7 +1203,7 @@ int ObTabletCopyFinishTask::create_new_table_store_() } else { update_table_store_param.multi_version_start_ = 0; update_table_store_param.need_report_ = true; - update_table_store_param.storage_schema_ = &tablet->get_storage_schema(); + update_table_store_param.tablet_meta_ = src_tablet_meta_; update_table_store_param.rebuild_seq_ = ls_->get_rebuild_seq(); if (OB_FAIL(update_table_store_param.tables_handle_.assign(tables_handle_))) { diff --git a/src/storage/high_availability/ob_physical_copy_task.h b/src/storage/high_availability/ob_physical_copy_task.h index 452c2d82b..0cb95ccb9 100644 --- a/src/storage/high_availability/ob_physical_copy_task.h +++ b/src/storage/high_availability/ob_physical_copy_task.h @@ -205,7 +205,8 @@ public: int init( const common::ObTabletID &tablet_id, ObLS *ls, - observer::ObIMetaReport *reporter); + observer::ObIMetaReport *reporter, + const ObMigrationTabletParam *src_tablet_meta); virtual int process() override; VIRTUAL_TO_STRING_KV(K("ObTabletCopyFinishTask"), KP(this)); int add_sstable(ObTableHandleV2 &table_handle); @@ -224,6 +225,7 @@ private: observer::ObIMetaReport *reporter_; ObStorageHADag *ha_dag_; ObTablesHandleArray tables_handle_; + const ObMigrationTabletParam *src_tablet_meta_; DISALLOW_COPY_AND_ASSIGN(ObTabletCopyFinishTask); }; diff --git a/src/storage/high_availability/ob_storage_ha_reader.cpp b/src/storage/high_availability/ob_storage_ha_reader.cpp index 1835e3445..0a72c9a2f 100644 --- a/src/storage/high_availability/ob_storage_ha_reader.cpp +++ b/src/storage/high_availability/ob_storage_ha_reader.cpp @@ -1150,19 +1150,27 @@ ObCopySSTableInfoRestoreReader::ObCopySSTableInfoRestoreReader() } int ObCopySSTableInfoRestoreReader::init( + const share::ObLSID &ls_id, const ObRestoreBaseInfo &restore_base_info, const common::ObIArray &tablet_id_array, backup::ObBackupMetaIndexStoreWrapper &meta_index_store) { int ret = OB_SUCCESS; + ObLSService *ls_service = nullptr; if (OB_UNLIKELY(is_inited_)) { ret = OB_INIT_TWICE; LOG_WARN("can not init twice", K(ret)); - } else if (OB_UNLIKELY(!restore_base_info.is_valid()) + } else if (OB_UNLIKELY(!ls_id.is_valid()) + || OB_UNLIKELY(!restore_base_info.is_valid()) || OB_UNLIKELY(tablet_id_array.empty())) { ret = OB_INVALID_ARGUMENT; - LOG_WARN("invalid argument", K(ret), K(restore_base_info), K(tablet_id_array)); + LOG_WARN("invalid argument", K(ret), K(ls_id), K(restore_base_info), K(tablet_id_array)); + } else if (OB_ISNULL(ls_service = MTL(ObLSService *))) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("ls service should not be null", K(ret), KP(ls_service)); + } else if (OB_FAIL(ls_service->get_ls(ls_id, ls_handle_, ObLSGetMod::HA_MOD))) { + LOG_WARN("fail to get log stream", KR(ret), K(ls_id)); } else if (OB_FAIL(tablet_id_array_.assign(tablet_id_array))) { LOG_WARN("failed to assign tablet id array", K(ret), K(tablet_id_array)); } else { @@ -1341,6 +1349,8 @@ int ObCopySSTableInfoRestoreReader::get_next_tablet_sstable_header( } else if (FALSE_IT(tablet_id = tablet_id_array_.at(tablet_index_))) { } else if (OB_FAIL(get_backup_sstable_metas_(tablet_id))) { LOG_WARN("failed to get backup sstable metas", K(ret), K(tablet_id), KPC(restore_base_info_)); + } else if (OB_FAIL(get_tablet_meta_(tablet_id, copy_header.tablet_meta_))) { + LOG_WARN("failed to get tablet meta", K(ret), K(tablet_id)); } else { sstable_index_ = 0; is_sstable_iter_end_ = false; @@ -1352,6 +1362,33 @@ int ObCopySSTableInfoRestoreReader::get_next_tablet_sstable_header( return ret; } +int ObCopySSTableInfoRestoreReader::get_tablet_meta_( + const common::ObTabletID &tablet_id, + ObMigrationTabletParam &tablet_meta) +{ + int ret = OB_SUCCESS; + ObLS *ls = nullptr; + ObTabletHandle tablet_handle; + ObTablet *tablet = nullptr; + + if (!is_inited_) { + ret = OB_NOT_INIT; + LOG_WARN("copy sstable info restore reader do not init", K(ret)); + } else if (OB_ISNULL(ls = ls_handle_.get_ls())) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("ls should not be NULL", K(ret), KP(ls)); + } else if (OB_FAIL(ls->get_tablet(tablet_id, tablet_handle, + ObTabletCommon::NO_CHECK_GET_TABLET_TIMEOUT_US))) { + LOG_WARN("failed to get tablet", K(ret), K(tablet_id)); + } else if (OB_ISNULL(tablet = tablet_handle.get_obj())) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("tablet should not be NULL", K(ret), KP(tablet), K(tablet_id)); + } else if (OB_FAIL(tablet->build_migration_tablet_param(tablet_meta))) { + LOG_WARN("failed to build migration tablet param", K(ret), K(tablet_id)); + } + return ret; +} + ObCopyTabletsSSTableInfoObProducer::ObCopyTabletsSSTableInfoObProducer() : is_inited_(false), @@ -1539,8 +1576,7 @@ int ObCopySSTableInfoObProducer::check_need_copy_sstable_( } else if (sstable->is_minor_sstable()) { if (tablet_sstable_info_.minor_sstable_log_ts_range_.is_empty()) { need_copy_sstable = false; - } else if (sstable->get_key().log_ts_range_.end_log_ts_ <= tablet_sstable_info_.minor_sstable_log_ts_range_.start_log_ts_ - || sstable->get_key().log_ts_range_.start_log_ts_ >= tablet_sstable_info_.minor_sstable_log_ts_range_.end_log_ts_) { + } else if (sstable->get_key().log_ts_range_.end_log_ts_ <= tablet_sstable_info_.minor_sstable_log_ts_range_.start_log_ts_) { need_copy_sstable = false; } else { need_copy_sstable = true; @@ -1632,14 +1668,35 @@ int ObCopySSTableInfoObProducer::get_copy_tablet_sstable_header( } else { copy_header.tablet_id_ = tablet_sstable_info_.tablet_id_; copy_header.status_ = status_; - if (ObCopyTabletStatus::TABLET_EXIST == status_ - && OB_FAIL(get_copy_sstable_count_(copy_header.sstable_count_))) { - LOG_WARN("failed to get copy sstable count", K(ret), K(tablet_sstable_info_)); + if (ObCopyTabletStatus::TABLET_EXIST == status_) { + if (OB_FAIL(get_tablet_meta_(copy_header.tablet_meta_))) { + LOG_WARN("failed to get tablet meta", K(ret), K(tablet_sstable_info_)); + } else if (OB_FAIL(get_copy_sstable_count_(copy_header.sstable_count_))) { + LOG_WARN("failed to get copy sstable count", K(ret), K(tablet_sstable_info_)); + } } } return ret; } +int ObCopySSTableInfoObProducer::get_tablet_meta_(ObMigrationTabletParam &tablet_meta) +{ + int ret = OB_SUCCESS; + tablet_meta.reset(); + ObTablet *tablet = nullptr; + + if (!is_inited_) { + ret = OB_NOT_INIT; + LOG_WARN("copy sstable info ob producer do not init", K(ret)); + } else if (OB_ISNULL(tablet = tablet_handle_.get_obj())) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("tablet should not be NULL", K(ret), KP(tablet)); + } else if (OB_FAIL(tablet->build_migration_tablet_param(tablet_meta))) { + LOG_WARN("failed to build migration tablet param", K(ret), KPC(tablet)); + } + return ret; +} + ObCopySSTableMacroObReader::ObCopySSTableMacroObReader() : is_inited_(false), diff --git a/src/storage/high_availability/ob_storage_ha_reader.h b/src/storage/high_availability/ob_storage_ha_reader.h index 76275a49b..09f678b3d 100644 --- a/src/storage/high_availability/ob_storage_ha_reader.h +++ b/src/storage/high_availability/ob_storage_ha_reader.h @@ -335,6 +335,7 @@ public: virtual ~ObCopySSTableInfoRestoreReader() {} int init( + const share::ObLSID &ls_id, const ObRestoreBaseInfo &restore_base_info, const common::ObIArray &tablet_id_array, backup::ObBackupMetaIndexStoreWrapper &meta_index_store); @@ -356,6 +357,9 @@ private: common::ObIArray &backup_sstable_meta_array); int set_backup_sstable_meta_array_( const common::ObIArray &backup_sstable_meta_array); + int get_tablet_meta_( + const common::ObTabletID &tablet_id, + ObMigrationTabletParam &tablet_meta); private: @@ -368,6 +372,8 @@ private: bool is_sstable_iter_end_; common::ObArray backup_sstable_meta_array_; common::ObArenaAllocator allocator_; + share::ObLSID ls_id_; + ObLSHandle ls_handle_; DISALLOW_COPY_AND_ASSIGN(ObCopySSTableInfoRestoreReader); }; @@ -408,6 +414,8 @@ private: blocksstable::ObSSTable *sstable, bool &need_copy_sstable); int get_copy_sstable_count_(int64_t &sstable_count); + int get_tablet_meta_(ObMigrationTabletParam &tablet_meta); + private: bool is_inited_; obrpc::ObCopyTabletSSTableInfoArg tablet_sstable_info_; diff --git a/src/storage/high_availability/ob_storage_ha_tablet_builder.cpp b/src/storage/high_availability/ob_storage_ha_tablet_builder.cpp index 1d1fd3b33..b94261eb4 100644 --- a/src/storage/high_availability/ob_storage_ha_tablet_builder.cpp +++ b/src/storage/high_availability/ob_storage_ha_tablet_builder.cpp @@ -318,7 +318,7 @@ int ObStorageHATabletsBuilder::create_or_update_tablet_( //do nothing } else if (OB_FAIL(param.tables_handle_.assign(tables_handle))) { LOG_WARN("failed to assign tables handle", K(ret), K(tables_handle), K(tablet_info)); - } else if (FALSE_IT(param.storage_schema_ = &tablet_info.param_.storage_schema_)) { + } else if (FALSE_IT(param.tablet_meta_ = &tablet_info.param_)) { } else if (FALSE_IT(param.rebuild_seq_ = ls->get_rebuild_seq())) { } else if (OB_FAIL(ls->build_ha_tablet_new_table_store(tablet_info.tablet_id_, param))) { LOG_WARN("failed to build ha tablet new table store", K(ret), K(tables_handle), K(tablet_info)); @@ -440,7 +440,8 @@ int ObStorageHATabletsBuilder::get_tablets_sstable_restore_reader_(ObICopySSTabl LOG_WARN("failed to alloc memory", K(ret), KP(buf)); } else if (FALSE_IT(restore_reader = new (buf) ObCopySSTableInfoRestoreReader())) { } else if (FALSE_IT(reader = restore_reader)) { - } else if (OB_FAIL(restore_reader->init(*param_.restore_base_info_, param_.tablet_id_array_, *param_.meta_index_store_))) { + } else if (OB_FAIL(restore_reader->init(param_.ls_->get_ls_id(), + *param_.restore_base_info_, param_.tablet_id_array_, *param_.meta_index_store_))) { LOG_WARN("failed to init restore reader", K(ret), K(param_)); } @@ -1058,7 +1059,6 @@ int ObStorageHATabletsBuilder::update_local_tablet_( LOG_WARN("local exist tablet data is complete, no need update local tablet", K(ret), KPC(tablet)); } else if (tablet->get_tablet_meta().start_scn_ == tablet_info.param_.start_scn_) { //do nothing - } else if (FALSE_IT(param.storage_schema_ = &tablet->get_storage_schema())) { } else if (FALSE_IT(param.rebuild_seq_ = ls->get_rebuild_seq())) { } else if (FALSE_IT(param.update_logical_minor_sstable_ = true)) { } else if (FALSE_IT(param.start_scn_ = tablet_info.param_.start_scn_)) { @@ -1085,15 +1085,20 @@ ObStorageHATableInfoMgr::ObStorageHATabletTableInfoMgr::~ObStorageHATabletTableI int ObStorageHATableInfoMgr::ObStorageHATabletTableInfoMgr::init( const ObTabletID &tablet_id, - const storage::ObCopyTabletStatus::STATUS &status) + const storage::ObCopyTabletStatus::STATUS &status, + const ObMigrationTabletParam &tablet_meta) { int ret = OB_SUCCESS; if (is_inited_) { ret = OB_INIT_TWICE; LOG_WARN("storage ha tablet table info mgr init twice", K(ret), K(tablet_id)); - } else if (!tablet_id.is_valid() || !ObCopyTabletStatus::is_valid(status)) { + } else if (!tablet_id.is_valid() || !ObCopyTabletStatus::is_valid(status) + || (ObCopyTabletStatus::TABLET_EXIST == status && !tablet_meta.is_valid())) { ret = OB_INVALID_ARGUMENT; - LOG_WARN("init storage ha tablet table info mgr get invalid argument", K(ret), K(tablet_id), K(status)); + LOG_WARN("init storage ha tablet table info mgr get invalid argument", K(ret), K(tablet_id), + K(status), K(tablet_meta)); + } else if (ObCopyTabletStatus::TABLET_EXIST == status && OB_FAIL(tablet_meta_.assign(tablet_meta))) { + LOG_WARN("failed to assign tablet meta", K(ret), K(tablet_meta)); } else { tablet_id_ = tablet_id; status_ = status; @@ -1197,6 +1202,22 @@ int ObStorageHATableInfoMgr::ObStorageHATabletTableInfoMgr::check_copy_tablet_ex return ret; } +int ObStorageHATableInfoMgr::ObStorageHATabletTableInfoMgr::get_tablet_meta(const ObMigrationTabletParam *&tablet_meta) +{ + int ret = OB_SUCCESS; + tablet_meta = nullptr; + if (!is_inited_) { + ret = OB_NOT_INIT; + LOG_WARN("storage ha tablet table info mgr do not init", K(ret)); + } else if (ObCopyTabletStatus::TABLET_EXIST != status_) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("src tablet do not exist, cannot get tablet meta", K(ret), K(status_)); + } else { + tablet_meta = &tablet_meta_; + } + return ret; +} + /******************ObStorageHATableInfoMgr*********************/ ObStorageHATableInfoMgr::ObStorageHATableInfoMgr() : is_inited_(false), @@ -1373,7 +1394,7 @@ int ObStorageHATableInfoMgr::init_tablet_info( ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("failed to alloc memory", K(ret), KP(buf)); } else if (FALSE_IT(tablet_table_info_mgr = new (buf) ObStorageHATabletTableInfoMgr())) { - } else if (OB_FAIL(tablet_table_info_mgr->init(copy_header.tablet_id_, copy_header.status_))) { + } else if (OB_FAIL(tablet_table_info_mgr->init(copy_header.tablet_id_, copy_header.status_, copy_header.tablet_meta_))) { LOG_WARN("failed to init tabelt table key mgr", K(ret), K(copy_header)); } else if (OB_FAIL(table_info_mgr_map_.set_refactored(copy_header.tablet_id_, tablet_table_info_mgr))) { LOG_WARN("failed to set tablet table key mgr into map", K(ret), K(copy_header)); @@ -1445,6 +1466,31 @@ int ObStorageHATableInfoMgr::check_tablet_table_info_exist( return ret; } +int ObStorageHATableInfoMgr::get_tablet_meta( + const common::ObTabletID &tablet_id, + const ObMigrationTabletParam *&tablet_meta) +{ + int ret = OB_SUCCESS; + tablet_meta = nullptr; + ObStorageHATabletTableInfoMgr *tablet_table_info_mgr = nullptr; + + if (!is_inited_) { + ret = OB_NOT_INIT; + LOG_WARN("storage ha tablet info mgr do not init", K(ret)); + } else if (!tablet_id.is_valid()) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("check copy tablet exist get invalid argument", K(ret), K(tablet_id)); + } else { + common::SpinRLockGuard guard(lock_); + if (OB_FAIL(table_info_mgr_map_.get_refactored(tablet_id, tablet_table_info_mgr))) { + LOG_WARN("failed to get tablet table info mgr", K(ret), K(tablet_id)); + } else if (OB_FAIL(tablet_table_info_mgr->get_tablet_meta(tablet_meta))) { + LOG_WARN("failed to get tablet meta", K(ret), K(tablet_id), KP(tablet_meta)); + } + } + return ret; +} + /******************ObStorageHACopySSTableParam*********************/ ObStorageHACopySSTableParam::ObStorageHACopySSTableParam() : tenant_id_(OB_INVALID_ID), diff --git a/src/storage/high_availability/ob_storage_ha_tablet_builder.h b/src/storage/high_availability/ob_storage_ha_tablet_builder.h index 21c0e3e65..7d854de02 100644 --- a/src/storage/high_availability/ob_storage_ha_tablet_builder.h +++ b/src/storage/high_availability/ob_storage_ha_tablet_builder.h @@ -159,6 +159,9 @@ public: int check_copy_tablet_exist(const common::ObTabletID &tablet_id, bool &is_exist); int check_tablet_table_info_exist( const common::ObTabletID &tablet_id, bool &is_exist); + int get_tablet_meta( + const common::ObTabletID &tablet_id, + const ObMigrationTabletParam *&tablet_meta); void reuse(); public: @@ -167,7 +170,9 @@ public: public: ObStorageHATabletTableInfoMgr(); virtual ~ObStorageHATabletTableInfoMgr(); - int init(const common::ObTabletID &tablet_id, const storage::ObCopyTabletStatus::STATUS &status); + int init(const common::ObTabletID &tablet_id, + const storage::ObCopyTabletStatus::STATUS &status, + const ObMigrationTabletParam &tablet_meta); int add_copy_table_info(const blocksstable::ObMigrationSSTableParam ©_table_info); int get_copy_table_info( const ObITable::TableKey &table_key, @@ -175,12 +180,13 @@ public: int get_table_keys( common::ObIArray &table_keys); int check_copy_tablet_exist(bool &is_exist); - + int get_tablet_meta(const ObMigrationTabletParam *&tablet_meta); private: bool is_inited_; common::ObTabletID tablet_id_; storage::ObCopyTabletStatus::STATUS status_; common::ObArray copy_table_info_array_; + ObMigrationTabletParam tablet_meta_; DISALLOW_COPY_AND_ASSIGN(ObStorageHATabletTableInfoMgr); }; diff --git a/src/storage/high_availability/ob_tablet_group_restore.cpp b/src/storage/high_availability/ob_tablet_group_restore.cpp index c90fbfa37..e0e3a4d82 100644 --- a/src/storage/high_availability/ob_tablet_group_restore.cpp +++ b/src/storage/high_availability/ob_tablet_group_restore.cpp @@ -2396,13 +2396,17 @@ int ObTabletRestoreTask::generate_tablet_copy_finish_task_( int ret = OB_SUCCESS; tablet_copy_finish_task = nullptr; observer::ObIMetaReport *reporter = GCTX.ob_service_; + const ObMigrationTabletParam *src_tablet_meta = nullptr; if (!is_inited_) { ret = OB_NOT_INIT; LOG_WARN("tablet restore task do not init", K(ret)); } else if (OB_FAIL(dag_->alloc_task(tablet_copy_finish_task))) { LOG_WARN("failed to alloc tablet copy finish task", K(ret), KPC(tablet_restore_ctx_)); - } else if (OB_FAIL(tablet_copy_finish_task->init(tablet_restore_ctx_->tablet_id_, ls_, reporter))) { + } else if (OB_FAIL(tablet_restore_ctx_->ha_table_info_mgr_->get_tablet_meta( + tablet_restore_ctx_->tablet_id_, src_tablet_meta))) { + LOG_WARN("failed to get src tablet meta", K(ret), KPC(tablet_restore_ctx_)); + } else if (OB_FAIL(tablet_copy_finish_task->init(tablet_restore_ctx_->tablet_id_, ls_, reporter, src_tablet_meta))) { LOG_WARN("failed to init tablet copy finish task", K(ret), KPC(ha_dag_net_ctx_), KPC(tablet_restore_ctx_)); } return ret; diff --git a/src/storage/ob_storage_rpc.cpp b/src/storage/ob_storage_rpc.cpp index 6f0672dbf..16878ec76 100644 --- a/src/storage/ob_storage_rpc.cpp +++ b/src/storage/ob_storage_rpc.cpp @@ -542,7 +542,8 @@ OB_SERIALIZE_MEMBER(ObCopySSTableMacroRangeInfoHeader, ObCopyTabletSSTableHeader::ObCopyTabletSSTableHeader() : tablet_id_(), status_(ObCopyTabletStatus::MAX_STATUS), - sstable_count_(0) + sstable_count_(0), + tablet_meta_() { } @@ -551,17 +552,20 @@ void ObCopyTabletSSTableHeader::reset() tablet_id_.reset(); status_ = ObCopyTabletStatus::MAX_STATUS; sstable_count_ = 0; + tablet_meta_.reset(); } bool ObCopyTabletSSTableHeader::is_valid() const { return tablet_id_.is_valid() && ObCopyTabletStatus::is_valid(status_) - && sstable_count_ >= 0; + && sstable_count_ >= 0 + && ((ObCopyTabletStatus::TABLET_EXIST == status_ && tablet_meta_.is_valid()) + || ObCopyTabletStatus::TABLET_NOT_EXIST == status_); } OB_SERIALIZE_MEMBER(ObCopyTabletSSTableHeader, - tablet_id_, status_, sstable_count_); + tablet_id_, status_, sstable_count_, tablet_meta_); ObNotifyRestoreTabletsArg::ObNotifyRestoreTabletsArg() : tenant_id_(OB_INVALID_ID), ls_id_(), tablet_id_array_(), restore_status_() diff --git a/src/storage/ob_storage_rpc.h b/src/storage/ob_storage_rpc.h index 1fc3fa15a..1793d0302 100644 --- a/src/storage/ob_storage_rpc.h +++ b/src/storage/ob_storage_rpc.h @@ -326,11 +326,12 @@ public: ~ObCopyTabletSSTableHeader() {} void reset(); bool is_valid() const; - TO_STRING_KV(K_(tablet_id), K_(status), K_(sstable_count)); + TO_STRING_KV(K_(tablet_id), K_(status), K_(sstable_count), K_(tablet_meta)); common::ObTabletID tablet_id_; storage::ObCopyTabletStatus::STATUS status_; int64_t sstable_count_; + ObMigrationTabletParam tablet_meta_; }; // Leader notify follower to restore some tablets. diff --git a/src/storage/ob_storage_struct.cpp b/src/storage/ob_storage_struct.cpp index 1886cd50d..dfcdd5183 100644 --- a/src/storage/ob_storage_struct.cpp +++ b/src/storage/ob_storage_struct.cpp @@ -288,11 +288,11 @@ ObBatchUpdateTableStoreParam::ObBatchUpdateTableStoreParam() : tables_handle_(), snapshot_version_(0), multi_version_start_(0), - storage_schema_(nullptr), need_report_(false), rebuild_seq_(OB_INVALID_VERSION), update_logical_minor_sstable_(false), - start_scn_(0) + start_scn_(0), + tablet_meta_(nullptr) { } @@ -300,20 +300,20 @@ void ObBatchUpdateTableStoreParam::reset() { tables_handle_.reset(); multi_version_start_ = 0; - storage_schema_ = nullptr; need_report_ = false; rebuild_seq_ = OB_INVALID_VERSION; update_logical_minor_sstable_ = false; start_scn_ = 0; + tablet_meta_ = nullptr; } bool ObBatchUpdateTableStoreParam::is_valid() const { return snapshot_version_ >= 0 && multi_version_start_ >= 0 - && OB_NOT_NULL(storage_schema_) && rebuild_seq_ > OB_INVALID_VERSION - && (!update_logical_minor_sstable_ || (update_logical_minor_sstable_ && start_scn_ > 0)); + && ((!update_logical_minor_sstable_ && OB_NOT_NULL(tablet_meta_)) + || (update_logical_minor_sstable_ && start_scn_ > 0)); } int ObBatchUpdateTableStoreParam::assign( @@ -327,11 +327,11 @@ int ObBatchUpdateTableStoreParam::assign( LOG_WARN("failed to assign tables handle", K(ret), K(param)); } else { multi_version_start_ = param.multi_version_start_; - storage_schema_ = param.storage_schema_; need_report_ = param.need_report_; rebuild_seq_ = param.rebuild_seq_; update_logical_minor_sstable_ = param.update_logical_minor_sstable_; start_scn_ = param.start_scn_; + tablet_meta_ = param.tablet_meta_; } return ret; } @@ -359,7 +359,6 @@ int ObBatchUpdateTableStoreParam::get_max_clog_checkpoint_ts(int64_t &clog_check return ret; } - ObPartitionReadableInfo::ObPartitionReadableInfo() : min_log_service_ts_(0), min_trans_service_ts_(0), diff --git a/src/storage/ob_storage_struct.h b/src/storage/ob_storage_struct.h index 007b36706..0acc6b64f 100644 --- a/src/storage/ob_storage_struct.h +++ b/src/storage/ob_storage_struct.h @@ -33,6 +33,7 @@ class ObLSTxCtxMgr; namespace storage { class ObStorageSchema; +class ObMigrationTabletParam; typedef common::ObSEArray GetRowkeyArray; typedef common::ObSEArray ScanRangeArray; @@ -341,16 +342,16 @@ struct ObBatchUpdateTableStoreParam final int get_max_clog_checkpoint_ts(int64_t &clog_checkpoint_ts) const; TO_STRING_KV(K_(tables_handle), K_(snapshot_version), K_(multi_version_start), K_(need_report), - KPC_(storage_schema), K_(rebuild_seq), K_(update_logical_minor_sstable), K_(start_scn)); + K_(rebuild_seq), K_(update_logical_minor_sstable), K_(start_scn), KP_(tablet_meta)); ObTablesHandleArray tables_handle_; int64_t snapshot_version_; int64_t multi_version_start_; - const ObStorageSchema *storage_schema_; bool need_report_; int64_t rebuild_seq_; bool update_logical_minor_sstable_; int64_t start_scn_; + const ObMigrationTabletParam *tablet_meta_; DISALLOW_COPY_AND_ASSIGN(ObBatchUpdateTableStoreParam); }; diff --git a/src/storage/tablet/ob_tablet.cpp b/src/storage/tablet/ob_tablet.cpp index c9dde27ba..4c18a13dc 100644 --- a/src/storage/tablet/ob_tablet.cpp +++ b/src/storage/tablet/ob_tablet.cpp @@ -326,6 +326,7 @@ int ObTablet::init( int ret = OB_SUCCESS; allocator_ = &(MTL(ObTenantMetaMemMgr*)->get_tenant_allocator()); int64_t max_sync_schema_version = 0; + const ObStorageSchema *storage_schema = nullptr; if (OB_UNLIKELY(is_inited_)) { ret = OB_INIT_TWICE; @@ -340,15 +341,16 @@ int ObTablet::init( LOG_WARN("tablet pointer handle is invalid", K(ret), K_(pointer_hdl), K_(memtable_mgr), K_(log_handler)); } else if (OB_FAIL(old_tablet.get_max_sync_storage_schema_version(max_sync_schema_version))) { LOG_WARN("failed to get max sync storage schema version", K(ret)); - } else if (OB_FAIL(tablet_meta_.init(*allocator_, old_tablet.tablet_meta_, - param.snapshot_version_, param.multi_version_start_, tx_data, ddl_data, autoinc_seq, - // use min schema version to avoid lose storage_schema in replay/reboot - // use old tablet clog_checkpoint_ts to avoid lose storage schema in migration - MIN(MAX(param.storage_schema_->schema_version_, old_tablet.storage_schema_.schema_version_), max_sync_schema_version)))) { + } else if (FALSE_IT(storage_schema = OB_ISNULL(param.tablet_meta_) ? &old_tablet.storage_schema_ : ¶m.tablet_meta_->storage_schema_)) { + } else if (OB_FAIL(tablet_meta_.init(*allocator_, old_tablet.tablet_meta_, tx_data, ddl_data, autoinc_seq, param.tablet_meta_ + // this interface for migration to batch update table store + // use old tablet clog_checkpoint_ts to avoid lose tx data + // use max schema to makesure sstable and schema match + ))) { LOG_WARN("failed to init tablet meta", K(ret), K(old_tablet), K(param), K(tx_data), K(ddl_data), K(autoinc_seq)); } else if (OB_FAIL(table_store_.build_ha_new_table_store(*allocator_, this, param, old_tablet.table_store_))) { LOG_WARN("failed to init table store", K(ret), K(old_tablet)); - } else if (OB_FAIL(choose_and_save_storage_schema(*allocator_, old_tablet.storage_schema_, *param.storage_schema_))) { + } else if (OB_FAIL(choose_and_save_storage_schema(*allocator_, old_tablet.storage_schema_, *storage_schema))) { LOG_WARN("failed to choose and save storage schema", K(ret), K(old_tablet), K(param)); } else if (OB_FAIL(try_update_start_scn())) { LOG_WARN("failed to update start scn", K(ret), K(param), K(table_store_)); diff --git a/src/storage/tablet/ob_tablet.h b/src/storage/tablet/ob_tablet.h index 8f729aa71..ae8f8f4ee 100644 --- a/src/storage/tablet/ob_tablet.h +++ b/src/storage/tablet/ob_tablet.h @@ -476,6 +476,7 @@ private: // we keep it on tablet because we cannot get them in ObTablet::deserialize // through ObTabletPointerHandle. // may be some day will fix this issue, then the pointers have no need to exist. + ObIMemtableMgr *memtable_mgr_; logservice::ObLogHandler *log_handler_; @@ -484,6 +485,11 @@ private: ObTableReadInfo full_read_info_; common::ObIAllocator *allocator_; ObMetaObjGuard next_tablet_guard_; + + //ATTENTION : Add a new variable need consider ObMigrationTabletParam + // and tablet meta init interface for migration. + // yuque : https://yuque.antfin.com/ob/ob-backup/zzwpuh + bool is_inited_; }; diff --git a/src/storage/tablet/ob_tablet_meta.cpp b/src/storage/tablet/ob_tablet_meta.cpp index b7ecaafc4..c1d13ae10 100644 --- a/src/storage/tablet/ob_tablet_meta.cpp +++ b/src/storage/tablet/ob_tablet_meta.cpp @@ -229,6 +229,75 @@ int ObTabletMeta::init( return ret; } +int ObTabletMeta::init( + common::ObIAllocator &allocator, + const ObTabletMeta &old_tablet_meta, + const ObTabletTxMultiSourceDataUnit &tx_data, + const ObTabletBindingInfo &ddl_data, + const share::ObTabletAutoincSeq &autoinc_seq, + const ObMigrationTabletParam *tablet_meta) +{ + int ret = OB_SUCCESS; + + if (OB_UNLIKELY(is_inited_)) { + ret = OB_INIT_TWICE; + LOG_WARN("init twice", K(ret), K_(is_inited)); + } else if (OB_UNLIKELY(!old_tablet_meta.is_valid())) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid args", K(ret), K(old_tablet_meta)); + } else if (OB_FAIL(inner_check_(old_tablet_meta, tablet_meta))) { + LOG_WARN("failed to do inner check", K(ret), K(old_tablet_meta), KP(tablet_meta)); + } else { + const int64_t snapshot_version = OB_ISNULL(tablet_meta) ? + old_tablet_meta.snapshot_version_ : MAX(old_tablet_meta.snapshot_version_, tablet_meta->snapshot_version_); + const int64_t multi_version_start = OB_ISNULL(tablet_meta) ? + old_tablet_meta.multi_version_start_ : MAX(old_tablet_meta.multi_version_start_, tablet_meta->multi_version_start_); + const int64_t max_sync_storage_schema_version = OB_ISNULL(tablet_meta) ? + old_tablet_meta.max_sync_storage_schema_version_ : MIN(old_tablet_meta.max_sync_storage_schema_version_, + tablet_meta->max_sync_storage_schema_version_); + ObTabletTableStoreFlag table_store_flag = old_tablet_meta.table_store_flag_; + if (!table_store_flag.with_major_sstable()) { + table_store_flag = OB_ISNULL(tablet_meta) ? table_store_flag : tablet_meta->table_store_flag_; + } + + version_ = TABLET_META_VERSION; + ls_id_ = old_tablet_meta.ls_id_; + tablet_id_ = old_tablet_meta.tablet_id_; + data_tablet_id_ = old_tablet_meta.data_tablet_id_; + ref_tablet_id_ = old_tablet_meta.ref_tablet_id_; + create_scn_ = old_tablet_meta.create_scn_; + start_scn_ = old_tablet_meta.start_scn_; + clog_checkpoint_ts_ = old_tablet_meta.clog_checkpoint_ts_; + ddl_checkpoint_ts_ = old_tablet_meta.ddl_checkpoint_ts_; + snapshot_version_ = snapshot_version; + multi_version_start_ = multi_version_start; + compat_mode_ = old_tablet_meta.compat_mode_; + if (FAILEDx(autoinc_seq_.assign(autoinc_seq))) { + LOG_WARN("failed to assign autoinc seq", K(ret)); + } + ha_status_ = old_tablet_meta.ha_status_; + report_status_ = old_tablet_meta.report_status_; + tx_data_ = tx_data; + if (FAILEDx(ddl_data_.assign(ddl_data))) { + LOG_WARN("failed to assign ddl data", K(ret)); + } + table_store_flag_ = table_store_flag; + ddl_checkpoint_ts_ = old_tablet_meta.ddl_checkpoint_ts_; + ddl_start_log_ts_ = old_tablet_meta.ddl_start_log_ts_; + ddl_snapshot_version_ = old_tablet_meta.ddl_snapshot_version_; + max_sync_storage_schema_version_ = max_sync_storage_schema_version; + + if (OB_SUCC(ret)) { + is_inited_ = true; + } + } + + if (OB_UNLIKELY(!is_inited_)) { + reset(); + } + return ret; +} + void ObTabletMeta::reset() { version_ = 0; @@ -581,6 +650,29 @@ int ObTabletMeta::update_create_scn(const int64_t create_scn) return ret; } +int ObTabletMeta::inner_check_( + const ObTabletMeta &old_tablet_meta, + const ObMigrationTabletParam *tablet_meta) +{ + int ret = OB_SUCCESS; + if (!old_tablet_meta.is_valid()) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("inner check get invalid argument", K(ret), K(old_tablet_meta)); + } else if (OB_ISNULL(tablet_meta)) { + //do nohting + } else if (OB_FAIL(old_tablet_meta.ls_id_ != tablet_meta->ls_id_ + || old_tablet_meta.tablet_id_ != tablet_meta->tablet_id_ + || old_tablet_meta.data_tablet_id_ != tablet_meta->data_tablet_id_ + || old_tablet_meta.ref_tablet_id_ != tablet_meta->ref_tablet_id_ + || old_tablet_meta.compat_mode_ != tablet_meta->compat_mode_)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("old tablet meta part variable is not same with migration tablet param", + K(ret), K(old_tablet_meta), KPC(tablet_meta)); + } + return ret; +} + + ObMigrationTabletParam::ObMigrationTabletParam() : allocator_(), ls_id_(), diff --git a/src/storage/tablet/ob_tablet_meta.h b/src/storage/tablet/ob_tablet_meta.h index 0d4fb7613..336faa0d1 100644 --- a/src/storage/tablet/ob_tablet_meta.h +++ b/src/storage/tablet/ob_tablet_meta.h @@ -78,6 +78,14 @@ public: int init( common::ObIAllocator &allocator, const ObMigrationTabletParam ¶m); + int init( + common::ObIAllocator &allocator, + const ObTabletMeta &old_tablet_meta, + const ObTabletTxMultiSourceDataUnit &tx_data, + const ObTabletBindingInfo &ddl_data, + const share::ObTabletAutoincSeq &autoinc_seq, + const ObMigrationTabletParam *tablet_meta); + void reset(); bool is_valid() const; @@ -151,7 +159,14 @@ public: int64_t ddl_start_log_ts_; int64_t ddl_snapshot_version_; int64_t max_sync_storage_schema_version_; + //ATTENTION : Add a new variable need consider ObMigrationTabletParam + // and tablet meta init interface for migration. + // yuque : https://yuque.antfin.com/ob/ob-backup/zzwpuh +private: + int inner_check_( + const ObTabletMeta &old_tablet_meta, + const ObMigrationTabletParam *tablet_meta); private: static const int32_t TABLET_META_VERSION = 1; private: