diff --git a/src/storage/ddl/ob_ddl_clog.cpp b/src/storage/ddl/ob_ddl_clog.cpp index 80fbf41dae..a3c68bbd04 100644 --- a/src/storage/ddl/ob_ddl_clog.cpp +++ b/src/storage/ddl/ob_ddl_clog.cpp @@ -391,7 +391,8 @@ DEFINE_GET_SERIALIZE_SIZE(ObDDLClogHeader) } ObDDLStartLog::ObDDLStartLog() - : table_key_(), data_format_version_(0), execution_id_(-1), direct_load_type_(ObDirectLoadType::DIRECT_LOAD_DDL) /*for compatibility*/ + : table_key_(), data_format_version_(0), execution_id_(-1), direct_load_type_(ObDirectLoadType::DIRECT_LOAD_DDL) /*for compatibility*/, + lob_meta_tablet_id_(ObDDLClog::COMPATIBLE_LOB_META_TABLET_ID) { } @@ -399,22 +400,25 @@ int ObDDLStartLog::init( const ObITable::TableKey &table_key, const uint64_t data_format_version, const int64_t execution_id, - const ObDirectLoadType direct_load_type) + const ObDirectLoadType direct_load_type, + const ObTabletID &lob_meta_tablet_id) { int ret = OB_SUCCESS; - if (OB_UNLIKELY(!table_key.is_valid() || execution_id < 0 || data_format_version <= 0 || !is_valid_direct_load(direct_load_type))) { + if (OB_UNLIKELY(!table_key.is_valid() || execution_id < 0 || data_format_version <= 0 || !is_valid_direct_load(direct_load_type) + || ObDDLClog::COMPATIBLE_LOB_META_TABLET_ID == lob_meta_tablet_id.id())) { ret = OB_INVALID_ARGUMENT; - LOG_WARN("invalid argument", K(ret), K(table_key), K(execution_id), K(data_format_version), K(direct_load_type)); + LOG_WARN("invalid argument", K(ret), K(table_key), K(execution_id), K(data_format_version), K(direct_load_type), K(lob_meta_tablet_id)); } else { table_key_ = table_key; data_format_version_ = data_format_version; execution_id_ = execution_id; direct_load_type_ = direct_load_type; + lob_meta_tablet_id_ = lob_meta_tablet_id; } return ret; } -OB_SERIALIZE_MEMBER(ObDDLStartLog, table_key_, data_format_version_, execution_id_, direct_load_type_); +OB_SERIALIZE_MEMBER(ObDDLStartLog, table_key_, data_format_version_, execution_id_, direct_load_type_, lob_meta_tablet_id_); ObDDLRedoLog::ObDDLRedoLog() : redo_info_() @@ -436,25 +440,28 @@ int ObDDLRedoLog::init(const blocksstable::ObDDLMacroBlockRedoInfo &redo_info) OB_SERIALIZE_MEMBER(ObDDLRedoLog, redo_info_); ObDDLCommitLog::ObDDLCommitLog() - : table_key_(), start_scn_(SCN::min_scn()) + : table_key_(), start_scn_(SCN::min_scn()), lob_meta_tablet_id_(ObDDLClog::COMPATIBLE_LOB_META_TABLET_ID) { } int ObDDLCommitLog::init(const ObITable::TableKey &table_key, - const SCN &start_scn) + const SCN &start_scn, + const ObTabletID &lob_meta_tablet_id) { int ret = OB_SUCCESS; - if (!table_key.is_valid() || !start_scn.is_valid_and_not_min()) { + if (OB_UNLIKELY(!table_key.is_valid() || !start_scn.is_valid_and_not_min() + || ObDDLClog::COMPATIBLE_LOB_META_TABLET_ID == lob_meta_tablet_id.id())) { ret = OB_INVALID_ARGUMENT; - LOG_WARN("invalid argument", K(ret), K(table_key), K(start_scn)); + LOG_WARN("invalid argument", K(ret), K(table_key), K(start_scn), K(lob_meta_tablet_id)); } else { table_key_ = table_key; start_scn_ = start_scn; + lob_meta_tablet_id_ = lob_meta_tablet_id; } return ret; } -OB_SERIALIZE_MEMBER(ObDDLCommitLog, table_key_, start_scn_); +OB_SERIALIZE_MEMBER(ObDDLCommitLog, table_key_, start_scn_, lob_meta_tablet_id_); ObTabletSchemaVersionChangeLog::ObTabletSchemaVersionChangeLog() diff --git a/src/storage/ddl/ob_ddl_clog.h b/src/storage/ddl/ob_ddl_clog.h index c029c6ab4c..cc7fe3b71e 100644 --- a/src/storage/ddl/ob_ddl_clog.h +++ b/src/storage/ddl/ob_ddl_clog.h @@ -180,24 +180,36 @@ private: ObDDLClogType ddl_clog_type_; }; +class ObDDLClog +{ +public: + static const uint64_t COMPATIBLE_LOB_META_TABLET_ID = 1; +}; + class ObDDLStartLog final { OB_UNIS_VERSION_V(1); public: ObDDLStartLog(); ~ObDDLStartLog() = default; - int init(const ObITable::TableKey &table_key, const uint64_t data_format_version, const int64_t execution_id, const ObDirectLoadType direct_load_type); + int init(const ObITable::TableKey &table_key, + const uint64_t data_format_version, + const int64_t execution_id, + const ObDirectLoadType direct_load_type, + const ObTabletID &lob_meta_tablet_id); bool is_valid() const { return table_key_.is_valid() && data_format_version_ >= 0 && execution_id_ >= 0 && is_valid_direct_load(direct_load_type_); } ObITable::TableKey get_table_key() const { return table_key_; } uint64_t get_data_format_version() const { return data_format_version_; } int64_t get_execution_id() const { return execution_id_; } ObDirectLoadType get_direct_load_type() const { return direct_load_type_; } - TO_STRING_KV(K_(table_key), K_(data_format_version), K_(execution_id), K_(direct_load_type)); + const ObTabletID &get_lob_meta_tablet_id() const { return lob_meta_tablet_id_; } + TO_STRING_KV(K_(table_key), K_(data_format_version), K_(execution_id), K_(direct_load_type), K_(lob_meta_tablet_id)); private: ObITable::TableKey table_key_; // use table type to distinguish column store, column group id is valid uint64_t data_format_version_; // used for compatibility int64_t execution_id_; ObDirectLoadType direct_load_type_; + ObTabletID lob_meta_tablet_id_; // avoid replay get newest mds data }; class ObDDLRedoLog final @@ -221,14 +233,17 @@ public: ObDDLCommitLog(); ~ObDDLCommitLog() = default; int init(const ObITable::TableKey &table_key, - const share::SCN &start_scn); + const share::SCN &start_scn, + const ObTabletID &lob_meta_tablet_id); bool is_valid() const { return table_key_.is_valid() && start_scn_.is_valid(); } ObITable::TableKey get_table_key() const { return table_key_; } share::SCN get_start_scn() const { return start_scn_; } - TO_STRING_KV(K_(table_key), K_(start_scn)); + const ObTabletID &get_lob_meta_tablet_id() const { return lob_meta_tablet_id_; } + TO_STRING_KV(K_(table_key), K_(start_scn), K_(lob_meta_tablet_id)); private: ObITable::TableKey table_key_; share::SCN start_scn_; + ObTabletID lob_meta_tablet_id_; // avoid replay get newest mds data }; class ObTabletSchemaVersionChangeLog final diff --git a/src/storage/ddl/ob_ddl_redo_log_writer.cpp b/src/storage/ddl/ob_ddl_redo_log_writer.cpp index 08f5c3be33..35f7bec4a0 100644 --- a/src/storage/ddl/ob_ddl_redo_log_writer.cpp +++ b/src/storage/ddl/ob_ddl_redo_log_writer.cpp @@ -1135,7 +1135,8 @@ int ObDDLRedoLogWriter::write_start_log( } else if (OB_UNLIKELY(!table_key.is_valid() || execution_id < 0 || data_format_version <= 0 || !is_valid_direct_load(direct_load_type))) { ret = OB_INVALID_ARGUMENT; LOG_WARN("invalid arguments", K(ret), K(table_key), K(execution_id), K(data_format_version), K(direct_load_type)); - } else if (OB_FAIL(log.init(table_key, data_format_version, execution_id, direct_load_type))) { + } else if (OB_FAIL(log.init(table_key, data_format_version, execution_id, direct_load_type, + lob_kv_mgr_handle.is_valid() ? lob_kv_mgr_handle.get_obj()->get_tablet_id() : ObTabletID()))) { LOG_WARN("fail to init DDLStartLog", K(ret), K(table_key), K(execution_id), K(data_format_version)); } else if (OB_FAIL(MTL(ObLSService *)->get_ls(ls_id_, ls_handle, ObLSGetMod::DDL_MOD))) { LOG_WARN("get ls failed", K(ret), K(ls_id_)); @@ -1282,14 +1283,17 @@ int ObDDLRedoLogWriter::write_commit_log( ObLS *ls = nullptr; ObDDLCommitLog log; ObDDLCommitLogHandle handle; + ObTabletBindingMdsUserData ddl_data; if (OB_UNLIKELY(!is_inited_)) { ret = OB_NOT_INIT; LOG_WARN("ddl redo log writer has not been inited", K(ret)); } else if (OB_UNLIKELY(!table_key.is_valid() || !start_scn.is_valid_and_not_min())) { ret = OB_INVALID_ARGUMENT; LOG_WARN("invalid arguments", K(ret), K(table_key), K(start_scn)); - } else if (OB_FAIL(log.init(table_key, start_scn))) { - LOG_WARN("fail to init DDLCommitLog", K(ret), K(table_key), K(start_scn)); + } else if (OB_FAIL(tablet_handle.get_obj()->ObITabletMdsInterface::get_ddl_data(share::SCN::max_scn(), ddl_data))) { + LOG_WARN("failed to get ddl data from tablet", K(ret), K(tablet_handle)); + } else if (OB_FAIL(log.init(table_key, start_scn, ddl_data.lob_meta_tablet_id_))) { + LOG_WARN("fail to init DDLCommitLog", K(ret), K(table_key), K(start_scn), K(ddl_data.lob_meta_tablet_id_)); } else if (OB_FAIL(MTL(ObLSService *)->get_ls(ls_id_, ls_handle, ObLSGetMod::DDL_MOD))) { LOG_WARN("get ls failed", K(ret), K(ls_id_)); } else if (OB_ISNULL(ls = ls_handle.get_ls())) { diff --git a/src/storage/ddl/ob_ddl_replay_executor.cpp b/src/storage/ddl/ob_ddl_replay_executor.cpp index ee54e18735..1a2c423698 100644 --- a/src/storage/ddl/ob_ddl_replay_executor.cpp +++ b/src/storage/ddl/ob_ddl_replay_executor.cpp @@ -42,7 +42,6 @@ int ObDDLReplayExecutor::check_need_replay_ddl_log_( ObTablet *tablet = nullptr; ObDDLKvMgrHandle ddl_kv_mgr_handle; ObMigrationStatus migration_status; - ObTabletBindingMdsUserData ddl_data; if (OB_UNLIKELY(nullptr == ls || !tablet_handle.is_valid() || !ddl_start_scn.is_valid_and_not_min() || !scn.is_valid_and_not_min())) { ret = OB_INVALID_ARGUMENT; LOG_WARN("not init", K(ret), KP(ls), K(tablet_handle), K(ddl_start_scn), K(scn)); @@ -79,21 +78,31 @@ int ObDDLReplayExecutor::check_need_replay_ddl_log_( LOG_INFO("no need to replay ddl log, because the ddl start log ts is less than the value in ddl kv manager", K(tablet_handle), K(ddl_start_scn), "ddl_start_scn_in_tablet", tablet->get_tablet_meta().ddl_start_scn_); } - } else if (OB_FAIL(tablet_handle.get_obj()->ObITabletMdsInterface::get_ddl_data(share::SCN::max_scn(), ddl_data))) { - LOG_WARN("failed to get ddl data from tablet", K(ret), K(tablet_handle)); - } else if (ddl_data.lob_meta_tablet_id_.is_valid()) { - ObTabletHandle lob_tablet_handle; - const ObTabletID lob_tablet_id = ddl_data.lob_meta_tablet_id_; - if (OB_FAIL(ls->replay_get_tablet_no_check(lob_tablet_id, scn, lob_tablet_handle))) { - LOG_WARN("get tablet handle failed", K(ret), K(lob_tablet_id), K(scn)); - } else if (lob_tablet_handle.get_obj()->is_empty_shell()) { - need_replay = false; - LOG_INFO("lob tablet is empty shell, skip replay", K(ret), "tablet_id", tablet->get_tablet_id(), K(lob_tablet_id)); - } } return ret; } +int ObDDLReplayExecutor::get_lob_meta_tablet_id( + const ObTabletHandle &tablet_handle, + const common::ObTabletID &possible_lob_meta_tablet_id, + common::ObTabletID &lob_meta_tablet_id) +{ + int ret = OB_SUCCESS; + if (OB_UNLIKELY(!tablet_handle.is_valid())) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid argument", K(ret), K(tablet_handle)); + } else if (ObDDLClog::COMPATIBLE_LOB_META_TABLET_ID == possible_lob_meta_tablet_id.id()) { // compatible code + ObTabletBindingMdsUserData ddl_data; + if (OB_FAIL(tablet_handle.get_obj()->ObITabletMdsInterface::get_ddl_data(share::SCN::max_scn(), ddl_data))) { + LOG_WARN("failed to get ddl data from tablet", K(ret), K(tablet_handle)); + } else { + lob_meta_tablet_id = ddl_data.lob_meta_tablet_id_; + } + } else { + lob_meta_tablet_id = possible_lob_meta_tablet_id; + } + return ret; +} // ObDDLStartReplayExecutor ObDDLStartReplayExecutor::ObDDLStartReplayExecutor() @@ -129,18 +138,17 @@ int ObDDLStartReplayExecutor::init( int ObDDLStartReplayExecutor::do_replay_(ObTabletHandle &tablet_handle) { int ret = OB_SUCCESS; - ObTabletBindingMdsUserData ddl_data; + ObTabletID lob_meta_tablet_id; if (OB_UNLIKELY(!is_inited_)) { ret = OB_NOT_INIT; LOG_WARN("ObDDLRedoLogReplayer has not been inited", K(ret)); } else if (OB_UNLIKELY(!log_->is_valid() || !tablet_handle.is_valid())) { ret = OB_INVALID_ARGUMENT; LOG_WARN("invalid arguments", K(ret), K_(log), K(tablet_handle)); - } else if (OB_FAIL(tablet_handle.get_obj()->ObITabletMdsInterface::get_ddl_data(share::SCN::max_scn(), ddl_data))) { - LOG_WARN("failed to get ddl data from tablet", K(ret), K(tablet_handle)); - } else if (ddl_data.lob_meta_tablet_id_.is_valid()) { + } else if (OB_FAIL(ObDDLReplayExecutor::get_lob_meta_tablet_id(tablet_handle, log_->get_lob_meta_tablet_id(), lob_meta_tablet_id))) { + LOG_WARN("get lob meta tablet id failed", K(ret)); + } else if (lob_meta_tablet_id.is_valid()) { ObTabletHandle lob_meta_tablet_handle; - const ObTabletID &lob_meta_tablet_id = ddl_data.lob_meta_tablet_id_; if (OB_FAIL(ls_->replay_get_tablet_no_check(lob_meta_tablet_id, scn_, lob_meta_tablet_handle))) { LOG_WARN("get tablet handle failed", K(ret), K(lob_meta_tablet_id), K(scn_)); } else if (OB_FAIL(replay_ddl_start(lob_meta_tablet_handle, true/*is_lob_meta_tablet*/))) { @@ -404,18 +412,17 @@ int ObDDLCommitReplayExecutor::init( int ObDDLCommitReplayExecutor::do_replay_(ObTabletHandle &tablet_handle) { int ret = OB_SUCCESS; - ObTabletBindingMdsUserData ddl_data; + ObTabletID lob_meta_tablet_id; if (OB_UNLIKELY(!is_inited_)) { ret = OB_NOT_INIT; LOG_WARN("ObDDLRedoLogReplayer has not been inited", K(ret)); } else if (OB_UNLIKELY(!log_->is_valid() || !tablet_handle.is_valid())) { ret = OB_INVALID_ARGUMENT; LOG_WARN("invalid arguments", K(ret), K_(log), K(tablet_handle)); - } else if (OB_FAIL(tablet_handle.get_obj()->ObITabletMdsInterface::get_ddl_data(share::SCN::max_scn(), ddl_data))) { - LOG_WARN("failed to get ddl data from tablet", K(ret), K(tablet_handle)); - } else if (ddl_data.lob_meta_tablet_id_.is_valid()) { + } else if (OB_FAIL(ObDDLReplayExecutor::get_lob_meta_tablet_id(tablet_handle, log_->get_lob_meta_tablet_id(), lob_meta_tablet_id))) { + LOG_WARN("get lob meta tablet id failed", K(ret)); + } else if (lob_meta_tablet_id.is_valid()) { ObTabletHandle lob_meta_tablet_handle; - const ObTabletID &lob_meta_tablet_id = ddl_data.lob_meta_tablet_id_; if (OB_FAIL(ls_->replay_get_tablet_no_check(lob_meta_tablet_id, scn_, lob_meta_tablet_handle))) { LOG_WARN("get tablet handle failed", K(ret), K(lob_meta_tablet_id), K(scn_)); } else if (OB_FAIL(replay_ddl_commit(lob_meta_tablet_handle))) { diff --git a/src/storage/ddl/ob_ddl_replay_executor.h b/src/storage/ddl/ob_ddl_replay_executor.h index ab8a1a10ab..be673aa78a 100644 --- a/src/storage/ddl/ob_ddl_replay_executor.h +++ b/src/storage/ddl/ob_ddl_replay_executor.h @@ -45,6 +45,12 @@ protected: const share::SCN &scn, bool &need_replay); + static int get_lob_meta_tablet_id( + const ObTabletHandle &tablet_handle, + const common::ObTabletID &possible_lob_meta_tablet_id, + common::ObTabletID &lob_meta_tablet_id); + + virtual bool is_replay_update_mds_table_() const override { return false;