placeholder for mds data source type and related mds ctx
Co-authored-by: fengdeyiji <546976189@qq.com>
This commit is contained in:
		| @ -677,6 +677,9 @@ ob_set_subtarget(ob_storage multi_data_source | |||||||
|   multi_data_source/ob_mds_table_merge_dag.cpp |   multi_data_source/ob_mds_table_merge_dag.cpp | ||||||
|   multi_data_source/ob_mds_table_merge_dag_param.cpp |   multi_data_source/ob_mds_table_merge_dag_param.cpp | ||||||
|   multi_data_source/ob_mds_table_merge_task.cpp |   multi_data_source/ob_mds_table_merge_task.cpp | ||||||
|  |   multi_data_source/ob_start_transfer_in_mds_ctx.cpp | ||||||
|  |   multi_data_source/ob_finish_transfer_in_mds_ctx.cpp | ||||||
|  |   multi_data_source/ob_tablet_create_mds_ctx.cpp | ||||||
|   multi_data_source/test/example_user_helper_define.cpp |   multi_data_source/test/example_user_helper_define.cpp | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | |||||||
| @ -10,6 +10,40 @@ | |||||||
|  * See the Mulan PubL v2 for more details. |  * See the Mulan PubL v2 for more details. | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
|  | // ################################### 使用多源事务兼容性占位须知 ################################## | ||||||
|  | // # 占位代码需要书写于宏定义块【NEED_GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION】中 | ||||||
|  | // # 占位方式: 通过【注释】占位,占位需要信息:Helper类型名/Ctx类型名/Enum数值/Enum命名 | ||||||
|  | // # | ||||||
|  | // # 注意: | ||||||
|  | // # 0. 在‘余留位置’之前占位 | ||||||
|  | // # 1. 始终先在master占位,保证master分支是其他所有分支的超集 | ||||||
|  | // # 2. master占位之后,开发分支上不可修改注册宏中的对应信息,否则FARM会认为占位冲突,如果有这种场景,需要先修改master占位 | ||||||
|  | // # 3. 所有类型名的书写从全局命名空间'::oceanbase'开始 | ||||||
|  | // # 4. Enum数值采用递增方式占位 | ||||||
|  | // # 5. Enum命名不可同前文重复 | ||||||
|  | // # 6. 由于采用注释方式占位,因此【不需要】书写对应的类型定义并包含在【NEED_MDS_REGISTER_DEFINE】中 | ||||||
|  | // ############################################################################################ | ||||||
|  |  | ||||||
|  | // ################################### 使用多源数据兼容性占位须知 ################################## | ||||||
|  | // # 占位代码需要书写于宏定义块【GENERATE_MDS_UNIT】中,更近一步的: | ||||||
|  | // # 1. 如果想要添加tablet级别元数据,则将占位信息增加至【GENERATE_NORMAL_MDS_TABLE】中 | ||||||
|  | // # 2. 如果想要添加日志流级别元数据,则将占位信息增加至【GENERATE_LS_INNER_MDS_TABLE】中 | ||||||
|  | // # 占位方式: 通过【定义】占位,占位需要信息:Key类型名/Value类型名/多版本语义支持 | ||||||
|  | // # | ||||||
|  | // # 注意: | ||||||
|  | // # 0. 在‘余留位置’之前占位 | ||||||
|  | // # 1. 始终先在master占位,保证master分支是其他所有分支的超集 | ||||||
|  | // # 2. master占位之后,开发分支上不可修改注册宏中的对应信息,否则FARM会认为占位冲突,如果有这种场景,需要先修改master占位 | ||||||
|  | // # 3. 所有类型名的书写从全局命名空间'::oceanbase'开始 | ||||||
|  | // # 4. 若Key类型名非'::oceanbase::storage::mds::DummyKey',则需要提供对应的Key类型定义,并将对应头文件包含在【NEED_MDS_REGISTER_DEFINE】中 | ||||||
|  | // # 5. 需要提供对应的Value类型定义,并将对应头文件包含在【NEED_MDS_REGISTER_DEFINE】中 | ||||||
|  | // # 6. Key/Value的类型仅需要空定义,不需要定义成员方法和变量,但需要实现框架所需的接口,以通过框架的编译期检查,包括(占位时实现为空): | ||||||
|  | // #    a. 打印函数:[int64_t T::to_string(char *, const int64_t) const] | ||||||
|  | // #    b. 比较函数的某种实现,例如:[bool T::operator==(const T &) const] and [bool T::operator<(const T &) const] | ||||||
|  | // #    c. 序列化函数的某种实现,例如:[int serialize(char *, const int64_t, int64_t &) const] and [int deserialize(const char *, const int64_t, int64_t &)] and [int64_t get_serialize_size() const] | ||||||
|  | // #    d. 拷贝/移动函数的某种实现,例如:[int T::assign(const T &)] | ||||||
|  | // ############################################################################################ | ||||||
|  |  | ||||||
| // the MDS FRAME must know the defination of some class type to generate legal CPP codes, including: | // the MDS FRAME must know the defination of some class type to generate legal CPP codes, including: | ||||||
| // 1. DATA type defination if you need multi source data support. | // 1. DATA type defination if you need multi source data support. | ||||||
| //    1.a. KEY type defination if you need multi source data support with multi key support. | //    1.a. KEY type defination if you need multi source data support with multi key support. | ||||||
| @ -34,6 +68,9 @@ | |||||||
|   #include "src/storage/tablet/ob_tablet_finish_transfer_mds_helper.h" |   #include "src/storage/tablet/ob_tablet_finish_transfer_mds_helper.h" | ||||||
|   #include "src/share/balance/ob_balance_task_table_operator.h" |   #include "src/share/balance/ob_balance_task_table_operator.h" | ||||||
|   #include "src/storage/tablet/ob_tablet_transfer_tx_ctx.h" |   #include "src/storage/tablet/ob_tablet_transfer_tx_ctx.h" | ||||||
|  |   #include "src/storage/multi_data_source/ob_tablet_create_mds_ctx.h" | ||||||
|  |   #include "src/storage/multi_data_source/ob_start_transfer_in_mds_ctx.h" | ||||||
|  |   #include "src/storage/multi_data_source/ob_finish_transfer_in_mds_ctx.h" | ||||||
| #endif | #endif | ||||||
| /**************************************************************************************************/ | /**************************************************************************************************/ | ||||||
|  |  | ||||||
| @ -71,7 +108,7 @@ _GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION_(HELPER_CLASS, BUFFER_CTX_TYPE, ID, ENU | |||||||
|                                           16,\ |                                           16,\ | ||||||
|                                           TEST3) |                                           TEST3) | ||||||
|   GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION(::oceanbase::storage::ObTabletCreateMdsHelper,\ |   GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION(::oceanbase::storage::ObTabletCreateMdsHelper,\ | ||||||
|                                           ::oceanbase::storage::mds::MdsCtx,\ |                                           ::oceanbase::storage::mds::ObTabletCreateMdsCtx,\ | ||||||
|                                           3,\ |                                           3,\ | ||||||
|                                           CREATE_TABLET_NEW_MDS) |                                           CREATE_TABLET_NEW_MDS) | ||||||
|   GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION(::oceanbase::storage::ObTabletDeleteMdsHelper,\ |   GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION(::oceanbase::storage::ObTabletDeleteMdsHelper,\ | ||||||
| @ -87,7 +124,7 @@ _GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION_(HELPER_CLASS, BUFFER_CTX_TYPE, ID, ENU | |||||||
|                                           20,\ |                                           20,\ | ||||||
|                                           START_TRANSFER_OUT) |                                           START_TRANSFER_OUT) | ||||||
|   GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION(::oceanbase::storage::ObTabletStartTransferInHelper,\ |   GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION(::oceanbase::storage::ObTabletStartTransferInHelper,\ | ||||||
|                                           ::oceanbase::storage::mds::MdsCtx,\ |                                           ::oceanbase::storage::mds::ObStartTransferInMdsCtx,\ | ||||||
|                                           21,\ |                                           21,\ | ||||||
|                                           START_TRANSFER_IN) |                                           START_TRANSFER_IN) | ||||||
|   GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION(::oceanbase::storage::ObTabletFinishTransferOutHelper,\ |   GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION(::oceanbase::storage::ObTabletFinishTransferOutHelper,\ | ||||||
| @ -95,7 +132,7 @@ _GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION_(HELPER_CLASS, BUFFER_CTX_TYPE, ID, ENU | |||||||
|                                           22,\ |                                           22,\ | ||||||
|                                           FINISH_TRANSFER_OUT) |                                           FINISH_TRANSFER_OUT) | ||||||
|   GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION(::oceanbase::storage::ObTabletFinishTransferInHelper,\ |   GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION(::oceanbase::storage::ObTabletFinishTransferInHelper,\ | ||||||
|                                           ::oceanbase::storage::mds::MdsCtx,\ |                                           ::oceanbase::storage::mds::ObFinishTransferInMdsCtx,\ | ||||||
|                                           23,\ |                                           23,\ | ||||||
|                                           FINISH_TRANSFER_IN) |                                           FINISH_TRANSFER_IN) | ||||||
|   GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION(::oceanbase::share::ObBalanceTaskMDSHelper,\ |   GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION(::oceanbase::share::ObBalanceTaskMDSHelper,\ | ||||||
| @ -118,12 +155,23 @@ _GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION_(HELPER_CLASS, BUFFER_CTX_TYPE, ID, ENU | |||||||
|                                           ::oceanbase::storage::ObTransferDestPrepareTxCtx,\ |                                           ::oceanbase::storage::ObTransferDestPrepareTxCtx,\ | ||||||
|                                           28,\ |                                           28,\ | ||||||
|                                           TRANSFER_DEST_PREPARE) |                                           TRANSFER_DEST_PREPARE) | ||||||
|   // UNBIND_LOB_TABLET: ID = 29 for drop lob tablet when drop column instant. |   // GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION(::oceanbase::storage::ObTabletUnbindLobMdsHelper,\ | ||||||
|  |   //                                         ::oceanbase::storage::mds::MdsCtx,\ | ||||||
|  |   //                                         29,\ | ||||||
|  |   //                                         UNBIND_LOB_TABLET) | ||||||
|   GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION(::oceanbase::storage::ObChangeTabletToTableHelper,\ |   GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION(::oceanbase::storage::ObChangeTabletToTableHelper,\ | ||||||
|                                           ::oceanbase::storage::mds::MdsCtx,\ |                                           ::oceanbase::storage::mds::MdsCtx,\ | ||||||
|                                           30,\ |                                           30,\ | ||||||
|                                           CHANGE_TABLET_TO_TABLE_MDS) |                                           CHANGE_TABLET_TO_TABLE_MDS) | ||||||
|   // TABLET_SPLIT: ID = 31 for auto_split. |   // GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION(::oceanbase::storage::ObTabletSplitMdsHelper,\ | ||||||
|  |   //                                         ::oceanbase::storage::mds::MdsCtx,\ | ||||||
|  |   //                                         31,\ | ||||||
|  |   //                                         TABLET_SPLIT) | ||||||
|  |   // GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION(::oceanbase::storage::ObTabletAbortTransferHelper,\ | ||||||
|  |   //                                         ::oceanbase::storage::mds::ObAbortTransferInMdsCtx,\ | ||||||
|  |   //                                         32,\ | ||||||
|  |   //                                         TRANSFER_IN_ABORTED) | ||||||
|  |   // # 余留位置(此行之前占位) | ||||||
| #undef GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION | #undef GENERATE_MDS_FRAME_CODE_FOR_TRANSACTION | ||||||
| #endif | #endif | ||||||
| /**************************************************************************************************/ | /**************************************************************************************************/ | ||||||
| @ -188,11 +236,13 @@ _GENERATE_MDS_UNIT_(KEY_TYPE, VALUE_TYPE, NEED_MULTI_VERSION) | |||||||
|   GENERATE_MDS_UNIT(::oceanbase::compaction::ObMediumCompactionInfoKey,\ |   GENERATE_MDS_UNIT(::oceanbase::compaction::ObMediumCompactionInfoKey,\ | ||||||
|                     ::oceanbase::compaction::ObMediumCompactionInfo,\ |                     ::oceanbase::compaction::ObMediumCompactionInfo,\ | ||||||
|                     false) |                     false) | ||||||
|  |   // # 余留位置(此行之前占位) | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #ifdef GENERATE_LS_INNER_MDS_TABLE | #ifdef GENERATE_LS_INNER_MDS_TABLE | ||||||
|   GENERATE_MDS_UNIT(::oceanbase::storage::mds::DummyKey,\ |   GENERATE_MDS_UNIT(::oceanbase::storage::mds::DummyKey,\ | ||||||
|                     ::oceanbase::unittest::ExampleUserData1,\ |                     ::oceanbase::unittest::ExampleUserData1,\ | ||||||
|                     true) // replace this line if you are the first user to register LS INNER TABLET |                     true) // replace this line if you are the first user to register LS INNER TABLET | ||||||
|  |   // # 余留位置(此行之前占位) | ||||||
| #endif | #endif | ||||||
| /**************************************************************************************************/ | /**************************************************************************************************/ | ||||||
							
								
								
									
										161
									
								
								src/storage/multi_data_source/ob_finish_transfer_in_mds_ctx.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										161
									
								
								src/storage/multi_data_source/ob_finish_transfer_in_mds_ctx.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,161 @@ | |||||||
|  | /** | ||||||
|  |  * 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 "ob_finish_transfer_in_mds_ctx.h" | ||||||
|  | #include "lib/ob_errno.h" | ||||||
|  | #include "lib/utility/ob_macro_utils.h" | ||||||
|  | #include "mds_table_handle.h" | ||||||
|  | #include "share/ob_errno.h" | ||||||
|  | #include "storage/tx_storage/ob_ls_handle.h" | ||||||
|  | #include "storage/tx_storage/ob_ls_service.h" | ||||||
|  |  | ||||||
|  | #define USING_LOG_PREFIX MDS | ||||||
|  |  | ||||||
|  | namespace oceanbase | ||||||
|  | { | ||||||
|  | namespace storage | ||||||
|  | { | ||||||
|  | namespace mds | ||||||
|  | { | ||||||
|  |  | ||||||
|  | ObFinishTransferInMdsCtx::ObFinishTransferInMdsCtx() | ||||||
|  |     : MdsCtx(), | ||||||
|  |       version_(ObFinishTransferInMdsCtxVersion::CURRENT_CTX_VERSION), | ||||||
|  |       redo_scn_(share::SCN::base_scn()) | ||||||
|  | { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | ObFinishTransferInMdsCtx::ObFinishTransferInMdsCtx(const MdsWriter &writer) | ||||||
|  |     : MdsCtx(writer), | ||||||
|  |       version_(ObFinishTransferInMdsCtxVersion::CURRENT_CTX_VERSION), | ||||||
|  |       redo_scn_(share::SCN::base_scn()) | ||||||
|  |  | ||||||
|  | { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | ObFinishTransferInMdsCtx::~ObFinishTransferInMdsCtx() | ||||||
|  | { | ||||||
|  |   version_ = ObFinishTransferInMdsCtxVersion::MAX; | ||||||
|  |   redo_scn_.reset(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int ObFinishTransferInMdsCtx::serialize(char *buf, const int64_t len, int64_t &pos) const | ||||||
|  | { | ||||||
|  |   int ret = OB_SUCCESS; | ||||||
|  |   int64_t saved_pos = pos; | ||||||
|  |   const int64_t length = get_serialize_size(); | ||||||
|  |  | ||||||
|  |   if (OB_ISNULL(buf) | ||||||
|  |       || OB_UNLIKELY(len <= 0) | ||||||
|  |       || OB_UNLIKELY(pos < 0)) { | ||||||
|  |     ret = OB_INVALID_ARGUMENT; | ||||||
|  |     LOG_WARN("invalid args", K(ret), K(buf), K(len), K(pos)); | ||||||
|  |   } else if (!ObFinishTransferInMdsCtxVersion::is_valid(version_)) { | ||||||
|  |     ret = OB_ERR_UNEXPECTED; | ||||||
|  |     LOG_ERROR("invalid version", K(ret), K_(version)); | ||||||
|  |   } else if (OB_UNLIKELY(length > len - pos)) { | ||||||
|  |     ret = OB_ERR_UNEXPECTED; | ||||||
|  |     LOG_WARN("buffer's length is not enough", K(ret), K(length), K(len - pos)); | ||||||
|  |   } else if (ObFinishTransferInMdsCtxVersion::FINISH_TRANSFER_IN_MDS_CTX_VERSION_V1 == version_) { | ||||||
|  |     if (OB_FAIL(MdsCtx::serialize(buf, len, pos))) { | ||||||
|  |       LOG_WARN("failed to serialize mds ctx serialize", K(ret), K(len), K(pos)); | ||||||
|  |     } | ||||||
|  |   } else { | ||||||
|  |     if (OB_FAIL(serialization::encode(buf, len, pos, static_cast<int64_t>(version_)))) { | ||||||
|  |       LOG_WARN("failed to serialize tablet meta's version", K(ret), K(len), K(pos), K_(version)); | ||||||
|  |     } else if (OB_FAIL(serialization::encode_i32(buf, len, pos, length))) { | ||||||
|  |       LOG_WARN("failed to serialize tablet meta's length", K(ret), K(len), K(pos), K(length)); | ||||||
|  |     } else if (OB_FAIL(MdsCtx::serialize(buf, len, pos))) { | ||||||
|  |       LOG_WARN("failed to serialize mds ctx serialize", K(ret), K(len), K(pos)); | ||||||
|  |     } else if (OB_FAIL(redo_scn_.serialize(buf, len, pos))) { | ||||||
|  |       LOG_WARN("failed to serialize redo scn", K(ret), K(len), K(pos)); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   if (OB_FAIL(ret)) { | ||||||
|  |   } else if (OB_UNLIKELY(length != pos - saved_pos)) { | ||||||
|  |     ret = OB_ERR_UNEXPECTED; | ||||||
|  |     LOG_WARN("finish transfer in mds ctx is not match standard length", K(ret), K(saved_pos), K(pos), K(length), K(len)); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   return ret; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int ObFinishTransferInMdsCtx::deserialize(const char *buf, const int64_t len, int64_t &pos) | ||||||
|  | { | ||||||
|  |   int ret = OB_SUCCESS; | ||||||
|  |   int64_t saved_pos = pos; | ||||||
|  |   int64_t version = -1; | ||||||
|  |   int32_t length = 0; | ||||||
|  |  | ||||||
|  |   if (OB_ISNULL(buf) | ||||||
|  |       || OB_UNLIKELY(len <= 0) | ||||||
|  |       || OB_UNLIKELY(pos < 0) | ||||||
|  |       || OB_UNLIKELY(len <= pos)) { | ||||||
|  |     ret = OB_INVALID_ARGUMENT; | ||||||
|  |     LOG_WARN("invalid args", K(ret), K(buf), K(len), K(pos)); | ||||||
|  |   } else if (OB_FAIL(serialization::decode(buf, len, pos, version))) { | ||||||
|  |     LOG_WARN("failed to deserialize start transfer in mds ctx's version", K(ret), K(len), K(pos)); | ||||||
|  |   } else if (FALSE_IT(version_ = static_cast<ObFinishTransferInMdsCtxVersion::VERSION>(version))) { | ||||||
|  |   } else if (ObFinishTransferInMdsCtxVersion::FINISH_TRANSFER_IN_MDS_CTX_VERSION_V1 == version_) { | ||||||
|  |     pos = saved_pos; | ||||||
|  |     if (OB_FAIL(MdsCtx::deserialize(buf, len, pos))) { | ||||||
|  |       LOG_WARN("failed to deserialize mds ctx", K(ret), K(len), K(pos)); | ||||||
|  |     } | ||||||
|  |   } else { | ||||||
|  |     if (OB_FAIL(serialization::decode_i32(buf, len, pos, &length))) { | ||||||
|  |       LOG_WARN("failed to deserialize start transfer in mds ctx's length", K(ret), K(len), K(pos)); | ||||||
|  |     } else if (ObFinishTransferInMdsCtxVersion::CURRENT_CTX_VERSION != version_) { | ||||||
|  |       ret = OB_ERR_UNEXPECTED; | ||||||
|  |       LOG_WARN("invalid version", K(ret), K_(version)); | ||||||
|  |     } else { | ||||||
|  |       if (OB_UNLIKELY(length > len - saved_pos)) { | ||||||
|  |         ret = OB_ERR_UNEXPECTED; | ||||||
|  |         LOG_WARN("buffer's length is not enough", K(ret), K(length), K(len - saved_pos)); | ||||||
|  |       } else if (OB_FAIL(MdsCtx::deserialize(buf, len, pos))) { | ||||||
|  |         LOG_WARN("failed to deserialize mds ctx", K(ret), K(len), K(pos)); | ||||||
|  |       } else if (OB_FAIL(redo_scn_.deserialize(buf, len, pos))) { | ||||||
|  |         LOG_WARN("failed to deserialize redo scn", K(ret), K(len), K(pos)); | ||||||
|  |       } else if (OB_UNLIKELY(length != pos - saved_pos)) { | ||||||
|  |         ret = OB_ERR_UNEXPECTED; | ||||||
|  |         LOG_WARN("tablet's length doesn't match standard length", K(ret), K(saved_pos), K(pos), K(length), K(len)); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |   return ret; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int64_t ObFinishTransferInMdsCtx::get_serialize_size(void) const | ||||||
|  | { | ||||||
|  |   int64_t size = 0; | ||||||
|  |   const int32_t placeholder_length = 0; | ||||||
|  |   if (ObFinishTransferInMdsCtxVersion::FINISH_TRANSFER_IN_MDS_CTX_VERSION_V1 == version_) { | ||||||
|  |     size += MdsCtx::get_serialize_size(); | ||||||
|  |   } else { | ||||||
|  |     const int64_t version = static_cast<int64_t>(version_); | ||||||
|  |     size += serialization::encoded_length(version); | ||||||
|  |     size += serialization::encoded_length_i32(placeholder_length); | ||||||
|  |     size += MdsCtx::get_serialize_size(); | ||||||
|  |     size += redo_scn_.get_serialize_size(); | ||||||
|  |   } | ||||||
|  |   return size; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void ObFinishTransferInMdsCtx::on_redo(const share::SCN &redo_scn) | ||||||
|  | { | ||||||
|  |   redo_scn_ = redo_scn; | ||||||
|  |   MdsCtx::on_redo(redo_scn); | ||||||
|  |   LOG_INFO("[TRANSFER] finish transfer in mds ctx on_redo", K(redo_scn)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | } | ||||||
|  | } | ||||||
|  | } | ||||||
| @ -0,0 +1,67 @@ | |||||||
|  | /** | ||||||
|  |  * 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 SHARE_STORAGE_MULTI_DATA_SOURCE_OB_FINISH_TRANSFER_IN_MDS_CTX_H | ||||||
|  | #define SHARE_STORAGE_MULTI_DATA_SOURCE_OB_FINISH_TRANSFER_IN_MDS_CTX_H | ||||||
|  |  | ||||||
|  | #include "mds_ctx.h" | ||||||
|  | #include "lib/container/ob_array.h" | ||||||
|  | #include "storage/multi_data_source/runtime_utility/mds_tenant_service.h" | ||||||
|  | #include "lib/container/ob_array_serialization.h" | ||||||
|  |  | ||||||
|  | namespace oceanbase | ||||||
|  | { | ||||||
|  | namespace storage | ||||||
|  | { | ||||||
|  | namespace mds | ||||||
|  | { | ||||||
|  | class MdsTableHandle; | ||||||
|  | struct ObFinishTransferInMdsCtxVersion | ||||||
|  | { | ||||||
|  |   enum VERSION { | ||||||
|  |     FINISH_TRANSFER_IN_MDS_CTX_VERSION_V1 = 1, | ||||||
|  |     FINISH_TRANSFER_IN_MDS_CTX_VERSION_V2 = 2, | ||||||
|  |     MAX | ||||||
|  |   }; | ||||||
|  |   static const VERSION CURRENT_CTX_VERSION = FINISH_TRANSFER_IN_MDS_CTX_VERSION_V2; | ||||||
|  |   static bool is_valid(const ObFinishTransferInMdsCtxVersion::VERSION &version) { | ||||||
|  |     return version >= FINISH_TRANSFER_IN_MDS_CTX_VERSION_V1 | ||||||
|  |         && version < MAX; | ||||||
|  |   } | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | class ObFinishTransferInMdsCtx : public MdsCtx | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |   ObFinishTransferInMdsCtx(); | ||||||
|  |   ObFinishTransferInMdsCtx(const MdsWriter &writer); | ||||||
|  |   virtual ~ObFinishTransferInMdsCtx(); | ||||||
|  |   virtual int serialize(char *buf, const int64_t len, int64_t &pos) const; | ||||||
|  |   virtual int deserialize(const char *buf, const int64_t len, int64_t &pos); | ||||||
|  |   virtual int64_t get_serialize_size(void) const; | ||||||
|  |  | ||||||
|  |   virtual void on_redo(const share::SCN &redo_scn) override; | ||||||
|  |   share::SCN &get_redo_scn() { return redo_scn_; } | ||||||
|  |  | ||||||
|  |   INHERIT_TO_STRING_KV("MdsCtx", MdsCtx, K_(version), K_(redo_scn)); | ||||||
|  | private: | ||||||
|  |   ObFinishTransferInMdsCtxVersion::VERSION version_; | ||||||
|  |   share::SCN redo_scn_; | ||||||
|  | private: | ||||||
|  |   DISALLOW_COPY_AND_ASSIGN(ObFinishTransferInMdsCtx); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | } //mds | ||||||
|  | } //storage | ||||||
|  | } //oceanbase | ||||||
|  |  | ||||||
|  | #endif //SHARE_STORAGE_MULTI_DATA_SOURCE_OB_FINISH_TRANSFER_IN_MDS_CTX_H | ||||||
							
								
								
									
										174
									
								
								src/storage/multi_data_source/ob_start_transfer_in_mds_ctx.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										174
									
								
								src/storage/multi_data_source/ob_start_transfer_in_mds_ctx.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,174 @@ | |||||||
|  | /** | ||||||
|  |  * 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 "ob_start_transfer_in_mds_ctx.h" | ||||||
|  | #include "lib/ob_errno.h" | ||||||
|  | #include "lib/utility/ob_macro_utils.h" | ||||||
|  | #include "mds_table_handle.h" | ||||||
|  | #include "share/ob_errno.h" | ||||||
|  | #include "storage/tx_storage/ob_ls_handle.h" | ||||||
|  | #include "storage/tx_storage/ob_ls_service.h" | ||||||
|  | #include "storage/high_availability/ob_ls_transfer_info.h" | ||||||
|  |  | ||||||
|  | #define USING_LOG_PREFIX MDS | ||||||
|  |  | ||||||
|  | namespace oceanbase | ||||||
|  | { | ||||||
|  | namespace storage | ||||||
|  | { | ||||||
|  | namespace mds | ||||||
|  | { | ||||||
|  |  | ||||||
|  | //errsim def | ||||||
|  | ERRSIM_POINT_DEF(EN_START_TRANSFER_IN_ON_PREPARE); | ||||||
|  |  | ||||||
|  | ObStartTransferInMdsCtx::ObStartTransferInMdsCtx() | ||||||
|  |     : MdsCtx(), | ||||||
|  |       version_(ObStartTransferInMdsCtxVersion::CURRENT_CTX_VERSION), | ||||||
|  |       ls_id_() | ||||||
|  | { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | ObStartTransferInMdsCtx::ObStartTransferInMdsCtx(const MdsWriter &writer) | ||||||
|  |     : MdsCtx(writer), | ||||||
|  |       version_(ObStartTransferInMdsCtxVersion::CURRENT_CTX_VERSION), | ||||||
|  |       ls_id_() | ||||||
|  | { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | ObStartTransferInMdsCtx::~ObStartTransferInMdsCtx() | ||||||
|  | { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void ObStartTransferInMdsCtx::on_prepare(const share::SCN &prepare_version) | ||||||
|  | { | ||||||
|  |   // TODO(@muwei.ym): add ERRSIM code later | ||||||
|  |   MdsCtx::on_prepare(prepare_version); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void ObStartTransferInMdsCtx::on_abort(const share::SCN &abort_scn) | ||||||
|  | { | ||||||
|  |   mds::MdsCtx::on_abort(abort_scn); | ||||||
|  |  | ||||||
|  |   // TODO(@bowen.gbw): feature branch transfer_dml_ctrl_42x patch to master, | ||||||
|  |   // then add more logic, currently this code is just for compat | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int ObStartTransferInMdsCtx::serialize(char *buf, const int64_t len, int64_t &pos) const | ||||||
|  | { | ||||||
|  |   int ret = OB_SUCCESS; | ||||||
|  |   int64_t saved_pos = pos; | ||||||
|  |   const int64_t length = get_serialize_size(); | ||||||
|  |  | ||||||
|  |   if (OB_ISNULL(buf) | ||||||
|  |       || OB_UNLIKELY(len <= 0) | ||||||
|  |       || OB_UNLIKELY(pos < 0)) { | ||||||
|  |     ret = OB_INVALID_ARGUMENT; | ||||||
|  |     LOG_WARN("invalid args", K(ret), K(buf), K(len), K(pos)); | ||||||
|  |   } else if (!ObStartTransferInMdsCtxVersion::is_valid(version_)) { | ||||||
|  |     ret = OB_ERR_UNEXPECTED; | ||||||
|  |     LOG_ERROR("invalid version", K(ret), K_(version)); | ||||||
|  |   } else if (OB_UNLIKELY(length > len - pos)) { | ||||||
|  |     ret = OB_ERR_UNEXPECTED; | ||||||
|  |     LOG_WARN("buffer's length is not enough", K(ret), K(length), K(len - pos)); | ||||||
|  |   } else if (ObStartTransferInMdsCtxVersion::START_TRANSFER_IN_MDS_CTX_VERSION_V1 == version_) { | ||||||
|  |     if (OB_FAIL(MdsCtx::serialize(buf, len, pos))) { | ||||||
|  |       LOG_WARN("failed to serialize mds ctx", K(ret), K(len), K(pos)); | ||||||
|  |     } | ||||||
|  |   } else if (ObStartTransferInMdsCtxVersion::START_TRANSFER_IN_MDS_CTX_VERSION_V2 == version_ | ||||||
|  |       || ObStartTransferInMdsCtxVersion::START_TRANSFER_IN_MDS_CTX_VERSION_V3 == version_) { | ||||||
|  |     if (OB_FAIL(serialization::encode(buf, len, pos, static_cast<int64_t>(version_)))) { | ||||||
|  |       LOG_WARN("failed to serialize start transfer in mds ctx version", K(ret), K(len), K(pos), K_(version)); | ||||||
|  |     } else if (OB_FAIL(serialization::encode_i32(buf, len, pos, length))) { | ||||||
|  |       LOG_WARN("failed to serialize start transfer in mds ctx length", K(ret), K(len), K(pos), K(length)); | ||||||
|  |     } else if (ObStartTransferInMdsCtxVersion::START_TRANSFER_IN_MDS_CTX_VERSION_V3 == version_ | ||||||
|  |         && OB_FAIL(ls_id_.serialize(buf, len, pos))) { | ||||||
|  |       LOG_WARN("failed to serialize ls id", K(ret), K(len), K(pos), K_(ls_id)); | ||||||
|  |     } else if (OB_FAIL(MdsCtx::serialize(buf, len, pos))) { | ||||||
|  |       LOG_WARN("failed to serialize mds ctx", K(ret), K(len), K(pos)); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   if (OB_FAIL(ret)) { | ||||||
|  |   } else if (OB_UNLIKELY(length != pos - saved_pos)) { | ||||||
|  |     ret = OB_ERR_UNEXPECTED; | ||||||
|  |     LOG_WARN("start transfer in mds ctx is not match standard length", K(ret), K(saved_pos), K(pos), K(length), K(len)); | ||||||
|  |   } | ||||||
|  |   return ret; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int ObStartTransferInMdsCtx::deserialize(const char *buf, const int64_t len, int64_t &pos) | ||||||
|  | { | ||||||
|  |   int ret = OB_SUCCESS; | ||||||
|  |   int64_t saved_pos = pos; | ||||||
|  |   int64_t version = -1; | ||||||
|  |   int32_t length = 0; | ||||||
|  |  | ||||||
|  |   if (OB_ISNULL(buf) | ||||||
|  |       || OB_UNLIKELY(len <= 0) | ||||||
|  |       || OB_UNLIKELY(pos < 0) | ||||||
|  |       || OB_UNLIKELY(len <= pos)) { | ||||||
|  |     ret = OB_INVALID_ARGUMENT; | ||||||
|  |     LOG_WARN("invalid args", K(ret), K(buf), K(len), K(pos)); | ||||||
|  |   } else if (OB_FAIL(serialization::decode(buf, len, pos, version))) { | ||||||
|  |     LOG_WARN("failed to deserialize start transfer in mds ctx's version", K(ret), K(len), K(pos)); | ||||||
|  |   } else if (FALSE_IT(version_ = static_cast<ObStartTransferInMdsCtxVersion::VERSION>(version))) { | ||||||
|  |   } else if (ObStartTransferInMdsCtxVersion::START_TRANSFER_IN_MDS_CTX_VERSION_V1 == version_) { | ||||||
|  |     pos = saved_pos; | ||||||
|  |     if (OB_FAIL(MdsCtx::deserialize(buf, len, pos))) { | ||||||
|  |       LOG_WARN("failed to deserialize mds ctx", K(ret), K(len), K(pos)); | ||||||
|  |     } | ||||||
|  |   } else if (ObStartTransferInMdsCtxVersion::START_TRANSFER_IN_MDS_CTX_VERSION_V2 == version_ | ||||||
|  |       || ObStartTransferInMdsCtxVersion::START_TRANSFER_IN_MDS_CTX_VERSION_V3 == version_) { | ||||||
|  |     if (OB_FAIL(serialization::decode_i32(buf, len, pos, &length))) { | ||||||
|  |       LOG_WARN("failed to deserialize start transfer in mds ctx's length", K(ret), K(len), K(pos)); | ||||||
|  |     } else if (OB_UNLIKELY(length > len - saved_pos)) { | ||||||
|  |       ret = OB_ERR_UNEXPECTED; | ||||||
|  |       LOG_WARN("buffer's length is not enough", K(ret), K(length), K(len - pos)); | ||||||
|  |     } else if (ObStartTransferInMdsCtxVersion::START_TRANSFER_IN_MDS_CTX_VERSION_V3 == version_ | ||||||
|  |         && OB_FAIL(ls_id_.deserialize(buf, len, pos))) { | ||||||
|  |       LOG_WARN("fail to deserialize ls id", K(ret), K(len), K(pos)); | ||||||
|  |     } else if (OB_FAIL(MdsCtx::deserialize(buf, len, pos))) { | ||||||
|  |       LOG_WARN("failed to deserialize mds ctx", K(ret), K(len), K(pos)); | ||||||
|  |     } else if (OB_UNLIKELY(length != pos - saved_pos)) { | ||||||
|  |       ret = OB_ERR_UNEXPECTED; | ||||||
|  |       LOG_WARN("start transfer in ctx length doesn't match standard length", K(ret), K(saved_pos), K(pos), K(length), K(len)); | ||||||
|  |     } | ||||||
|  |   } else { | ||||||
|  |     ret = OB_ERR_UNEXPECTED; | ||||||
|  |     LOG_WARN("invalid version", K(ret), K_(version)); | ||||||
|  |   } | ||||||
|  |   return ret; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int64_t ObStartTransferInMdsCtx::get_serialize_size(void) const | ||||||
|  | { | ||||||
|  |   int64_t size = 0; | ||||||
|  |   const int32_t placeholder_length = 0; | ||||||
|  |   if (ObStartTransferInMdsCtxVersion::START_TRANSFER_IN_MDS_CTX_VERSION_V1 == version_) { | ||||||
|  |     size += MdsCtx::get_serialize_size(); | ||||||
|  |   } else if (ObStartTransferInMdsCtxVersion::START_TRANSFER_IN_MDS_CTX_VERSION_V2 == version_ | ||||||
|  |       || ObStartTransferInMdsCtxVersion::START_TRANSFER_IN_MDS_CTX_VERSION_V3 == version_) { | ||||||
|  |     const int64_t version = static_cast<int64_t>(version_); | ||||||
|  |     size += serialization::encoded_length(version); | ||||||
|  |     size += serialization::encoded_length_i32(placeholder_length); | ||||||
|  |     if (ObStartTransferInMdsCtxVersion::START_TRANSFER_IN_MDS_CTX_VERSION_V3 == version_) { | ||||||
|  |       size += ls_id_.get_serialize_size(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     size += MdsCtx::get_serialize_size(); | ||||||
|  |   } | ||||||
|  |   return size; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | } | ||||||
|  | } | ||||||
|  | } | ||||||
							
								
								
									
										71
									
								
								src/storage/multi_data_source/ob_start_transfer_in_mds_ctx.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								src/storage/multi_data_source/ob_start_transfer_in_mds_ctx.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,71 @@ | |||||||
|  | /** | ||||||
|  |  * 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 SHARE_STORAGE_MULTI_DATA_SOURCE_OB_START_TRANSFER_IN_MDS_CTX_H | ||||||
|  | #define SHARE_STORAGE_MULTI_DATA_SOURCE_OB_START_TRANSFER_IN_MDS_CTX_H | ||||||
|  |  | ||||||
|  | #include "mds_ctx.h" | ||||||
|  | #include "lib/container/ob_array.h" | ||||||
|  | #include "lib/container/ob_array_serialization.h" | ||||||
|  | #include "share/ob_ls_id.h" | ||||||
|  | #include "storage/multi_data_source/runtime_utility/mds_tenant_service.h" | ||||||
|  |  | ||||||
|  | namespace oceanbase | ||||||
|  | { | ||||||
|  | namespace storage | ||||||
|  | { | ||||||
|  | namespace mds | ||||||
|  | { | ||||||
|  |  | ||||||
|  | class MdsTableHandle; | ||||||
|  |  | ||||||
|  | struct ObStartTransferInMdsCtxVersion | ||||||
|  | { | ||||||
|  |   enum VERSION { | ||||||
|  |     START_TRANSFER_IN_MDS_CTX_VERSION_V1 = 1, | ||||||
|  |     START_TRANSFER_IN_MDS_CTX_VERSION_V2 = 2, | ||||||
|  |     START_TRANSFER_IN_MDS_CTX_VERSION_V3 = 3, | ||||||
|  |     MAX | ||||||
|  |   }; | ||||||
|  |   static const VERSION CURRENT_CTX_VERSION = START_TRANSFER_IN_MDS_CTX_VERSION_V3; | ||||||
|  |   static bool is_valid(const ObStartTransferInMdsCtxVersion::VERSION &version) { | ||||||
|  |     return version >= START_TRANSFER_IN_MDS_CTX_VERSION_V1 | ||||||
|  |         && version < MAX; | ||||||
|  |   } | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | class ObStartTransferInMdsCtx : public MdsCtx | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |   ObStartTransferInMdsCtx(); | ||||||
|  |   explicit ObStartTransferInMdsCtx(const MdsWriter &writer); | ||||||
|  |   virtual ~ObStartTransferInMdsCtx(); | ||||||
|  | public: | ||||||
|  |   virtual void on_prepare(const share::SCN &prepare_version) override; | ||||||
|  |   virtual void on_abort(const share::SCN &abort_scn) override; | ||||||
|  |  | ||||||
|  |   virtual int serialize(char *buf, const int64_t len, int64_t &pos) const override; | ||||||
|  |   virtual int deserialize(const char *buf, const int64_t len, int64_t &pos) override; | ||||||
|  |   virtual int64_t get_serialize_size(void) const override; | ||||||
|  | public: | ||||||
|  |   void set_ls_id(const share::ObLSID &ls_id) { ls_id_ = ls_id; } | ||||||
|  | private: | ||||||
|  |   ObStartTransferInMdsCtxVersion::VERSION version_; | ||||||
|  |   share::ObLSID ls_id_; | ||||||
|  |   DISALLOW_COPY_AND_ASSIGN(ObStartTransferInMdsCtx); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | } //mds | ||||||
|  | } //storage | ||||||
|  | } //oceanbase | ||||||
|  |  | ||||||
|  | #endif //SHARE_STORAGE_MULTI_DATA_SOURCE_OB_TRANSFER_IN_MDS_CTX_H | ||||||
							
								
								
									
										143
									
								
								src/storage/multi_data_source/ob_tablet_create_mds_ctx.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										143
									
								
								src/storage/multi_data_source/ob_tablet_create_mds_ctx.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,143 @@ | |||||||
|  | /** | ||||||
|  |  * 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/multi_data_source/ob_tablet_create_mds_ctx.h" | ||||||
|  | #include "lib/utility/serialization.h" | ||||||
|  | #include "storage/ls/ob_ls_get_mod.h" | ||||||
|  | #include "storage/tx_storage/ob_empty_shell_task.h" | ||||||
|  | #include "storage/tx_storage/ob_ls_service.h" | ||||||
|  | #include "storage/tx_storage/ob_ls_handle.h" | ||||||
|  |  | ||||||
|  | #define USING_LOG_PREFIX MDS | ||||||
|  |  | ||||||
|  | namespace oceanbase | ||||||
|  | { | ||||||
|  | namespace storage | ||||||
|  | { | ||||||
|  | namespace mds | ||||||
|  | { | ||||||
|  | ObTabletCreateMdsCtx::ObTabletCreateMdsCtx() | ||||||
|  |   : MdsCtx(), | ||||||
|  |     magic_(MAGIC), | ||||||
|  |     version_(VERSION), | ||||||
|  |     ls_id_() | ||||||
|  | { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | ObTabletCreateMdsCtx::ObTabletCreateMdsCtx(const MdsWriter &writer) | ||||||
|  |   : MdsCtx(writer), | ||||||
|  |     magic_(MAGIC), | ||||||
|  |     version_(VERSION), | ||||||
|  |     ls_id_() | ||||||
|  | { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void ObTabletCreateMdsCtx::on_abort(const share::SCN &abort_scn) | ||||||
|  | { | ||||||
|  |   mds::MdsCtx::on_abort(abort_scn); | ||||||
|  |  | ||||||
|  |   // TODO(@bowen.gbw): feature branch transfer_dml_ctrl_42x patch to master, | ||||||
|  |   // then add more logic, currently this code is just for compat | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int ObTabletCreateMdsCtx::serialize(char *buf, const int64_t buf_len, int64_t &pos) const | ||||||
|  | { | ||||||
|  |   int ret = OB_SUCCESS; | ||||||
|  |   const int64_t serialize_size = get_serialize_size(); | ||||||
|  |   int64_t tmp_pos = pos; | ||||||
|  |  | ||||||
|  |   if (OB_ISNULL(buf) | ||||||
|  |       || OB_UNLIKELY(buf_len <= 0) | ||||||
|  |       || OB_UNLIKELY(pos < 0)) { | ||||||
|  |     ret = OB_INVALID_ARGUMENT; | ||||||
|  |     LOG_WARN("invalid args", K(ret), K(buf), K(buf_len), K(pos)); | ||||||
|  |   } else if (OB_UNLIKELY(buf_len - pos < serialize_size)) { | ||||||
|  |     ret = OB_ERR_UNEXPECTED; | ||||||
|  |     LOG_WARN("buffer len is not enough to serialize", K(ret), K(buf_len), K(pos), K(serialize_size)); | ||||||
|  |   } else if (VERSION == version_) { | ||||||
|  |     if (OB_FAIL(MdsCtx::serialize(buf, buf_len, tmp_pos))) { | ||||||
|  |       LOG_WARN("failed to serialize mds ctx", K(ret), K(buf_len), K(tmp_pos)); | ||||||
|  |     } else if (OB_FAIL(serialization::encode(buf, buf_len, tmp_pos, magic_))) { | ||||||
|  |       LOG_WARN("fail to serialize magic", K(ret), K(buf_len), K(tmp_pos), K_(magic)); | ||||||
|  |     } else if (OB_FAIL(serialization::encode(buf, buf_len, tmp_pos, version_))) { | ||||||
|  |       LOG_WARN("fail to serialize version", K(ret), K(buf_len), K(tmp_pos), K_(version)); | ||||||
|  |     } else if (OB_FAIL(serialization::encode_i64(buf, buf_len, tmp_pos, serialize_size))) { | ||||||
|  |       LOG_WARN("fail to serialize length", K(ret), K(buf_len), K(tmp_pos), K(serialize_size)); | ||||||
|  |     } else if (OB_FAIL(ls_id_.serialize(buf, buf_len, tmp_pos))) { | ||||||
|  |       LOG_WARN("fail to serialize ls id", K(ret), K(buf_len), K(tmp_pos), K_(ls_id)); | ||||||
|  |     } else { | ||||||
|  |       pos = tmp_pos; | ||||||
|  |     } | ||||||
|  |   } else { | ||||||
|  |     ret = OB_ERR_UNEXPECTED; | ||||||
|  |     LOG_WARN("unexpected version", K(ret), K_(version)); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   return ret; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int ObTabletCreateMdsCtx::deserialize(const char *buf, const int64_t buf_len, int64_t &pos) | ||||||
|  | { | ||||||
|  |   int ret = OB_SUCCESS; | ||||||
|  |   int64_t tmp_pos = pos; | ||||||
|  |   int32_t magic = -1; | ||||||
|  |   int32_t version = -1; | ||||||
|  |   int64_t serialize_size = 0; | ||||||
|  |  | ||||||
|  |   if (OB_ISNULL(buf) | ||||||
|  |       || OB_UNLIKELY(buf_len <= 0) | ||||||
|  |       || OB_UNLIKELY(pos < 0)) { | ||||||
|  |     ret = OB_INVALID_ARGUMENT; | ||||||
|  |     LOG_WARN("invalid args", K(ret), K(buf), K(buf_len), K(pos)); | ||||||
|  |   } else if (OB_FAIL(MdsCtx::deserialize(buf, buf_len, tmp_pos))) { | ||||||
|  |     LOG_WARN("fail to deserialize mds ctx", K(ret), K(buf_len), K(tmp_pos)); | ||||||
|  |   } else if (OB_FAIL(serialization::decode(buf, buf_len, tmp_pos, magic))) { | ||||||
|  |     LOG_WARN("failed to deserialize magic", K(ret), K(buf_len), K(tmp_pos)); | ||||||
|  |   } else if (OB_UNLIKELY(magic != MAGIC)) { | ||||||
|  |     FLOG_INFO("magic does not match, maybe this is old version data", K(ret), K(magic), LITERAL_K(MAGIC)); | ||||||
|  |     version_ = VERSION; | ||||||
|  |     ls_id_ = ObLSID::INVALID_LS_ID; | ||||||
|  |     pos = tmp_pos; | ||||||
|  |   } else if (OB_FAIL(serialization::decode(buf, buf_len, tmp_pos, version))) { | ||||||
|  |     LOG_WARN("failed to deserialize version", K(ret), K(buf_len), K(tmp_pos)); | ||||||
|  |   } else if (OB_UNLIKELY(VERSION != version)) { | ||||||
|  |     ret = OB_ERR_UNEXPECTED; | ||||||
|  |     LOG_WARN("version does not match", K(ret), K(version)); | ||||||
|  |   } else if (OB_FAIL(serialization::decode_i64(buf, buf_len, tmp_pos, &serialize_size))) { | ||||||
|  |     LOG_WARN("failed to deserialize serialize size", K(ret), K(buf_len), K(tmp_pos)); | ||||||
|  |   } else if (tmp_pos - pos < serialize_size && OB_FAIL(ls_id_.deserialize(buf, buf_len, tmp_pos))) { | ||||||
|  |     LOG_WARN("failed to deserialize ls id", K(ret), K(buf_len), K(tmp_pos)); | ||||||
|  |   } else if (OB_UNLIKELY(tmp_pos - pos != serialize_size)) { | ||||||
|  |     ret = OB_ERR_UNEXPECTED; | ||||||
|  |     LOG_WARN("deserialize length does not match", K(ret), K(buf_len), K(pos), K(tmp_pos), K(serialize_size)); | ||||||
|  |   } else { | ||||||
|  |     version_ = version; | ||||||
|  |     pos = tmp_pos; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   return ret; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int64_t ObTabletCreateMdsCtx::get_serialize_size() const | ||||||
|  | { | ||||||
|  |   int64_t size = 0; | ||||||
|  |   int64_t serialize_size = 0; // dummy | ||||||
|  |   size += MdsCtx::get_serialize_size(); | ||||||
|  |   size += serialization::encoded_length(magic_); | ||||||
|  |   size += serialization::encoded_length(version_); | ||||||
|  |   size += serialization::encoded_length_i64(serialize_size); | ||||||
|  |   size += ls_id_.get_serialize_size(); | ||||||
|  |   return size; | ||||||
|  | } | ||||||
|  | } // namespace mds | ||||||
|  | } // namespace storage | ||||||
|  | } // namespace oceanbase | ||||||
							
								
								
									
										55
									
								
								src/storage/multi_data_source/ob_tablet_create_mds_ctx.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								src/storage/multi_data_source/ob_tablet_create_mds_ctx.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,55 @@ | |||||||
|  | /** | ||||||
|  |  * 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_CREATE_TABLET_MDS_CTX | ||||||
|  | #define OCEANBASE_STORAGE_OB_CREATE_TABLET_MDS_CTX | ||||||
|  |  | ||||||
|  | #include "storage/multi_data_source/mds_ctx.h" | ||||||
|  | #include "share/ob_ls_id.h" | ||||||
|  |  | ||||||
|  | namespace oceanbase | ||||||
|  | { | ||||||
|  | namespace storage | ||||||
|  | { | ||||||
|  | namespace mds | ||||||
|  | { | ||||||
|  | class ObTabletCreateMdsCtx : public MdsCtx | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |   ObTabletCreateMdsCtx(); | ||||||
|  |   explicit ObTabletCreateMdsCtx(const MdsWriter &writer); | ||||||
|  |   virtual ~ObTabletCreateMdsCtx() = default; | ||||||
|  | public: | ||||||
|  |   virtual void on_abort(const share::SCN &abort_scn) override; | ||||||
|  |   virtual int serialize(char *buf, const int64_t buf_len, int64_t &pos) const override; | ||||||
|  |   virtual int deserialize(const char *buf, const int64_t buf_len, int64_t &pos) override; | ||||||
|  |   virtual int64_t get_serialize_size() const override; | ||||||
|  | public: | ||||||
|  |   void set_ls_id(const share::ObLSID &ls_id); | ||||||
|  | private: | ||||||
|  |   static constexpr int32_t MAGIC = 0xdead; | ||||||
|  |   static constexpr int32_t VERSION = 1; | ||||||
|  |  | ||||||
|  |   const int32_t magic_; | ||||||
|  |   int32_t version_; | ||||||
|  |   share::ObLSID ls_id_; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | inline void ObTabletCreateMdsCtx::set_ls_id(const share::ObLSID &ls_id) | ||||||
|  | { | ||||||
|  |   ls_id_ = ls_id; | ||||||
|  | } | ||||||
|  | } // namespace mds | ||||||
|  | } // namespace storage | ||||||
|  | } // namespace oceanbase | ||||||
|  |  | ||||||
|  | #endif // OCEANBASE_STORAGE_OB_CREATE_TABLET_MDS_CTX | ||||||
		Reference in New Issue
	
	Block a user
	 hiddenbomb
					hiddenbomb