refine tablet init functions & refactor code struct

This commit is contained in:
hiddenbomb
2023-08-31 12:10:35 +00:00
committed by ob-robot
parent b7da983c8d
commit 6e1811678e
16 changed files with 272 additions and 161 deletions

View File

@ -187,12 +187,14 @@ ob_set_subtarget(ob_storage backup
)
ob_set_subtarget(ob_storage tablet
tablet/ob_batch_create_tablet_pretty_arg.cpp
tablet/ob_full_tablet_creator.cpp
tablet/ob_tablet_binding_helper.cpp
tablet/ob_tablet_binding_replay_executor.cpp
tablet/ob_tablet_common.cpp
tablet/ob_tablet_complex_addr.cpp
tablet/ob_tablet_create_delete_helper.cpp
tablet/ob_tablet_create_replay_executor.cpp
tablet/ob_tablet_create_sstable_param.cpp
tablet/ob_tablet_ddl_info.cpp
tablet/ob_tablet_id_set.cpp

View File

@ -840,7 +840,7 @@ int ObLSTabletService::rebuild_tablet_with_old(
} else if (OB_FAIL(ObTabletCreateDeleteHelper::acquire_tmp_tablet(key, allocator, tmp_tablet_hdl))) {
LOG_WARN("fail to acquire temporary tablet", K(ret), K(key));
} else if (FALSE_IT(tmp_tablet = tmp_tablet_hdl.get_obj())) {
} else if (OB_FAIL(tmp_tablet->init(allocator, mig_tablet_param, true/*is_update*/, freezer))) {
} else if (OB_FAIL(tmp_tablet->init_with_migrate_param(allocator, mig_tablet_param, true/*is_update*/, freezer))) {
LOG_WARN("failed to init tablet", K(ret), K(mig_tablet_param));
} else if (FALSE_IT(tmp_tablet->set_next_tablet_guard(tablet_guard))) {
} else if (FALSE_IT(time_guard.click("InitTablet"))) {
@ -887,7 +887,7 @@ int ObLSTabletService::migrate_update_tablet(
} else if (OB_FAIL(ObTabletCreateDeleteHelper::acquire_tmp_tablet(key, allocator, tmp_tablet_hdl))) {
LOG_WARN("fail to acquire temporary tablet", K(ret), K(key));
} else if (FALSE_IT(new_tablet = tmp_tablet_hdl.get_obj())) {
} else if (OB_FAIL(new_tablet->init(allocator, mig_tablet_param, true/*is_update*/, freezer))) {
} else if (OB_FAIL(new_tablet->init_with_migrate_param(allocator, mig_tablet_param, true/*is_update*/, freezer))) {
LOG_WARN("failed to init tablet", K(ret), K(mig_tablet_param));
} else if (FALSE_IT(time_guard.click("InitTablet"))) {
} else if (OB_FAIL(ObTabletPersister::persist_and_transform_tablet(*new_tablet, new_tablet_hdl))) {
@ -928,7 +928,7 @@ int ObLSTabletService::migrate_create_tablet(
if (OB_FAIL(ObTabletCreateDeleteHelper::create_tmp_tablet(key, allocator, tmp_tablet_hdl))) {
LOG_WARN("fail to create temporary tablet", K(ret), K(key));
} else if (OB_FAIL(tmp_tablet_hdl.get_obj()->init(allocator, mig_tablet_param, false/*is_update*/, freezer))) {
} else if (OB_FAIL(tmp_tablet_hdl.get_obj()->init_with_migrate_param(allocator, mig_tablet_param, false/*is_update*/, freezer))) {
LOG_WARN("fail to init tablet", K(ret), K(mig_tablet_param));
} else if (FALSE_IT(time_guard.click("InitTablet"))) {
} else if (OB_FAIL(ObTabletPersister::persist_and_transform_tablet(*tmp_tablet_hdl.get_obj(), tablet_handle))) {
@ -1092,7 +1092,7 @@ int ObLSTabletService::update_tablet_table_store(
if (OB_FAIL(ObTabletCreateDeleteHelper::acquire_tmp_tablet(key, allocator, tmp_tablet_hdl))) {
LOG_WARN("fail to acquire temporary tablet", K(ret), K(key));
} else if (FALSE_IT(tmp_tablet = tmp_tablet_hdl.get_obj())) {
} else if (OB_FAIL(tmp_tablet->init(allocator, tables, *old_tablet))) {
} else if (OB_FAIL(tmp_tablet->init_for_defragment(allocator, tables, *old_tablet))) {
LOG_WARN("fail to init new tablet", K(ret), KPC(old_tablet));
} else if (FALSE_IT(time_guard.click("InitTablet"))) {
} else if (OB_FAIL(ObTabletPersister::persist_and_transform_tablet(*tmp_tablet, new_tablet_hdl))) {
@ -1157,7 +1157,7 @@ int ObLSTabletService::update_tablet_table_store(
ObTenantMetaMemMgr *t3m = MTL(ObTenantMetaMemMgr*);
ObTablet *old_tablet = old_tablet_hdl.get_obj();
ObMetaDiskAddr disk_addr;
if (OB_FAIL(tmp_tablet->init(allocator, param, *old_tablet))) {
if (OB_FAIL(tmp_tablet->init_for_merge(allocator, param, *old_tablet))) {
LOG_WARN("failed to init tablet", K(ret), K(param), KPC(old_tablet));
} else if (FALSE_IT(time_guard.click("InitNew"))) {
} else if (OB_FAIL(ObTabletPersister::persist_and_transform_tablet(*tmp_tablet, new_tablet_hdl))) {
@ -1441,7 +1441,7 @@ int ObLSTabletService::build_new_tablet_from_mds_table(
} else {
LOG_WARN("failed to read mds table", K(ret), K(key));
}
} else if (CLICK_FAIL(tmp_tablet->init(allocator, *old_tablet, flush_scn, mds_data, old_tablet->mds_data_))) {
} else if (CLICK_FAIL(tmp_tablet->init_for_mds_table_dump(allocator, *old_tablet, flush_scn, mds_data, old_tablet->mds_data_))) {
LOG_WARN("failed to init tablet", K(ret), KPC(old_tablet), K(flush_scn));
} else if (CLICK_FAIL(ObTabletPersister::persist_and_transform_tablet(*tmp_tablet, new_tablet_handle))) {
LOG_WARN("fail to persist and transform tablet", K(ret), KPC(tmp_tablet), K(new_tablet_handle));
@ -1999,8 +1999,8 @@ int ObLSTabletService::create_tablet(
sstable = &new_sstable;
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(tablet->init(*allocator, ls_id, tablet_id, data_tablet_id, create_scn, snapshot_version,
table_schema, compat_mode, table_store_flag, sstable, freezer))) {
} else if (OB_FAIL(tablet->init_for_first_time_creation(*allocator, ls_id, tablet_id, data_tablet_id,
create_scn, snapshot_version, table_schema, compat_mode, table_store_flag, sstable, freezer))) {
LOG_WARN("failed to init tablet", K(ret), K(ls_id), K(tablet_id), K(data_tablet_id),
K(create_scn), K(snapshot_version), K(table_schema), K(compat_mode), K(table_store_flag));
} else if (OB_FAIL(t3m->compare_and_swap_tablet(key, tablet_handle, tablet_handle))) {
@ -2066,8 +2066,8 @@ int ObLSTabletService::create_inner_tablet(
sstable = &new_sstable;
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(tmp_tablet->init(allocator, ls_id, tablet_id, data_tablet_id, create_scn, snapshot_version,
table_schema, compat_mode, table_store_flag, sstable, freezer))) {
} else if (OB_FAIL(tmp_tablet->init_for_first_time_creation(allocator, ls_id, tablet_id, data_tablet_id,
create_scn, snapshot_version, table_schema, compat_mode, table_store_flag, sstable, freezer))) {
LOG_WARN("failed to init tablet", K(ret), K(ls_id), K(tablet_id), K(data_tablet_id),
K(create_scn), K(snapshot_version), K(table_schema), K(compat_mode), K(table_store_flag));
@ -2147,7 +2147,7 @@ int ObLSTabletService::create_transfer_in_tablet(
|| OB_ISNULL(allocator = tablet_handle.get_allocator())) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("new tablet is null", K(ret), KP(tablet), KP(allocator), K(tablet_handle));
} else if (OB_FAIL(tablet->init(*allocator, tablet_meta, false/*is_update*/, freezer))) {
} else if (OB_FAIL(tablet->init_with_migrate_param(*allocator, tablet_meta, false/*is_update*/, freezer))) {
LOG_WARN("failed to init tablet", K(ret), K(ls_id), K(tablet_meta));
} else if (OB_FAIL(t3m->compare_and_swap_tablet(key, tablet_handle, tablet_handle))) {
LOG_WARN("failed to compare and swap tablet", K(ret), K(key), K(tablet_handle));
@ -2203,7 +2203,7 @@ int ObLSTabletService::create_empty_shell_tablet(
ObFreezer *freezer = ls_->get_freezer();
ObTablet *new_tablet = tablet_handle.get_obj();
ObMetaDiskAddr disk_addr;
if (OB_FAIL(new_tablet->init(*tablet_handle.get_allocator(), param, false/*is_update*/, freezer))) {
if (OB_FAIL(new_tablet->init_with_migrate_param(*tablet_handle.get_allocator(), param, false/*is_update*/, freezer))) {
LOG_WARN("failed to init tablet", K(ret), K(param));
} else if (OB_FAIL(ObTabletSlogHelper::write_empty_shell_tablet_slog(new_tablet, disk_addr))) {
LOG_WARN("fail to write update tablet slog", K(ret), K(ls_id), K(tablet_id));
@ -3417,7 +3417,7 @@ int ObLSTabletService::build_ha_tablet_new_table_store(
if (OB_FAIL(ObTabletCreateDeleteHelper::acquire_tmp_tablet(key, allocator, tmp_tablet_handle))) {
LOG_WARN("failed to acquire tablet", K(ret), K(key));
} else if (FALSE_IT(tmp_tablet = tmp_tablet_handle.get_obj())) {
} else if (OB_FAIL(tmp_tablet->init(allocator, param, *old_tablet))) {
} else if (OB_FAIL(tmp_tablet->init_for_sstable_replace(allocator, param, *old_tablet))) {
LOG_WARN("failed to init tablet", K(ret), KPC(old_tablet));
} else if (FALSE_IT(time_guard.click("InitTablet"))) {
} else if (OB_FAIL(ObTabletPersister::persist_and_transform_tablet(*tmp_tablet, new_tablet_handle))) {

View File

@ -0,0 +1,62 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#include "storage/tablet/ob_batch_create_tablet_pretty_arg.h"
#include "lib/utility/ob_print_utils.h"
#include "share/ob_rpc_struct.h"
using namespace oceanbase::obrpc;
namespace oceanbase
{
namespace storage
{
ObBatchCreateTabletPrettyArg::ObBatchCreateTabletPrettyArg(const ObBatchCreateTabletArg &arg)
: arg_(arg)
{
}
int64_t ObBatchCreateTabletPrettyArg::to_string(char *buf, const int64_t buf_len) const
{
int64_t pos = 0;
if (OB_ISNULL(buf) || OB_UNLIKELY(buf_len <= 0)) {
// do nothing
} else {
J_OBJ_START();
J_KV("ls_id", arg_.id_,
"major_frozen_scn", arg_.major_frozen_scn_,
"total_tablet_cnt", arg_.get_tablet_count());
J_COMMA();
BUF_PRINTF("tablets");
J_COLON();
J_OBJ_START();
for (int64_t i = 0; i < arg_.tablets_.count(); ++i) {
const ObCreateTabletInfo &info = arg_.tablets_.at(i);
ObCurTraceId::TraceId *trace_id = ObCurTraceId::get_trace_id();
J_NEWLINE();
BUF_PRINTF("[%ld] [", GETTID());
BUF_PRINTO(PC(trace_id));
BUF_PRINTF("] ");
J_KV("data_tablet_id", info.data_tablet_id_,
"tablet_ids", info.tablet_ids_,
"compat_mode", info.compat_mode_,
"is_create_bind_hidden_tablets", info.is_create_bind_hidden_tablets_);
}
J_NEWLINE();
J_OBJ_END();
J_OBJ_END();
}
return pos;
}
} // namespace storage
} // namespace oceanbase

View File

@ -0,0 +1,42 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#ifndef OCEANBASE_STORAGE_OB_BATCH_CREATE_TABLET_PRETTY_ARG
#define OCEANBASE_STORAGE_OB_BATCH_CREATE_TABLET_PRETTY_ARG
#include <stdint.h>
namespace oceanbase
{
namespace obrpc
{
struct ObBatchCreateTabletArg;
}
namespace storage
{
class ObBatchCreateTabletPrettyArg
{
public:
ObBatchCreateTabletPrettyArg(const obrpc::ObBatchCreateTabletArg &arg);
~ObBatchCreateTabletPrettyArg() = default;
ObBatchCreateTabletPrettyArg(const ObBatchCreateTabletPrettyArg&) = delete;
ObBatchCreateTabletPrettyArg &operator=(const ObBatchCreateTabletPrettyArg&) = delete;
public:
int64_t to_string(char *buf, const int64_t buf_len) const;
private:
const obrpc::ObBatchCreateTabletArg &arg_;
};
} // namespace storage
} // namespace oceanbase
#endif // OCEANBASE_STORAGE_OB_BATCH_CREATE_TABLET_PRETTY_ARG

View File

@ -184,7 +184,7 @@ void ObTablet::reset()
is_inited_ = false;
}
int ObTablet::init(
int ObTablet::init_for_first_time_creation(
common::ObArenaAllocator &allocator,
const share::ObLSID &ls_id,
const common::ObTabletID &tablet_id,
@ -264,7 +264,7 @@ int ObTablet::init(
return ret;
}
int ObTablet::init(
int ObTablet::init_for_merge(
common::ObArenaAllocator &allocator,
const ObUpdateTableStoreParam &param,
const ObTablet &old_tablet)
@ -370,7 +370,7 @@ int ObTablet::init(
return ret;
}
int ObTablet::init(
int ObTablet::init_for_mds_table_dump(
common::ObArenaAllocator &allocator,
const ObTablet &old_tablet,
const share::SCN &flush_scn,
@ -434,14 +434,14 @@ int ObTablet::init(
set_next_tablet_guard(old_tablet.next_tablet_guard_);
}
is_inited_ = true;
LOG_INFO("succeeded to init tablet for dump mds table", K(ret), K(old_tablet), K(flush_scn), KPC(this), K(mds_table_data), K(base_data));
LOG_INFO("succeeded to init tablet for mds table dump", K(ret), K(old_tablet), K(flush_scn), KPC(this), K(mds_table_data), K(base_data));
}
ObTablet::free_storage_schema(tmp_arena_allocator, old_storage_schema);
return ret;
}
int ObTablet::init(
int ObTablet::init_with_migrate_param(
common::ObArenaAllocator &allocator,
const ObMigrationTabletParam &param,
const bool is_update,
@ -530,7 +530,7 @@ int ObTablet::init(
return ret;
}
int ObTablet::init(
int ObTablet::init_for_defragment(
common::ObArenaAllocator &allocator,
const ObIArray<ObITable *> &tables,
const ObTablet &old_tablet)
@ -608,7 +608,7 @@ int ObTablet::init(
return ret;
}
int ObTablet::init(
int ObTablet::init_for_sstable_replace(
common::ObArenaAllocator &allocator,
const ObBatchUpdateTableStoreParam &param,
const ObTablet &old_tablet)

View File

@ -145,7 +145,7 @@ public:
public:
// first time create tablet
int init(
int init_for_first_time_creation(
common::ObArenaAllocator &allocator,
const share::ObLSID &ls_id,
const common::ObTabletID &tablet_id,
@ -158,25 +158,25 @@ public:
blocksstable::ObSSTable *sstable,
ObFreezer *freezer);
// dump/merge build new multi version tablet
int init(
int init_for_merge(
common::ObArenaAllocator &allocator,
const ObUpdateTableStoreParam &param,
const ObTablet &old_tablet);
// dump/merge mds table to tablet_meta
int init(
int init_for_mds_table_dump(
common::ObArenaAllocator &allocator,
const ObTablet &old_tablet,
const share::SCN &flush_scn,
const ObTabletMdsData &mds_table_data,
const ObTabletMdsData &base_data);
// transfer build new tablet
int init(
int init_with_migrate_param(
common::ObArenaAllocator &allocator,
const ObMigrationTabletParam &param,
const bool is_update,
ObFreezer *freezer);
//batch update table store with range cut
int init(
int init_for_sstable_replace(
common::ObArenaAllocator &allocator,
const ObBatchUpdateTableStoreParam &param,
const ObTablet &old_tablet);
@ -185,7 +185,7 @@ public:
common::ObArenaAllocator &allocator,
const ObTablet &old_tablet);
// batch replace sstables without data modification
int init(
int init_for_defragment(
common::ObArenaAllocator &allocator,
const ObIArray<storage::ObITable *> &tables,
const ObTablet &old_tablet);

View File

@ -38,7 +38,6 @@
#define USING_LOG_PREFIX STORAGE
using namespace oceanbase::obrpc;
using namespace oceanbase::common;
using namespace oceanbase::share;
using namespace oceanbase::share::schema;
@ -665,46 +664,5 @@ int ObTabletCreateDeleteHelper::build_create_sstable_param(
return ret;
}
ObSimpleBatchCreateTabletArg::ObSimpleBatchCreateTabletArg(const ObBatchCreateTabletArg &arg)
: arg_(arg)
{
}
int64_t ObSimpleBatchCreateTabletArg::to_string(char *buf, const int64_t buf_len) const
{
int64_t pos = 0;
if (OB_ISNULL(buf) || OB_UNLIKELY(buf_len <= 0)) {
// do nothing
} else {
J_OBJ_START();
J_NAME("ObSimpleBatchCreateTabletArg");
J_COLON();
J_KV("id", arg_.id_,
"major_frozen_scn", arg_.major_frozen_scn_,
"total_tablet_cnt", arg_.get_tablet_count());
J_COMMA();
BUF_PRINTF("tablets");
J_COLON();
J_OBJ_START();
for (int64_t i = 0; i < arg_.tablets_.count(); ++i) {
const ObCreateTabletInfo &info = arg_.tablets_.at(i);
ObCurTraceId::TraceId *trace_id = ObCurTraceId::get_trace_id();
J_NEWLINE();
BUF_PRINTF("[%ld] [", GETTID());
BUF_PRINTO(PC(trace_id));
BUF_PRINTF("] ");
J_KV("data_tablet_id", info.data_tablet_id_,
"tablet_ids", info.tablet_ids_,
"compat_mode", info.compat_mode_,
"is_create_bind_hidden_tablets", info.is_create_bind_hidden_tablets_);
}
J_NEWLINE();
J_OBJ_END();
J_OBJ_END();
}
return pos;
}
} // namespace storage
} // namespace oceanbase

View File

@ -212,17 +212,6 @@ int ObTabletCreateDeleteHelper::process_for_old_mds(
}
return ret;
};
class ObSimpleBatchCreateTabletArg
{
public:
ObSimpleBatchCreateTabletArg(const obrpc::ObBatchCreateTabletArg &arg);
~ObSimpleBatchCreateTabletArg() = default;
public:
int64_t to_string(char *buf, const int64_t buf_len) const;
private:
const obrpc::ObBatchCreateTabletArg &arg_;
};
} // namespace storage
} // namespace oceanbase

View File

@ -22,14 +22,15 @@
#include "storage/meta_mem/ob_tenant_meta_mem_mgr.h"
#include "storage/meta_mem/ob_tablet_map_key.h"
#include "storage/meta_mem/ob_tablet_handle.h"
#include "storage/tablet/ob_batch_create_tablet_pretty_arg.h"
#include "storage/tablet/ob_tablet_create_delete_helper.h"
#include "storage/tablet/ob_tablet_create_delete_mds_user_data.h"
#include "storage/tablet/ob_tablet_create_replay_executor.h"
#include "storage/tx_storage/ob_ls_handle.h"
#include "storage/tx_storage/ob_ls_service.h"
#include "logservice/replayservice/ob_tablet_replay_executor.h"
#define USING_LOG_PREFIX MDS
#define PRETTY_ARG(arg) (ObSimpleBatchCreateTabletArg(arg))
#define PRETTY_ARG(arg) (ObBatchCreateTabletPrettyArg(arg))
using namespace oceanbase::common;
using namespace oceanbase::share;
@ -39,74 +40,6 @@ namespace oceanbase
{
namespace storage
{
class ObTabletCreateReplayExecutor final : public logservice::ObTabletReplayExecutor
{
public:
ObTabletCreateReplayExecutor();
int init(
mds::BufferCtx &user_ctx,
const share::SCN &scn,
const bool for_old_mds);
protected:
bool is_replay_update_tablet_status_() const override
{
return true;
}
int do_replay_(ObTabletHandle &tablet_handle) override;
virtual bool is_replay_update_mds_table_() const override
{
return true;
}
private:
mds::BufferCtx *user_ctx_;
share::SCN scn_;
bool for_old_mds_;
};
ObTabletCreateReplayExecutor::ObTabletCreateReplayExecutor()
:logservice::ObTabletReplayExecutor(), user_ctx_(nullptr)
{}
int ObTabletCreateReplayExecutor::init(
mds::BufferCtx &user_ctx,
const share::SCN &scn,
const bool for_old_mds)
{
int ret = OB_SUCCESS;
if (OB_UNLIKELY(is_inited_)) {
ret = OB_INIT_TWICE;
LOG_WARN("tablet create replay executor init twice", KR(ret), K_(is_inited));
} else if (OB_UNLIKELY(!scn.is_valid())) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("get invalid argument", KR(ret), K(scn));
} else {
user_ctx_ = &user_ctx;
scn_ = scn;
is_inited_ = true;
for_old_mds_ = for_old_mds;
}
return ret;
}
int ObTabletCreateReplayExecutor::do_replay_(ObTabletHandle &tablet_handle)
{
int ret = OB_SUCCESS;
mds::MdsCtx &user_ctx = static_cast<mds::MdsCtx&>(*user_ctx_);
ObTabletCreateDeleteMdsUserData user_data(ObTabletStatus::NORMAL, ObTabletMdsUserDataType::CREATE_TABLET);
if (OB_FAIL(replay_to_mds_table_(tablet_handle, user_data, user_ctx, scn_, for_old_mds_))) {
LOG_WARN("failed to replay to tablet", K(ret));
}
return ret;
}
int ObTabletCreateMdsHelper::on_commit_for_old_mds(
const char* buf,
const int64_t len,

View File

@ -0,0 +1,66 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#include "storage/tablet/ob_tablet_create_replay_executor.h"
#include "lib/ob_errno.h"
#include "lib/oblog/ob_log_module.h"
#include "lib/utility/ob_print_utils.h"
#include "storage/multi_data_source/buffer_ctx.h"
#include "storage/tablet/ob_tablet_create_delete_mds_user_data.h"
#define USING_LOG_PREFIX STORAGE
namespace oceanbase
{
namespace storage
{
ObTabletCreateReplayExecutor::ObTabletCreateReplayExecutor()
: logservice::ObTabletReplayExecutor(),
user_ctx_(nullptr)
{
}
int ObTabletCreateReplayExecutor::init(
mds::BufferCtx &user_ctx,
const share::SCN &scn,
const bool for_old_mds)
{
int ret = OB_SUCCESS;
if (OB_UNLIKELY(is_inited_)) {
ret = OB_INIT_TWICE;
LOG_WARN("tablet create replay executor init twice", KR(ret), K_(is_inited));
} else if (OB_UNLIKELY(!scn.is_valid())) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("get invalid argument", KR(ret), K(scn));
} else {
user_ctx_ = &user_ctx;
scn_ = scn;
is_inited_ = true;
for_old_mds_ = for_old_mds;
}
return ret;
}
int ObTabletCreateReplayExecutor::do_replay_(ObTabletHandle &tablet_handle)
{
int ret = OB_SUCCESS;
mds::MdsCtx &user_ctx = static_cast<mds::MdsCtx&>(*user_ctx_);
ObTabletCreateDeleteMdsUserData user_data(ObTabletStatus::NORMAL, ObTabletMdsUserDataType::CREATE_TABLET);
if (OB_FAIL(replay_to_mds_table_(tablet_handle, user_data, user_ctx, scn_, for_old_mds_))) {
LOG_WARN("failed to replay to tablet", K(ret));
}
return ret;
}
} // namespace storage
} // namespace oceanbase

View File

@ -0,0 +1,59 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#ifndef OCEANBASE_STORAGE_OB_TABLET_REPLAY_EXECUTOR
#define OCEANBASE_STORAGE_OB_TABLET_REPLAY_EXECUTOR
#include "logservice/replayservice/ob_tablet_replay_executor.h"
#include "share/scn.h"
namespace oceanbase
{
namespace storage
{
namespace mds
{
class BufferCtx;
}
class ObTabletCreateReplayExecutor final : public logservice::ObTabletReplayExecutor
{
public:
ObTabletCreateReplayExecutor();
int init(
mds::BufferCtx &user_ctx,
const share::SCN &scn,
const bool for_old_mds);
protected:
bool is_replay_update_tablet_status_() const override
{
return true;
}
int do_replay_(ObTabletHandle &tablet_handle) override;
virtual bool is_replay_update_mds_table_() const override
{
return true;
}
private:
mds::BufferCtx *user_ctx_;
share::SCN scn_;
bool for_old_mds_;
};
} // namespace storage
} // namespace oceanbase
#endif // OCEANBASE_STORAGE_OB_TABLET_REPLAY_EXECUTOR