From 129e7dd5ff5863b941ac0ba9f31488d21f3403d0 Mon Sep 17 00:00:00 2001 From: obdev Date: Thu, 16 Nov 2023 13:42:24 +0000 Subject: [PATCH] when creating a tablet, replace table schema with storage schema in clog. --- .../src/ob_cdc_tablet_to_table_info.cpp | 25 ++- src/rootserver/ob_tablet_creator.cpp | 75 ++++++--- src/rootserver/ob_tablet_creator.h | 18 ++- src/share/ob_rpc_struct.cpp | 124 ++++++++++++++- src/share/ob_rpc_struct.h | 12 +- src/storage/ls/ob_ls_tablet_service.cpp | 9 +- src/storage/ls/ob_ls_tablet_service.h | 3 +- src/storage/memtable/ob_memtable_mutator.cpp | 149 ------------------ src/storage/memtable/ob_memtable_mutator.h | 37 ----- src/storage/ob_storage_schema.cpp | 70 +++++++- src/storage/ob_storage_schema.h | 47 +++++- src/storage/tablet/ob_tablet.cpp | 100 ++++++++++++ src/storage/tablet/ob_tablet.h | 10 ++ .../tablet/ob_tablet_binding_helper.cpp | 29 ++-- src/storage/tablet/ob_tablet_binding_helper.h | 2 +- .../tablet/ob_tablet_create_delete_helper.cpp | 16 ++ .../tablet/ob_tablet_create_delete_helper.h | 5 +- .../tablet/ob_tablet_create_mds_helper.cpp | 102 +++++++++--- .../tablet/ob_tablet_create_mds_helper.h | 1 + 19 files changed, 573 insertions(+), 261 deletions(-) diff --git a/src/logservice/libobcdc/src/ob_cdc_tablet_to_table_info.cpp b/src/logservice/libobcdc/src/ob_cdc_tablet_to_table_info.cpp index 8548bae9ef..f1be4f9ae5 100644 --- a/src/logservice/libobcdc/src/ob_cdc_tablet_to_table_info.cpp +++ b/src/logservice/libobcdc/src/ob_cdc_tablet_to_table_info.cpp @@ -135,7 +135,9 @@ int ObCDCTabletChangeInfo::parse_create_tablet_op_( ret = OB_ERR_UNEXPECTED; LOG_ERROR("ObBatchCreateTabletArg is invalid", KR(ret), K(tls_id), K(create_tablet_arg)); } else { + // the schema in create tablet arg is ObCreateTabletSchema after 4.2.2.0, the previous is ObTableSchema const common::ObSArray &table_schemas = create_tablet_arg.table_schemas_; + const ObSArray &create_tablet_schemas = create_tablet_arg.create_tablet_schemas_; const common::ObSArray &tablets_info = create_tablet_arg.tablets_; for (int64_t create_tablet_idx = 0; OB_SUCC(ret) && create_tablet_idx < tablets_info.count(); create_tablet_idx++) { @@ -146,13 +148,28 @@ int ObCDCTabletChangeInfo::parse_create_tablet_op_( for (int64_t tablet_id_idx = 0; OB_SUCC(ret) && tablet_id_idx < tablet_ids.count(); tablet_id_idx++) { const common::ObTabletID &tablet_id = tablet_ids.at(tablet_id_idx); const int64_t table_schema_idx = tb_schema_index_arr.at(tablet_id_idx); - if (OB_UNLIKELY(0 > table_schema_idx || table_schemas.count() <= table_schema_idx)) { + uint64_t table_id = common::OB_INVALID_ID; + share::schema::ObTableType table_type = share::schema::MAX_TABLE_TYPE; + if (OB_UNLIKELY(0 > table_schema_idx + || (create_tablet_schemas.count() <= table_schema_idx && table_schemas.count() <= table_schema_idx))) { ret = OB_ERR_UNEXPECTED; LOG_ERROR("invalid table_schema_index", KR(ret), K(tls_id), K(ob_create_tablet_info), K(table_schemas), K(table_schema_idx)); - } else { + } else if (create_tablet_schemas.count() > 0) { + const ObCreateTabletSchema *create_tablet_schema = create_tablet_schemas.at(table_schema_idx); + if (OB_ISNULL(create_tablet_schema)) { + ret = OB_INVALID_ARGUMENT; + LOG_ERROR("create_tablet_schema is NULL", KR(ret), K(tls_id), K(create_tablet_idx), K(tablet_id_idx), + K(table_schema_idx), K(ob_create_tablet_info), K(tablet_ids), K(tb_schema_index_arr)); + } else { + table_id = create_tablet_schema->get_table_id(); + table_type = create_tablet_schema->get_table_type(); + } + } else if (table_schemas.count() > 0) { const ObTableSchema &table_schema = table_schemas.at(table_schema_idx); - const uint64_t table_id = table_schema.get_table_id(); - const share::schema::ObTableType table_type = table_schema.get_table_type(); + table_id = table_schema.get_table_id(); + table_type = table_schema.get_table_type(); + } + if (OB_SUCC(ret)) { ObCDCTableInfo table_info; table_info.reset(table_id, table_type); CreateTabletOp create_tablet_op; diff --git a/src/rootserver/ob_tablet_creator.cpp b/src/rootserver/ob_tablet_creator.cpp index 70c6541ca3..ddfd257ab5 100644 --- a/src/rootserver/ob_tablet_creator.cpp +++ b/src/rootserver/ob_tablet_creator.cpp @@ -120,7 +120,7 @@ int ObBatchCreateTabletHelper::init( || OB_INVALID_TENANT_ID == tenant_id)) { ret = OB_INVALID_ARGUMENT; LOG_WARN("invalid argument", KR(ret), K(tenant_id), K(ls_key)); - } else if (OB_FAIL(arg_.init_create_tablet(ls_key, major_frozen_scn, need_check_tablet_cnt))) { + } else if (OB_FAIL(batch_arg_.init_create_tablet(ls_key, major_frozen_scn, need_check_tablet_cnt))) { LOG_WARN("failed to init create tablet", KR(ret), K(tenant_id), K(ls_key), K(major_frozen_scn)); } else if (OB_FAIL(table_schemas_map_.create(bucket_count, "CreateTablet", "CreateTablet"))) { LOG_WARN("failed to create hashmap", KR(ret)); @@ -143,11 +143,11 @@ int ObBatchCreateTabletHelper::add_arg_to_batch_arg( if (OB_ISNULL(table_schema)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("table schema is null", KR(ret), K(i), K(tablet_arg)); - } else if (OB_FAIL(try_add_table_schema(table_schema, index))) { - LOG_WARN("failed to add table schema to batch", KR(ret), K(table_schema), K(index), K(arg_)); + } else if (OB_FAIL(try_add_table_schema(table_schema, index, tablet_arg.compat_mode_))) { + LOG_WARN("failed to add table schema to batch", KR(ret), K(table_schema), K(index), K(batch_arg_)); } else if (OB_UNLIKELY(OB_INVALID_INDEX == index)) { ret = OB_ERR_UNEXPECTED; - LOG_WARN("index can not be invalid", KR(ret), K(index), K(tablet_arg), K(arg_)); + LOG_WARN("index can not be invalid", KR(ret), K(index), K(tablet_arg), K(batch_arg_)); } else if (OB_FAIL(index_array.push_back(index))) { LOG_WARN("failed to push back index", KR(ret), K(index)); } @@ -160,7 +160,7 @@ int ObBatchCreateTabletHelper::add_arg_to_batch_arg( tablet_arg.compat_mode_, tablet_arg.is_create_bind_hidden_tablets_))) { LOG_WARN("failed to init create tablet info", KR(ret), K(index_array), K(tablet_arg)); - } else if (OB_FAIL(arg_.tablets_.push_back(info))) { + } else if (OB_FAIL(batch_arg_.tablets_.push_back(info))) { LOG_WARN("failed to push back info", KR(ret), K(info)); } } @@ -168,8 +168,42 @@ int ObBatchCreateTabletHelper::add_arg_to_batch_arg( return ret; } +int ObBatchCreateTabletHelper::add_table_schema_(const share::schema::ObTableSchema &table_schema, + const lib::Worker::CompatMode compat_mode, + int64_t &index) +{ + int ret = OB_SUCCESS; + uint64_t data_version = 0; + if (OB_FAIL(GET_MIN_DATA_VERSION(table_schema.get_tenant_id(), data_version))) { + LOG_WARN("failed to get data version", KR(ret), K(table_schema)); + } else if (data_version < DATA_VERSION_4_2_2_0) { + // compatibility with DATA_VERSION_4_2_1. + index = batch_arg_.table_schemas_.count(); + if (OB_FAIL(batch_arg_.table_schemas_.push_back(table_schema))) { + LOG_WARN("failed to push back table schema", KR(ret), K(table_schema)); + } + } else { + index = batch_arg_.create_tablet_schemas_.count(); + ObCreateTabletSchema *create_tablet_schema = NULL; + void *create_tablet_schema_ptr = batch_arg_.allocator_.alloc(sizeof(ObCreateTabletSchema)); + if (OB_ISNULL(create_tablet_schema_ptr)) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_WARN("failed to allocate storage schema", KR(ret), K(table_schema)); + } else if (FALSE_IT(create_tablet_schema = new (create_tablet_schema_ptr)ObCreateTabletSchema())) { + } else if (OB_FAIL(create_tablet_schema->init(batch_arg_.allocator_, table_schema, compat_mode, + false/*skip_column_info*/, ObCreateTabletSchema::STORAGE_SCHEMA_VERSION_V3))) { + LOG_WARN("failed to init storage schema", KR(ret), K(table_schema)); + } else if (OB_FAIL(batch_arg_.create_tablet_schemas_.push_back(create_tablet_schema))) { + LOG_WARN("failed to push back table schema", KR(ret), K(table_schema)); + } + } + return ret; +} + int ObBatchCreateTabletHelper::try_add_table_schema( - const share::schema::ObTableSchema *table_schema, int64_t &index) + const share::schema::ObTableSchema *table_schema, + int64_t &index, + const lib::Worker::CompatMode compat_mode) { int ret = OB_SUCCESS; index = OB_INVALID_INDEX; @@ -181,12 +215,11 @@ int ObBatchCreateTabletHelper::try_add_table_schema( //nothing } else if(OB_HASH_NOT_EXIST == ret) { ret = OB_SUCCESS; - index = arg_.table_schemas_.count(); HEAP_VAR(ObTableSchema, temp_table_schema) { if (OB_FAIL(temp_table_schema.assign(*table_schema))) { LOG_WARN("failed to assign temp_table_schema", KR(ret), KPC(table_schema)); } else if (FALSE_IT(temp_table_schema.reset_partition_schema())) { - } else if (OB_FAIL(arg_.table_schemas_.push_back(temp_table_schema))) { + } else if (OB_FAIL(add_table_schema_(temp_table_schema, compat_mode, index))) { LOG_WARN("failed to push back table schema", KR(ret), K(temp_table_schema)); } else if (OB_FAIL(table_schemas_map_.set_refactored(temp_table_schema.get_table_id(), index))) { LOG_WARN("failed to set table schema map", KR(ret), K(index), K(temp_table_schema)); @@ -201,7 +234,7 @@ int ObBatchCreateTabletHelper::try_add_table_schema( DEF_TO_STRING(ObBatchCreateTabletHelper) { int64_t pos = 0; - J_KV(K_(arg), K_(result)); + J_KV(K_(batch_arg), K_(result)); return pos; } @@ -261,7 +294,8 @@ int ObTabletCreator::add_create_tablet_arg(const ObTabletCreatorArg &arg) ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("failed to allocate new arg", KR(ret), KP(batch_arg)); } else if (FALSE_IT(batch_arg = new (arg_buf)ObBatchCreateTabletHelper())) { - } else if (OB_FAIL(batch_arg->init(arg.ls_key_, tenant_id_, major_frozen_scn_, need_check_tablet_cnt_))) { + } else if (OB_FAIL(batch_arg->init(arg.ls_key_, tenant_id_, major_frozen_scn_, + need_check_tablet_cnt_))) { LOG_WARN("failed to init batch arg helper", KR(ret), K(arg)); } else if (OB_FAIL(args_map_.set_refactored(arg.ls_key_, batch_arg, 0/*not overwrite*/))) { LOG_WARN("fail to set refactored", KR(ret), K(arg)); @@ -273,15 +307,16 @@ int ObTabletCreator::add_create_tablet_arg(const ObTabletCreatorArg &arg) } if (OB_FAIL(ret)) { - } else if (batch_arg->arg_.get_serialize_size() > BATCH_ARG_SIZE) { - LOG_INFO("batch arg is more than 1M", KR(ret), K(batch_arg->arg_.tablets_.count()), K(batch_arg->arg_)); + } else if (batch_arg->batch_arg_.get_serialize_size() > BATCH_ARG_SIZE) { + LOG_INFO("batch arg is more than 1M", KR(ret), K(batch_arg->batch_arg_.tablets_.count()), K(batch_arg->batch_arg_)); void *arg_buf = allocator_.alloc(sizeof(ObBatchCreateTabletHelper)); ObBatchCreateTabletHelper *new_arg = NULL; if (OB_ISNULL(arg_buf)) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("failed to allocate new arg", KR(ret)); } else if (FALSE_IT(new_arg = new (arg_buf)ObBatchCreateTabletHelper())) { - } else if (OB_FAIL(new_arg->init(arg.ls_key_, tenant_id_, major_frozen_scn_, need_check_tablet_cnt_))) { + } else if (OB_FAIL(new_arg->init(arg.ls_key_, tenant_id_, major_frozen_scn_, + need_check_tablet_cnt_))) { LOG_WARN("failed to init batch arg helper", KR(ret), K(arg)); } else if (FALSE_IT(new_arg->next_ = batch_arg)) { } else if (OB_FAIL(args_map_.set_refactored(arg.ls_key_, new_arg, 1/*not overwrite*/))) { @@ -323,14 +358,14 @@ int ObTabletCreator::execute() LOG_WARN("batch arg not be null", KR(ret)); } else { while (OB_SUCC(ret) && OB_NOT_NULL(batch_arg)) { - int64_t buf_len = batch_arg->arg_.get_serialize_size(); + int64_t buf_len = batch_arg->batch_arg_.get_serialize_size(); int64_t pos = 0; char *buf = (char*)allocator_.alloc(buf_len); if (OB_ISNULL(buf)) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("fail alloc memory", KR(ret)); - } else if (OB_FAIL(batch_arg->arg_.serialize(buf, buf_len, pos))) { - LOG_WARN("fail to serialize", KR(ret), K(batch_arg->arg_)); + } else if (OB_FAIL(batch_arg->batch_arg_.serialize(buf, buf_len, pos))) { + LOG_WARN("fail to serialize", KR(ret), K(batch_arg->batch_arg_)); } else if (OB_FAIL(share::ObShareUtil::set_default_timeout_ctx(ctx, default_timeout_ts))) { LOG_WARN("fail to set timeout ctx", KR(ret), K(default_timeout_ts)); } else { @@ -342,15 +377,15 @@ int ObTabletCreator::execute() } else if (OB_FAIL(conn->register_multi_data_source(tenant_id_, iter->first, transaction::ObTxDataSourceType::CREATE_TABLET_NEW_MDS, buf, buf_len))) { if (need_retry(ret)) { - LOG_INFO("fail to register_tx_data, try again", KR(ret), K_(tenant_id), K(batch_arg->arg_)); + LOG_INFO("fail to register_tx_data, try again", KR(ret), K_(tenant_id), K(batch_arg->batch_arg_)); ob_usleep(SLEEP_INTERVAL); } else { - LOG_WARN("fail to register_tx_data", KR(ret), K(batch_arg->arg_), K(buf), K(buf_len)); + LOG_WARN("fail to register_tx_data", KR(ret), K(batch_arg->batch_arg_), K(buf), K(buf_len)); } } int64_t end_time = ObTimeUtility::current_time(); - LOG_INFO("generate create arg", KR(ret), K(buf_len), K(batch_arg->arg_.tablets_.count()), - K(batch_arg->arg_), "cost_ts", end_time - start_time); + LOG_INFO("generate create arg", KR(ret), K(buf_len), K(batch_arg->batch_arg_.tablets_.count()), + K(batch_arg->batch_arg_), "cost_ts", end_time - start_time); } while (need_retry(ret)); } batch_arg = batch_arg->next_; diff --git a/src/rootserver/ob_tablet_creator.h b/src/rootserver/ob_tablet_creator.h index fcbc1eb8f8..56dc00605a 100644 --- a/src/rootserver/ob_tablet_creator.h +++ b/src/rootserver/ob_tablet_creator.h @@ -63,27 +63,37 @@ private: struct ObBatchCreateTabletHelper { public: - ObBatchCreateTabletHelper() :arg_(), table_schemas_map_(), result_(common::OB_NOT_MASTER), next_(NULL) {} + ObBatchCreateTabletHelper() + : batch_arg_(), + table_schemas_map_(), + result_(common::OB_NOT_MASTER), + next_(NULL) + {} int init(const share::ObLSID &ls_key, const int64_t tenant_id, const share::SCN &major_frozen_scn, const bool need_check_tablet_cnt); - int try_add_table_schema(const share::schema::ObTableSchema *table_schema, int64_t &index); + int try_add_table_schema(const share::schema::ObTableSchema *table_schema, + int64_t &index, + const lib::Worker::CompatMode compat_mode); int add_arg_to_batch_arg(const ObTabletCreatorArg &arg); void reset() { - arg_.reset(); + batch_arg_.reset(); table_schemas_map_.clear(); result_ = common::OB_NOT_MASTER; } DECLARE_TO_STRING; - obrpc::ObBatchCreateTabletArg arg_; + obrpc::ObBatchCreateTabletArg batch_arg_; //table_id : index of table_schems_ in arg common::hash::ObHashMap table_schemas_map_; //the result of create tablet int result_; ObBatchCreateTabletHelper *next_; private: + int add_table_schema_(const share::schema::ObTableSchema &table_schema, + const lib::Worker::CompatMode compat_mode, + int64_t &index); DISALLOW_COPY_AND_ASSIGN(ObBatchCreateTabletHelper); }; diff --git a/src/share/ob_rpc_struct.cpp b/src/share/ob_rpc_struct.cpp index 7cf2dec4d1..dd7cebed99 100755 --- a/src/share/ob_rpc_struct.cpp +++ b/src/share/ob_rpc_struct.cpp @@ -7939,7 +7939,7 @@ bool ObBatchCreateTabletArg::is_inited() const bool ObBatchCreateTabletArg::is_valid() const { bool valid = true; - if (is_inited() && tablets_.count() > 0 && table_schemas_.count() > 0) { + if (is_inited() && tablets_.count() > 0 && (create_tablet_schemas_.count() > 0 || table_schemas_.count() > 0)) { for (int64_t i = 0; valid && i < tablets_.count(); ++i) { const ObCreateTabletInfo &info = tablets_[i]; const common::ObSArray &table_schema_index = info.table_schema_index_; @@ -7949,7 +7949,7 @@ bool ObBatchCreateTabletArg::is_valid() const for (int64_t j = 0; valid && j < table_schema_index.count(); ++j) { const int64_t index = table_schema_index[j]; - if (index < 0 || index >= table_schemas_.count()) { + if (index < 0 || (index >= create_tablet_schemas_.count() && index >= table_schemas_.count())) { valid = false; } } @@ -7968,11 +7968,17 @@ void ObBatchCreateTabletArg::reset() table_schemas_.reset(); need_check_tablet_cnt_ = false; is_old_mds_ = false; + for (int64_t i = 0; i < create_tablet_schemas_.count(); ++i) { + create_tablet_schemas_[i]->~ObCreateTabletSchema(); + } + create_tablet_schemas_.reset(); + allocator_.reset(); } int ObBatchCreateTabletArg::assign(const ObBatchCreateTabletArg &arg) { int ret = OB_SUCCESS; + const common::ObSArray &create_tablet_schemas = arg.create_tablet_schemas_; if (OB_UNLIKELY(!arg.is_valid())) { ret = OB_INVALID_ARGUMENT; LOG_WARN("arg is invalid", KR(ret), K(arg)); @@ -7980,6 +7986,32 @@ int ObBatchCreateTabletArg::assign(const ObBatchCreateTabletArg &arg) LOG_WARN("failed to assign tablets", KR(ret), K(arg)); } else if (OB_FAIL(table_schemas_.assign(arg.table_schemas_))) { LOG_WARN("failed to assign table schema", KR(ret), K(arg)); + } else if (OB_FAIL(create_tablet_schemas_.reserve(create_tablet_schemas.count()))) { + STORAGE_LOG(WARN, "Fail to reserve schema array", K(ret), K(create_tablet_schemas.count())); + } else { + for (int64_t i = 0; OB_SUCC(ret) && i < create_tablet_schemas.count(); ++i) { + if (OB_ISNULL(create_tablet_schemas[i])) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid argument", KR(ret), K(i), KPC(this)); + } else { + ObCreateTabletSchema *create_tablet_schema = NULL; + void *create_tablet_schema_ptr = allocator_.alloc(sizeof(ObCreateTabletSchema)); + if (OB_ISNULL(create_tablet_schema_ptr)) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_WARN("failed to allocate storage schema", KR(ret)); + } else if (FALSE_IT(create_tablet_schema = new (create_tablet_schema_ptr)ObCreateTabletSchema())) { + } else if (OB_FAIL(create_tablet_schema->init(allocator_, *create_tablet_schemas[i]))) { + create_tablet_schema->~ObCreateTabletSchema(); + STORAGE_LOG(WARN,"Fail to init create_tablet_schema", K(ret)); + } else if (OB_FAIL(create_tablet_schemas_.push_back(create_tablet_schema))) { + create_tablet_schema->~ObCreateTabletSchema(); + STORAGE_LOG(WARN, "Fail to add schema", K(ret)); + } + } + } + } + if (OB_FAIL(ret)) { + reset(); } else { id_ = arg.id_; major_frozen_scn_ = arg.major_frozen_scn_; @@ -8035,6 +8067,84 @@ int64_t ObBatchCreateTabletArg::get_tablet_count() const return cnt; } +int ObBatchCreateTabletArg::serialize_for_create_tablet_schemas(char *buf, + const int64_t data_len, + int64_t &pos) const +{ + int ret = OB_SUCCESS; + if (OB_FAIL(serialization::encode_vi64(buf, data_len, pos, create_tablet_schemas_.count()))) { + STORAGE_LOG(WARN, "failed to encode schema count", K(ret)); + } + for (int64_t i = 0; OB_SUCC(ret) && i < create_tablet_schemas_.count(); ++i) { + if (OB_ISNULL(create_tablet_schemas_.at(i))) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("null tx service ptr", KR(ret), K(i), KPC(this)); + } else if (OB_FAIL(create_tablet_schemas_.at(i)->serialize(buf, data_len, pos))) { + STORAGE_LOG(WARN, "failed to serialize schema", K(ret)); + } + } + return ret; +} + +int64_t ObBatchCreateTabletArg::get_serialize_size_for_create_tablet_schemas() const +{ + int ret = OB_SUCCESS; + int64_t len = 0; + len += serialization::encoded_length_vi64(create_tablet_schemas_.count()); + for (int64_t i = 0; OB_SUCC(ret) && i < create_tablet_schemas_.count(); ++i) { + if (OB_ISNULL(create_tablet_schemas_.at(i))) { + ret = OB_INVALID_ARGUMENT; + LOG_ERROR("create_tablet_schema is NULL", KR(ret), K(i), KPC(this)); + } else { + len += create_tablet_schemas_.at(i)->get_serialize_size(); + } + } + return len; +} + +int ObBatchCreateTabletArg::deserialize_create_tablet_schemas(const char *buf, + const int64_t data_len, + int64_t &pos) +{ + int ret = OB_SUCCESS; + int64_t count = 0; + if (OB_ISNULL(buf) || OB_UNLIKELY(data_len <= 0) || OB_UNLIKELY(pos > data_len)) { + ret = OB_INVALID_ARGUMENT; + STORAGE_LOG(WARN, "invalid argument", K(buf), K(data_len), K(pos), K(ret)); + } else if (pos == data_len) { + //do nothing + } else if (OB_FAIL(serialization::decode_vi64(buf, data_len, pos, &count))) { + STORAGE_LOG(WARN, "failed to decode schema count", K(ret)); + } else if (count < 0) { + ret = OB_INVALID_ARGUMENT; + STORAGE_LOG(WARN, "count invalid", KR(ret), K(buf), K(data_len), K(pos), K(count)); + } else if (count == 0) { + STORAGE_LOG(INFO, "upgrade, count is 0", KR(ret), K(buf), K(data_len), K(pos), K(count)); + } else if (OB_FAIL(create_tablet_schemas_.reserve(count))) { + STORAGE_LOG(WARN, "failed to reserve schema array", K(ret), K(count), K(buf), K(data_len), K(pos)); + } else { + for (int64_t i = 0; OB_SUCC(ret) && i < count; ++i) { + ObCreateTabletSchema *create_tablet_schema = NULL; + void *create_tablet_schema_ptr = allocator_.alloc(sizeof(ObCreateTabletSchema)); + if (OB_ISNULL(create_tablet_schema_ptr)) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_WARN("failed to allocate storage schema", KR(ret)); + } else if (FALSE_IT(create_tablet_schema = new (create_tablet_schema_ptr)ObCreateTabletSchema())) { + } else if (OB_FAIL(create_tablet_schema->deserialize(allocator_, buf, data_len, pos))) { + create_tablet_schema->~ObCreateTabletSchema(); + STORAGE_LOG(WARN,"failed to deserialize schema", K(ret), K(buf), K(data_len), K(pos)); + } else if (OB_FAIL(create_tablet_schemas_.push_back(create_tablet_schema))) { + create_tablet_schema->~ObCreateTabletSchema(); + STORAGE_LOG(WARN, "failed to add schema", K(ret)); + } + } + if (OB_FAIL(ret)) { + reset(); + } + } + return ret; +} + DEF_TO_STRING(ObBatchCreateTabletArg) { int64_t pos = 0; @@ -8046,6 +8156,10 @@ OB_DEF_SERIALIZE(ObBatchCreateTabletArg) { int ret = OB_SUCCESS; LST_DO_CODE(OB_UNIS_ENCODE, id_, major_frozen_scn_, tablets_, table_schemas_, need_check_tablet_cnt_, is_old_mds_); + if (OB_FAIL(ret)) { + } else if (OB_FAIL(serialize_for_create_tablet_schemas(buf, buf_len, pos))) { + LOG_WARN("failed to serialize_for_create_tablet_schemas", KR(ret), KPC(this)); + } return ret; } @@ -8053,6 +8167,7 @@ OB_DEF_SERIALIZE_SIZE(ObBatchCreateTabletArg) { int len = 0; LST_DO_CODE(OB_UNIS_ADD_LEN, id_, major_frozen_scn_, tablets_, table_schemas_, need_check_tablet_cnt_, is_old_mds_); + len += get_serialize_size_for_create_tablet_schemas(); return len; } @@ -8065,6 +8180,11 @@ OB_DEF_DESERIALIZE(ObBatchCreateTabletArg) is_old_mds_ = true; } else { LST_DO_CODE(OB_UNIS_DECODE, is_old_mds_); + if (OB_FAIL(ret)) { + } else if (pos == data_len) { + } else if (OB_FAIL(deserialize_create_tablet_schemas(buf, data_len, pos))) { + LOG_WARN("failed to deserialize_for_create_tablet_schemas", KR(ret)); + } } } return ret; diff --git a/src/share/ob_rpc_struct.h b/src/share/ob_rpc_struct.h index 0df688e622..4db05f9fc9 100755 --- a/src/share/ob_rpc_struct.h +++ b/src/share/ob_rpc_struct.h @@ -3434,7 +3434,8 @@ struct ObBatchCreateTabletArg { OB_UNIS_VERSION(1); public: - ObBatchCreateTabletArg() { reset(); } + ObBatchCreateTabletArg() + { reset(); } ~ObBatchCreateTabletArg() {} bool is_valid() const; bool is_inited() const; @@ -3444,6 +3445,13 @@ public: const share::SCN &major_frozen_scn, const bool need_check_tablet_cnt); int64_t get_tablet_count() const; + int serialize_for_create_tablet_schemas(char *buf, + const int64_t data_len, + int64_t &pos) const; + int64_t get_serialize_size_for_create_tablet_schemas() const; + int deserialize_create_tablet_schemas(const char *buf, + const int64_t data_len, + int64_t &pos); DECLARE_TO_STRING; public: @@ -3453,6 +3461,8 @@ public: common::ObSArray tablets_; bool need_check_tablet_cnt_; bool is_old_mds_; + common::ObSArray create_tablet_schemas_; + ObArenaAllocator allocator_; }; struct ObBatchRemoveTabletArg diff --git a/src/storage/ls/ob_ls_tablet_service.cpp b/src/storage/ls/ob_ls_tablet_service.cpp index fd86230893..0fbb5bd088 100644 --- a/src/storage/ls/ob_ls_tablet_service.cpp +++ b/src/storage/ls/ob_ls_tablet_service.cpp @@ -1936,8 +1936,7 @@ int ObLSTabletService::create_tablet( const common::ObTabletID &data_tablet_id, const share::SCN &create_scn, const int64_t snapshot_version, - const share::schema::ObTableSchema &table_schema, - const lib::Worker::CompatMode &compat_mode, + const ObCreateTabletSchema &create_tablet_schema, ObTabletHandle &tablet_handle) { int ret = OB_SUCCESS; @@ -1961,12 +1960,12 @@ int ObLSTabletService::create_tablet( ret = OB_ERR_UNEXPECTED; LOG_ERROR("new tablet is null", K(ret), KP(tablet), KP(allocator), K(tablet_handle)); } else if (OB_FAIL(ObTabletCreateDeleteHelper::check_need_create_empty_major_sstable( - table_schema, need_create_empty_major_sstable))) { + create_tablet_schema, need_create_empty_major_sstable))) { LOG_WARN("failed to check need create sstable", K(ret)); } 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, need_create_empty_major_sstable, freezer))) { + create_scn, snapshot_version, create_tablet_schema, need_create_empty_major_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(create_scn), K(snapshot_version), K(create_tablet_schema)); } 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)); } else if (OB_FAIL(tablet_id_set_.set(tablet_id))) { diff --git a/src/storage/ls/ob_ls_tablet_service.h b/src/storage/ls/ob_ls_tablet_service.h index ad3d310b83..310808fda0 100644 --- a/src/storage/ls/ob_ls_tablet_service.h +++ b/src/storage/ls/ob_ls_tablet_service.h @@ -185,8 +185,7 @@ public: const common::ObTabletID &data_tablet_id, const share::SCN &create_scn, const int64_t snapshot_version, - const share::schema::ObTableSchema &table_schema, - const lib::Worker::CompatMode &compat_mode, + const ObCreateTabletSchema &create_tablet_schema, ObTabletHandle &tablet_handle); int create_transfer_in_tablet( const share::ObLSID &ls_id, diff --git a/src/storage/memtable/ob_memtable_mutator.cpp b/src/storage/memtable/ob_memtable_mutator.cpp index 7d983001df..bbab8d2497 100644 --- a/src/storage/memtable/ob_memtable_mutator.cpp +++ b/src/storage/memtable/ob_memtable_mutator.cpp @@ -847,155 +847,6 @@ int ObMutatorTableLock::deserialize( return ret; } -int ObLsmtMutatorRow::set(const uint64_t table_id, - const int64_t table_version, - const common::ObTabletID primary_row_id, - const blocksstable::ObDmlFlag dml_flag, - const obrpc::ObBatchCreateTabletArg * create_arg, - const obrpc::ObBatchRemoveTabletArg * remove_arg) -{ - table_id_ = table_id; - table_version_ = table_version; - dml_flag_ = dml_flag; - primary_row_id_ = primary_row_id; - int ret = OB_SUCCESS; - if (ObDmlFlag::DF_INSERT == dml_flag){ - if (OB_ISNULL(create_arg)) { - ret = OB_ERR_UNEXPECTED; - TRANS_LOG(ERROR, "get trans node create_arg fail for ObDmlFlag::DF_INSERT", KR(ret), K(dml_flag)); - } else { - ret = create_arg_.assign(*create_arg); - } - } else if (ObDmlFlag::DF_DELETE == dml_flag){ - if (OB_ISNULL(remove_arg)) { - ret = OB_ERR_UNEXPECTED; - TRANS_LOG(ERROR, "get trans node create_arg fail for ObDmlFlag::DF_DELETE", KR(ret), K(dml_flag)); - } else { - ret = remove_arg_.assign(*remove_arg); - } - } else { - ret = OB_ERR_UNEXPECTED; - TRANS_LOG(ERROR, "unexpected dml type", KR(ret), K(dml_flag)); - } - - return ret; -} - -int ObLsmtMutatorRow::copy( uint64_t &table_id, - int64_t &table_version, - common::ObTabletID &primary_row_id, - blocksstable::ObDmlFlag &dml_flag, - obrpc::ObBatchCreateTabletArg &create_arg, - obrpc::ObBatchRemoveTabletArg &remove_arg) const -{ - int ret = OB_SUCCESS; - table_id = table_id_; - table_version = table_version_; - dml_flag = dml_flag_; - primary_row_id = primary_row_id_; - if (OB_FAIL(create_arg.assign(create_arg_))) { - TRANS_LOG(WARN, "create_arg.assign failed", KR(ret), K(create_arg), K(dml_flag_)); - } else if (OB_FAIL(remove_arg.assign(remove_arg_))) { - TRANS_LOG(WARN, "remove_arg.assign failed", KR(ret), K(remove_arg), K(dml_flag_)); - } - return ret; -} - -void ObLsmtMutatorRow::reset() -{ - ObMutator::reset(); - table_id_ = 0; - dml_flag_ = ObDmlFlag::DF_NOT_EXIST; - primary_row_id_.reset(); - table_version_ = OB_INVALID_VERSION; - create_arg_.reset(); - remove_arg_.reset(); -} - -int ObLsmtMutatorRow::serialize(char *buf, const int64_t buf_len, int64_t &pos, - const bool is_big_row) -{ - UNUSED(is_big_row); - int ret = OB_SUCCESS; - int64_t new_pos = pos + encoded_length_i32(0); - int64_t data_pos = new_pos + encoded_length_vi64(table_id_); - TRANS_LOG(INFO, "ObLsmtMutatorRow::serialize"); - if (OB_ISNULL(buf) || pos < 0 || pos > buf_len) { - ret = OB_INVALID_ARGUMENT; - TRANS_LOG(WARN, "Invalid param", KP(buf), K(buf_len), K(pos)); - } else if (OB_FAIL(encode_vi64(buf, buf_len, new_pos, table_id_))) { - TRANS_LOG(WARN, "serialize table id failed", K(ret), KP(buf), - K(buf_len), K(pos)); - } else if ( OB_FAIL(encode_vi64(buf, buf_len, new_pos, table_version_)) - || OB_FAIL(encode_vi64(buf, buf_len, new_pos, primary_row_id_.id())) - || OB_FAIL(encode_i8(buf, buf_len, new_pos, dml_flag_)) - // We will serialize both create_arg_ and remove_arg_ without check dml_type_ - || OB_FAIL(create_arg_.serialize(buf, buf_len, new_pos)) - || OB_FAIL(remove_arg_.serialize(buf, buf_len, new_pos)) - ){ - if (OB_BUF_NOT_ENOUGH != ret || buf_len > common::OB_MAX_LOG_ALLOWED_SIZE) { - TRANS_LOG(INFO, "serialize row fail", K(ret), KP(buf), - K(buf_len), K(pos)); - } - } else { - TRANS_LOG(DEBUG, "serialize ok", K(dml_flag_), K(pos)); - } - - if (OB_SUCC(ret)) { - row_size_ = (uint32_t)(new_pos - pos); - if (OB_FAIL(encode_i32(buf, buf_len, pos, row_size_))) { - TRANS_LOG(WARN, "ObLsmtMutatorRow::serialize row fail", K(ret), K(buf_len), - K(pos), K(table_id_)); - } else { - pos = new_pos; - } - } - return ret; -} - -int ObLsmtMutatorRow::deserialize(const char *buf, const int64_t buf_len, int64_t &pos, - const bool is_big_row) -{ - UNUSED(is_big_row); - int ret = OB_SUCCESS; - int64_t new_pos = pos; - int64_t primary_row_id; - if (OB_ISNULL(buf) || pos < 0 || pos > buf_len) { - ret = OB_INVALID_ARGUMENT; - } else if (OB_FAIL(decode_i32(buf, buf_len, new_pos, - (int32_t *)&row_size_))) { - TRANS_LOG(WARN, "deserialize encrypted length fail", K(ret), - K(buf_len), K(new_pos)); - } else if (pos + row_size_ > buf_len) { - ret = OB_ERR_UNEXPECTED; - TRANS_LOG(ERROR, "size overflow", K(ret), KP(buf), K(buf_len), - K(pos), K_(row_size)); - } else if (OB_FAIL(decode_vi64(buf, buf_len, new_pos, (int64_t *)&table_id_))) { - TRANS_LOG(WARN, "deserialize table_id_ failed", K(ret), K(buf_len), K(new_pos)); - } else if (OB_FAIL(decode_vi64(buf, buf_len, new_pos, (int64_t *)&table_version_))) { - TRANS_LOG(WARN, "deserialize table_version_ failed", K(ret), K(buf_len), K(new_pos)); - } else if (OB_FAIL(decode_vi64(buf, buf_len, new_pos, (int64_t *)&primary_row_id))) { - TRANS_LOG(WARN, "deserialize primary_row_id_ failed", K(ret), K(buf_len), K(new_pos)); - } else if (OB_FALSE_IT(primary_row_id_ = primary_row_id)) { - TRANS_LOG(WARN, "deserialize dml_type_ failed", K(ret), K(buf_len), K(new_pos)); - } else if (OB_FAIL(decode_i8(buf, buf_len, new_pos, (int8_t *)&dml_flag_))) { - TRANS_LOG(WARN, "deserialize dml_type_ failed", K(ret), K(buf_len), K(new_pos)); - } else if (OB_FAIL(create_arg_.deserialize(buf, buf_len, new_pos))){ - TRANS_LOG(WARN, "deserialize create_arg_ fail", KR(ret), K(table_id_), K(pos), - K(new_pos), K(row_size_), K(buf_len)); - } else if (OB_FAIL(remove_arg_.deserialize(buf, buf_len, new_pos))){ - TRANS_LOG(WARN, "deserialize remove_arg_ fail", KR(ret), K(table_id_), K(pos), - K(new_pos), K(row_size_), K(buf_len)); - } else { - TRANS_LOG(DEBUG, "ObLsmtMutatorRow::deserialize ok", K(dml_flag_), K(pos)); - } - - if(OB_SUCC(ret)) { - pos += row_size_; - } - return ret; -} - //////////////////////////////////////////////////////////////////////////////////////////////////// ObMutatorWriter::ObMutatorWriter() {} diff --git a/src/storage/memtable/ob_memtable_mutator.h b/src/storage/memtable/ob_memtable_mutator.h index 51be074b61..151f48e9fc 100644 --- a/src/storage/memtable/ob_memtable_mutator.h +++ b/src/storage/memtable/ob_memtable_mutator.h @@ -41,7 +41,6 @@ class ObTabletID; namespace memtable { -class ObLsmtMutatorRow; struct RedoDataNode; struct TableLockRedoDataNode; @@ -276,41 +275,6 @@ public: int64_t create_schema_version_; }; -class ObLsmtMutatorRow : public memtable::ObMutator -{ -public: - ObLsmtMutatorRow() {} - virtual ~ObLsmtMutatorRow(){}; - // set the trans data - int set( const uint64_t table_id, - const int64_t table_version, - const common::ObTabletID primary_row_id, - const blocksstable::ObDmlFlag dml_flag, - const obrpc::ObBatchCreateTabletArg * create_arg, - const obrpc::ObBatchRemoveTabletArg * remove_arg); - void reset(); - // copy the data out of this object - int copy(uint64_t &table_id, - int64_t &table_version, - common::ObTabletID &primary_row_id, - blocksstable::ObDmlFlag &dml_flag, - obrpc::ObBatchCreateTabletArg &create_arg, - obrpc::ObBatchRemoveTabletArg &remove_arg) const; - // serialize this object to clog - int serialize(char *buf, const int64_t buf_len, int64_t &pos, - const bool is_big_row = false); - // serialize this object from clog - virtual int deserialize(const char *buf, const int64_t data_len, int64_t &pos, - const bool is_big_row = false); - VIRTUAL_TO_STRING_KV(K(table_id_), K(table_version_), K(primary_row_id_), - K(dml_flag_), K(create_arg_), K(remove_arg_)); -public: - common::ObTabletID primary_row_id_; //record the primary row for the trans - blocksstable::ObDmlFlag dml_flag_; //ObDmlFlag::DF_INSERT:DF_DELETE; - obrpc::ObBatchCreateTabletArg create_arg_; //batch create args - obrpc::ObBatchRemoveTabletArg remove_arg_; //batch remove args -}; - class ObMutatorWriter { public: @@ -370,7 +334,6 @@ public: const ObMutatorRowHeader &get_row_head(); const ObMemtableMutatorRow &get_mutator_row(); const ObMutatorTableLock &get_table_lock_row(); - const ObLsmtMutatorRow &get_ls_mt_row(); TO_STRING_KV(K_(meta),K(buf_.get_position()),K(buf_.get_limit())); private: diff --git a/src/storage/ob_storage_schema.cpp b/src/storage/ob_storage_schema.cpp index 1d5f6691e8..6ed5e3c28c 100644 --- a/src/storage/ob_storage_schema.cpp +++ b/src/storage/ob_storage_schema.cpp @@ -430,7 +430,7 @@ int ObStorageSchema::init( STORAGE_LOG(WARN, "failed to generate column array", K(ret), K(input_schema)); } else if (OB_FAIL(generate_column_group_array(input_schema, allocator))) { STORAGE_LOG(WARN, "Failed to generate column group array", K(ret)); - } else if (OB_UNLIKELY(!is_valid())) { + } else if (OB_UNLIKELY(!ObStorageSchema::is_valid())) { ret = OB_ERR_UNEXPECTED; STORAGE_LOG(ERROR, "storage schema is invalid", K(ret)); } else { @@ -1588,5 +1588,73 @@ void ObStorageSchema::update_column_cnt(const int64_t input_col_cnt) } } +int ObCreateTabletSchema::serialize(char *buf, const int64_t buf_len, int64_t &pos) const +{ + int ret = OB_SUCCESS; + BASE_SER((, ObStorageSchema)); + LST_DO_CODE(OB_UNIS_ENCODE, + table_id_, + index_status_, + truncate_version_); + return ret; +} + +int ObCreateTabletSchema::deserialize(common::ObIAllocator &allocator, const char *buf, const int64_t data_len, int64_t &pos) +{ + int ret = OB_SUCCESS; + if (OB_FAIL(ObStorageSchema::deserialize(allocator, buf, data_len, pos))) { + STORAGE_LOG(WARN, "failed to deserialize", KR(ret)); + } else { + LST_DO_CODE(OB_UNIS_DECODE, + table_id_, + index_status_, + truncate_version_); + } + return ret; +} + +int64_t ObCreateTabletSchema::get_serialize_size() const +{ + int64_t len = ObStorageSchema::get_serialize_size(); + LST_DO_CODE(OB_UNIS_ADD_LEN, + table_id_, + index_status_, + truncate_version_); + return len; +} + +int ObCreateTabletSchema::init( + common::ObIAllocator &allocator, + const share::schema::ObTableSchema &input_schema, + const lib::Worker::CompatMode compat_mode, + const bool skip_column_info, + const int64_t compat_version) +{ + int ret = OB_SUCCESS; + if (OB_FAIL(ObStorageSchema::init(allocator, input_schema, compat_mode, skip_column_info, compat_version))) { + STORAGE_LOG(WARN, "failed to init", K(ret), KPC(this)); + } else { + table_id_ = input_schema.get_table_id(); + index_status_ = input_schema.get_index_status(); + truncate_version_ = input_schema.get_truncate_version(); + } + return ret; +} + +int ObCreateTabletSchema::init( + common::ObIAllocator &allocator, + const ObCreateTabletSchema &old_schema) +{ + int ret = OB_SUCCESS; + if (OB_FAIL(ObStorageSchema::init(allocator, old_schema))) { + STORAGE_LOG(WARN, "failed to init", K(ret), KPC(this)); + } else { + table_id_ = old_schema.get_table_id(); + index_status_ = old_schema.get_index_status(); + truncate_version_ = old_schema.get_truncate_version(); + } + return ret; +} + } // namespace storage } // namespace oceanbase diff --git a/src/storage/ob_storage_schema.h b/src/storage/ob_storage_schema.h index 4613165604..b6124dcd83 100644 --- a/src/storage/ob_storage_schema.h +++ b/src/storage/ob_storage_schema.h @@ -152,7 +152,6 @@ public: uint16_t *column_idxs_; //free the memory with the allocator outside }; - class ObStorageSchema : public share::schema::ObMergeSchema { public: @@ -257,6 +256,10 @@ public: || column_group_array_.count() < input_schema.column_group_array_.count(); } + inline bool is_aux_lob_meta_table() const { return share::schema::is_aux_lob_meta_table(table_type_); } + inline bool is_aux_lob_piece_table() const { return share::schema::is_aux_lob_piece_table(table_type_); } + OB_INLINE bool is_user_hidden_table() const { return share::schema::TABLE_STATE_IS_HIDDEN_MASK & table_mode_.state_flag_; } + VIRTUAL_TO_STRING_KV(KP(this), K_(storage_schema_version), K_(version), K_(is_use_bloomfilter), K_(column_info_simplified), K_(compat_mode), K_(table_type), K_(index_type), K_(index_status), K_(row_store_type), K_(schema_version), @@ -331,6 +334,7 @@ public: share::schema::ObTableMode table_mode_; share::schema::ObIndexType index_type_; share::schema::ObIndexStatus index_status_; + ObRowStoreType row_store_type_; int64_t schema_version_; int64_t column_cnt_; // include virtual generated column @@ -354,6 +358,47 @@ private: DISALLOW_COPY_AND_ASSIGN(ObStorageSchema); }; +class ObCreateTabletSchema : public ObStorageSchema +{ +public: + ObCreateTabletSchema() + : ObStorageSchema(), + table_id_(common::OB_INVALID_ID), + index_status_(share::schema::ObIndexStatus::INDEX_STATUS_UNAVAILABLE), + truncate_version_(OB_INVALID_VERSION) + {} + + int serialize(char *buf, const int64_t buf_len, int64_t &pos) const; + int deserialize(common::ObIAllocator &allocator, const char *buf, const int64_t data_len, int64_t &pos); + int64_t get_serialize_size() const; + + inline bool can_read_index() const + { return share::schema::INDEX_STATUS_AVAILABLE == index_status_; } + uint64_t get_table_id () const + { return table_id_; } + int64_t get_truncate_version() const + { return truncate_version_; } + bool is_valid() const + { + return ObStorageSchema::is_valid() && common::OB_INVALID_ID != table_id_; + } + int init(common::ObIAllocator &allocator, + const share::schema::ObTableSchema &input_schema, + const lib::Worker::CompatMode compat_mode, + const bool skip_column_info, + const int64_t compat_version); + int init(common::ObIAllocator &allocator, + const ObCreateTabletSchema &old_schema); + INHERIT_TO_STRING_KV("ObStorageSchema", ObStorageSchema, K_(table_id), K_(index_status), K_(truncate_version)); +private: + // for cdc + uint64_t table_id_; + // for create index + share::schema::ObIndexStatus index_status_; + // for tablet throttling + int64_t truncate_version_; +}; + template int ObStorageSchema::serialize_schema_array( char *buf, const int64_t data_len, int64_t &pos, const common::ObIArray &array) const diff --git a/src/storage/tablet/ob_tablet.cpp b/src/storage/tablet/ob_tablet.cpp index e7247e50d6..fc66e482ad 100644 --- a/src/storage/tablet/ob_tablet.cpp +++ b/src/storage/tablet/ob_tablet.cpp @@ -275,6 +275,106 @@ void ObTablet::reset() is_inited_ = false; } +int ObTablet::init_for_first_time_creation( + common::ObArenaAllocator &allocator, + const share::ObLSID &ls_id, + const common::ObTabletID &tablet_id, + const common::ObTabletID &data_tablet_id, + const share::SCN &create_scn, + const int64_t snapshot_version, + const ObStorageSchema &storage_schema, + const bool need_empty_major_table, + ObFreezer *freezer) +{ + int ret = OB_SUCCESS; + const lib::Worker::CompatMode compat_mode = storage_schema.get_compat_mode(); + const int64_t default_max_sync_medium_scn = 0; + ObTableHandleV2 table_handle; + ObTabletTableStoreFlag table_store_flag; + if (need_empty_major_table) { + table_store_flag.set_with_major_sstable(); + } else { + table_store_flag.set_without_major_sstable(); + } + ObITable **ddl_kvs_addr = nullptr; + int64_t ddl_kv_count = 0; + + if (OB_UNLIKELY(is_inited_)) { + ret = OB_INIT_TWICE; + LOG_WARN("init twice", K(ret), K(is_inited_)); + } else if (OB_UNLIKELY(!ls_id.is_valid()) + || OB_UNLIKELY(!tablet_id.is_valid()) + || OB_UNLIKELY(!data_tablet_id.is_valid()) + //|| OB_UNLIKELY(create_scn <= OB_INVALID_TIMESTAMP) + || OB_UNLIKELY(OB_INVALID_VERSION == snapshot_version) + || OB_UNLIKELY(!storage_schema.is_valid()) + || OB_UNLIKELY(lib::Worker::CompatMode::INVALID == compat_mode) + || OB_ISNULL(freezer)) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid args", K(ret), K(ls_id), K(tablet_id), K(data_tablet_id), + K(create_scn), K(snapshot_version), K(storage_schema), K(compat_mode), KP(freezer)); + } else if (OB_UNLIKELY(!pointer_hdl_.is_valid()) + || OB_ISNULL(memtable_mgr_) + || OB_ISNULL(log_handler_)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("tablet pointer handle is invalid", K(ret), K_(pointer_hdl), K_(memtable_mgr), K_(log_handler)); + } else if (OB_FAIL(init_shared_params(ls_id, tablet_id, storage_schema.get_schema_version(), + default_max_sync_medium_scn, compat_mode, freezer))) { + LOG_WARN("failed to init shared params", K(ret), K(ls_id), K(tablet_id), K(compat_mode), KP(freezer)); + } else if (OB_FAIL(tablet_meta_.init(ls_id, tablet_id, data_tablet_id, + create_scn, snapshot_version, compat_mode, table_store_flag, storage_schema.get_schema_version()/*create_schema_version*/))) { + LOG_WARN("failed to init tablet meta", K(ret), K(ls_id), K(tablet_id), K(data_tablet_id), + K(create_scn), K(snapshot_version), K(compat_mode), K(table_store_flag)); + } else if (is_ls_inner_tablet() && OB_FAIL(inner_create_memtable())) { + LOG_WARN("failed to create first memtable", K(ret), K(tablet_id)); + } else if (OB_FAIL(pull_memtables(allocator, ddl_kvs_addr, ddl_kv_count))) { + LOG_WARN("fail to pull memtable", K(ret)); + } else { + ddl_kvs_ = ddl_kvs_addr; + ddl_kv_count_ = ddl_kv_count; + if (OB_FAIL(ObTabletObjLoadHelper::alloc_and_new(allocator, storage_schema_addr_.ptr_))) { + LOG_WARN("fail to allocate and new object", K(ret)); + } else if (OB_FAIL(storage_schema_addr_.get_ptr()->init(allocator, storage_schema))) { + LOG_WARN("fail to initialize tablet member", K(ret), K(storage_schema_addr_)); + } + } + if (OB_FAIL(ret)) { + } else if (need_empty_major_table + && OB_FAIL(ObTabletCreateDeleteHelper::create_empty_sstable( + allocator, *storage_schema_addr_.get_ptr(), tablet_id, snapshot_version, table_handle))) { + LOG_WARN("failed to make empty co sstable", K(ret), K(snapshot_version)); + } else { + ALLOC_AND_INIT(allocator, table_store_addr_, (*this), static_cast(table_handle.get_table())); + } + + if (OB_FAIL(ret)) { + } else if (OB_FAIL(table_store_cache_.init(table_store_addr_.get_ptr()->get_major_sstables(), + table_store_addr_.get_ptr()->get_minor_sstables(), + storage_schema.is_row_store()))) { + LOG_WARN("failed to init table store cache", K(ret), KPC(this)); + } else if (OB_FAIL(check_sstable_column_checksum())) { + LOG_WARN("failed to check sstable column checksum", K(ret), KPC(this)); + } else if (OB_FAIL(build_read_info(allocator))) { + LOG_WARN("failed to build read info", K(ret)); + } else if (!is_ls_inner_tablet() && OB_FAIL(mds_data_.init_for_first_creation(allocator))) { + LOG_WARN("failed to init mds data", K(ret)); + } else if (is_ls_inner_tablet() && OB_FAIL(mds_data_.init_with_tablet_status(allocator, ObTabletStatus::NORMAL, ObTabletMdsUserDataType::CREATE_TABLET))) { + LOG_WARN("failed to init mds data for ls inner tablet", K(ret)); + } else if (FALSE_IT(set_mem_addr())) { + } else if (OB_FAIL(inner_inc_macro_ref_cnt())) { + LOG_WARN("failed to increase macro ref cnt", K(ret)); + } else { + is_inited_ = true; + LOG_INFO("succeeded to init tablet for first time creation", K(ret), K(*this)); + } + + if (OB_UNLIKELY(!is_inited_)) { + reset(); + } + + return ret; +} + int ObTablet::init_for_first_time_creation( common::ObArenaAllocator &allocator, const share::ObLSID &ls_id, diff --git a/src/storage/tablet/ob_tablet.h b/src/storage/tablet/ob_tablet.h index c2a83a90b3..3fc8b382f4 100644 --- a/src/storage/tablet/ob_tablet.h +++ b/src/storage/tablet/ob_tablet.h @@ -190,6 +190,16 @@ public: const lib::Worker::CompatMode compat_mode, const bool need_empty_major_table, ObFreezer *freezer); + int init_for_first_time_creation( + common::ObArenaAllocator &allocator, + const share::ObLSID &ls_id, + const common::ObTabletID &tablet_id, + const common::ObTabletID &data_tablet_id, + const share::SCN &create_scn, + const int64_t snapshot_version, + const ObStorageSchema &storage_schema, + const bool need_empty_major_table, + ObFreezer *freezer); // dump/merge build new multi version tablet int init_for_merge( common::ObArenaAllocator &allocator, diff --git a/src/storage/tablet/ob_tablet_binding_helper.cpp b/src/storage/tablet/ob_tablet_binding_helper.cpp index 0f6799643c..8a5368bb29 100644 --- a/src/storage/tablet/ob_tablet_binding_helper.cpp +++ b/src/storage/tablet/ob_tablet_binding_helper.cpp @@ -135,16 +135,20 @@ int ObTabletBindingHelper::get_tablet_for_new_mds(const ObLS &ls, const ObTablet return ret; } -bool ObTabletBindingHelper::has_lob_tablets(const obrpc::ObBatchCreateTabletArg &arg, const obrpc::ObCreateTabletInfo &info) +int ObTabletBindingHelper::has_lob_tablets(const obrpc::ObBatchCreateTabletArg &arg, const obrpc::ObCreateTabletInfo &info, bool &has_lob) { - bool has_lob = false; - for (int64_t i = 0; !has_lob && i < info.tablet_ids_.count(); i++) { - const ObTableSchema &table_schema = arg.table_schemas_.at(info.table_schema_index_.at(i)); - if (table_schema.is_aux_lob_meta_table() || table_schema.is_aux_lob_piece_table()) { + int ret = OB_SUCCESS; + has_lob = false; + for (int64_t i = 0; OB_SUCC(ret) && !has_lob && i < info.tablet_ids_.count(); i++) { + const ObCreateTabletSchema *create_tablet_schema = arg.create_tablet_schemas_.at(info.table_schema_index_.at(i)); + if (OB_ISNULL(create_tablet_schema)) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("storage is NULL", KR(ret), K(arg)); + } else if (create_tablet_schema->is_aux_lob_meta_table() || create_tablet_schema->is_aux_lob_piece_table()) { has_lob = true; } } - return has_lob; + return ret; } int ObTabletBindingHelper::modify_tablet_binding_for_new_mds_create(const ObBatchCreateTabletArg &arg, const share::SCN &replay_scn, mds::BufferCtx &ctx) @@ -157,13 +161,16 @@ int ObTabletBindingHelper::modify_tablet_binding_for_new_mds_create(const ObBatc } else { const ObArray empty_array; ObLS &ls = *ls_handle.get_ls(); + bool has_lob = false; for (int64_t i = 0; OB_SUCC(ret) && i < arg.tablets_.count(); i++) { const ObCreateTabletInfo &info = arg.tablets_[i]; if (ObTabletCreateDeleteHelper::is_pure_hidden_tablets(info)) { if (CLICK_FAIL(bind_hidden_tablet_to_orig_tablet(ls, info, replay_scn, ctx, arg.is_old_mds_))) { LOG_WARN("failed to add hidden tablet", K(ret)); } - } else if (ObTabletBindingHelper::has_lob_tablets(arg, info)) { + } else if (OB_FAIL(ObTabletBindingHelper::has_lob_tablets(arg, info, has_lob))) { + LOG_WARN("failed to has_lob_tablets", KR(ret)); + } else if (has_lob) { if (CLICK_FAIL(bind_lob_tablet_to_data_tablet(ls, arg, info, replay_scn, ctx))) { LOG_WARN("failed to add lob tablet", K(ret)); } @@ -206,9 +213,13 @@ int ObTabletBindingHelper::bind_lob_tablet_to_data_tablet( for (int64_t i = 0; OB_SUCC(ret) && i < info.tablet_ids_.count(); i++) { const ObTabletID &tablet_id = info.tablet_ids_.at(i); if (tablet_id != data_tablet_id) { - if (arg.table_schemas_.at(info.table_schema_index_.at(i)).is_aux_lob_meta_table()) { + const ObCreateTabletSchema *create_tablet_schema = arg.create_tablet_schemas_.at(info.table_schema_index_.at(i)); + if (OB_ISNULL(create_tablet_schema)) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("storage is NULL", KR(ret), K(arg)); + } else if (create_tablet_schema->is_aux_lob_meta_table()) { data.lob_meta_tablet_id_ = tablet_id; - } else if (arg.table_schemas_.at(info.table_schema_index_.at(i)).is_aux_lob_piece_table()) { + } else if (create_tablet_schema->is_aux_lob_piece_table()) { data.lob_piece_tablet_id_ = tablet_id; } else { // do not maintain index tablet ids diff --git a/src/storage/tablet/ob_tablet_binding_helper.h b/src/storage/tablet/ob_tablet_binding_helper.h index 8b42116f5a..4f015f4359 100644 --- a/src/storage/tablet/ob_tablet_binding_helper.h +++ b/src/storage/tablet/ob_tablet_binding_helper.h @@ -92,7 +92,7 @@ public: // common template static int modify_tablet_binding_new_mds(ObLS &ls, const ObTabletID &tablet_id, const share::SCN &replay_scn, mds::BufferCtx &ctx, const bool for_old_mds, F op); - static bool has_lob_tablets(const obrpc::ObBatchCreateTabletArg &arg, const obrpc::ObCreateTabletInfo &info); + static int has_lob_tablets(const obrpc::ObBatchCreateTabletArg &arg, const obrpc::ObCreateTabletInfo &info, bool &has_lob); static int get_ls(const share::ObLSID &ls_id, ObLSHandle &ls_handle); private: const ObLS &ls_; diff --git a/src/storage/tablet/ob_tablet_create_delete_helper.cpp b/src/storage/tablet/ob_tablet_create_delete_helper.cpp index 4b05b2a8da..718c27e87b 100644 --- a/src/storage/tablet/ob_tablet_create_delete_helper.cpp +++ b/src/storage/tablet/ob_tablet_create_delete_helper.cpp @@ -628,6 +628,22 @@ bool ObTabletCreateDeleteHelper::is_pure_hidden_tablets(const ObCreateTabletInfo return tablet_ids.count() >= 1 && !is_contain(tablet_ids, data_tablet_id) && info.is_create_bind_hidden_tablets_; } +int ObTabletCreateDeleteHelper::check_need_create_empty_major_sstable( + const ObCreateTabletSchema &create_table_schema, + bool &need_create_sstable) +{ + int ret = OB_SUCCESS; + need_create_sstable = false; + if (OB_UNLIKELY(!create_table_schema.is_valid())) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid args", K(ret), K(create_table_schema)); + } else { + need_create_sstable = !(create_table_schema.is_user_hidden_table() + || (create_table_schema.is_index_table() && !create_table_schema.can_read_index())); + } + return ret; +} + int ObTabletCreateDeleteHelper::check_need_create_empty_major_sstable( const ObTableSchema &table_schema, bool &need_create_sstable) diff --git a/src/storage/tablet/ob_tablet_create_delete_helper.h b/src/storage/tablet/ob_tablet_create_delete_helper.h index 944da58f4d..f50872731d 100644 --- a/src/storage/tablet/ob_tablet_create_delete_helper.h +++ b/src/storage/tablet/ob_tablet_create_delete_helper.h @@ -133,7 +133,10 @@ public: const ObTabletMapKey &key, ObTabletHandle &handle); static int check_need_create_empty_major_sstable( - const share::schema::ObTableSchema &table_schema, + const ObCreateTabletSchema &create_tablet_schema, + bool &need_create_sstable); + static int check_need_create_empty_major_sstable( + const ObTableSchema &table_schema, bool &need_create_sstable); // Attention !!! only used when first creating tablet static int create_empty_sstable( diff --git a/src/storage/tablet/ob_tablet_create_mds_helper.cpp b/src/storage/tablet/ob_tablet_create_mds_helper.cpp index 7562235763..6d6c11f5b0 100644 --- a/src/storage/tablet/ob_tablet_create_mds_helper.cpp +++ b/src/storage/tablet/ob_tablet_create_mds_helper.cpp @@ -105,6 +105,8 @@ int ObTabletCreateMdsHelper::on_register( } else if (arg.is_old_mds_) { ret = OB_ERR_UNEXPECTED; LOG_WARN("unexpected error, arg is old mds", K(ret), K(arg)); + } else if (OB_FAIL(convert_schemas(arg))) { + LOG_WARN("failed to convert_schemas", K(ret), "arg", PRETTY_ARG(arg)); } else if (CLICK_FAIL(check_create_new_tablets(arg, false/*is_replay*/))) { LOG_WARN("failed to check crate new tablets", K(ret), "arg", PRETTY_ARG(arg)); } else if (CLICK_FAIL(register_process(arg, ctx))) { @@ -178,6 +180,8 @@ int ObTabletCreateMdsHelper::on_replay( LOG_WARN("arg is invalid", K(ret), "arg", PRETTY_ARG(arg)); } else if (arg.is_old_mds_) { LOG_INFO("skip replay create tablet for old mds", K(ret), K(scn), "arg", PRETTY_ARG(arg)); + } else if (OB_FAIL(convert_schemas(arg))) { + LOG_WARN("failed to convert_schemas", K(ret), "arg", PRETTY_ARG(arg)); } else { // Should not fail the replay process when tablet count excceed recommended value // Only print ERROR log to notice user scale up the unit memory @@ -247,16 +251,17 @@ int ObTabletCreateMdsHelper::check_create_new_tablets(const obrpc::ObBatchCreate int ret = OB_SUCCESS; bool skip_check = !arg.need_check_tablet_cnt_; bool is_truncate = false; - // skip hidden tablet creation - for (int64_t i = 0; OB_SUCC(ret) && !skip_check && i < arg.table_schemas_.count(); ++i) { - if (arg.table_schemas_[i].is_user_hidden_table()) { + for (int64_t i = 0; OB_SUCC(ret) && !skip_check && i < arg.create_tablet_schemas_.count(); ++i) { + if (OB_ISNULL(arg.create_tablet_schemas_[i])) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid args", KR(ret), K(i), K(arg)); + } else if (arg.create_tablet_schemas_[i]->is_user_hidden_table()) { skip_check = true; - } else if (OB_INVALID_VERSION != arg.table_schemas_[i].get_truncate_version()) { + } else if (OB_INVALID_VERSION != arg.create_tablet_schemas_[i]->get_truncate_version()) { is_truncate = true; } } - if (OB_FAIL(ret)) { } else if (skip_check) { } else if (is_truncate) { @@ -560,6 +565,37 @@ bool ObTabletCreateMdsHelper::find_aux_info_for_hidden_tablets( return found; } +int ObTabletCreateMdsHelper::convert_schemas( + obrpc::ObBatchCreateTabletArg &arg) +{ + int ret = OB_SUCCESS; + if (arg.create_tablet_schemas_.count() > 0) { + } + // compatibility with DATA_VERSION_4_1_0_0 + else if (arg.tablets_.count() <= 0) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid args", KR(ret), K(arg)); + } else { + lib::Worker::CompatMode compat_mode = arg.tablets_.at(0).compat_mode_; + for (int64_t i = 0; OB_SUCC(ret) && i < arg.table_schemas_.count(); ++i) { + ObTableSchema &table_schema = arg.table_schemas_[i]; + ObCreateTabletSchema *create_tablet_schema = NULL; + void *create_tablet_schema_ptr = arg.allocator_.alloc(sizeof(ObCreateTabletSchema)); + if (OB_ISNULL(create_tablet_schema_ptr)) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_WARN("failed to allocate storage schema", KR(ret), K(table_schema)); + } else if (FALSE_IT(create_tablet_schema = new (create_tablet_schema_ptr)ObCreateTabletSchema())) { + } else if (OB_FAIL(create_tablet_schema->init(arg.allocator_, table_schema, compat_mode, + false/*skip_column_info*/, ObCreateTabletSchema::STORAGE_SCHEMA_VERSION_V3))) { + LOG_WARN("failed to init storage schema", KR(ret), K(table_schema)); + } else if (OB_FAIL(arg.create_tablet_schemas_.push_back(create_tablet_schema))) { + LOG_WARN("failed to push back table schema", KR(ret), K(create_tablet_schema)); + } + } + } + return ret; +} + int ObTabletCreateMdsHelper::build_pure_data_tablet( const obrpc::ObBatchCreateTabletArg &arg, const obrpc::ObCreateTabletInfo &info, @@ -572,7 +608,7 @@ int ObTabletCreateMdsHelper::build_pure_data_tablet( int ret = OB_SUCCESS; const ObLSID &ls_id = arg.id_; const ObTabletID &data_tablet_id = info.data_tablet_id_; - const ObSArray &table_schemas = arg.table_schemas_; + const ObSArray &create_tablet_schemas = arg.create_tablet_schemas_; const lib::Worker::CompatMode &compat_mode = info.compat_mode_; const int64_t snapshot_version = arg.major_frozen_scn_.get_val_for_tx(); ObTabletHandle tablet_handle; @@ -611,8 +647,11 @@ int ObTabletCreateMdsHelper::build_pure_data_tablet( LOG_WARN("ls is null", K(ret), K(ls_id), K(ls_handle)); } else if (CLICK_FAIL(tablet_id_array.push_back(data_tablet_id))) { LOG_WARN("failed to push back tablet id", K(ret), K(ls_id), K(data_tablet_id)); + } else if (OB_ISNULL(create_tablet_schemas[info.table_schema_index_[index]])) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid args", K(ret), K(info), K(arg)); } else if (CLICK_FAIL(ls->get_tablet_svr()->create_tablet(ls_id, data_tablet_id, data_tablet_id, - scn, snapshot_version, table_schemas[info.table_schema_index_[index]], compat_mode, + scn, snapshot_version, *create_tablet_schemas[info.table_schema_index_[index]], tablet_handle))) { LOG_WARN("failed to do create tablet", K(ret), K(ls_id), K(data_tablet_id), "arg", PRETTY_ARG(arg)); } @@ -638,7 +677,7 @@ int ObTabletCreateMdsHelper::build_mixed_tablets( const ObLSID &ls_id = arg.id_; const ObTabletID &data_tablet_id = info.data_tablet_id_; const ObSArray &tablet_ids = info.tablet_ids_; - const ObSArray &table_schemas = arg.table_schemas_; + const ObSArray &create_tablet_schemas = arg.create_tablet_schemas_; const lib::Worker::CompatMode &compat_mode = info.compat_mode_; const int64_t snapshot_version = arg.major_frozen_scn_.get_val_for_tx(); ObTabletHandle data_tablet_handle; @@ -660,14 +699,18 @@ int ObTabletCreateMdsHelper::build_mixed_tablets( MDS_TG(5_ms); exist = false; const ObTabletID &tablet_id = tablet_ids[i]; - const share::schema::ObTableSchema &table_schema = table_schemas[info.table_schema_index_[i]]; - if (table_schema.is_aux_lob_meta_table()) { + const ObCreateTabletSchema *create_tablet_schema = create_tablet_schemas[info.table_schema_index_[i]]; + if (OB_ISNULL(create_tablet_schema)) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid args", K(ret), K(info), K(i)); + } else if (create_tablet_schema->is_aux_lob_meta_table()) { lob_meta_tablet_id = tablet_id; - } else if (table_schema.is_aux_lob_piece_table()) { + } else if (create_tablet_schema->is_aux_lob_piece_table()) { lob_piece_tablet_id = tablet_id; } - if (for_replay) { + if (OB_FAIL(ret)) { + } else if (for_replay) { const ObTabletMapKey key(ls_id, tablet_id); if (CLICK_FAIL(ObTabletCreateDeleteHelper::get_tablet(key, tablet_handle))) { if (OB_TABLET_NOT_EXIST == ret) { @@ -681,13 +724,14 @@ int ObTabletCreateMdsHelper::build_mixed_tablets( } } + if (OB_FAIL(ret)) { } else if (for_replay && exist) { LOG_INFO("tablet already exists in replay procedure, skip it", K(ret), K(ls_id), K(tablet_id)); } else if (CLICK_FAIL(tablet_id_array.push_back(tablet_id))) { LOG_WARN("failed to push back tablet id", K(ret), K(ls_id), K(tablet_id)); } else if (CLICK_FAIL(ls->get_tablet_svr()->create_tablet(ls_id, tablet_id, data_tablet_id, - scn, snapshot_version, table_schema, compat_mode, tablet_handle))) { + scn, snapshot_version, *create_tablet_schema, tablet_handle))) { LOG_WARN("failed to do create tablet", K(ret), K(ls_id), K(tablet_id), K(data_tablet_id), "arg", PRETTY_ARG(arg)); } @@ -730,7 +774,7 @@ int ObTabletCreateMdsHelper::build_pure_aux_tablets( const ObLSID &ls_id = arg.id_; const ObTabletID &data_tablet_id = info.data_tablet_id_; const ObSArray &tablet_ids = info.tablet_ids_; - const ObSArray &table_schemas = arg.table_schemas_; + const ObSArray &create_tablet_schemas = arg.create_tablet_schemas_; const lib::Worker::CompatMode &compat_mode = info.compat_mode_; const int64_t snapshot_version = arg.major_frozen_scn_.get_val_for_tx(); ObTabletHandle tablet_handle; @@ -749,7 +793,7 @@ int ObTabletCreateMdsHelper::build_pure_aux_tablets( MDS_TG(5_ms); exist = false; const ObTabletID &tablet_id = tablet_ids[i]; - const share::schema::ObTableSchema &table_schema = table_schemas[info.table_schema_index_[i]]; + const ObCreateTabletSchema *create_tablet_schema = create_tablet_schemas[info.table_schema_index_[i]]; if (for_replay) { const ObTabletMapKey key(ls_id, tablet_id); @@ -771,8 +815,11 @@ int ObTabletCreateMdsHelper::build_pure_aux_tablets( K(ls_id), K(data_tablet_id), K(tablet_id)); } else if (CLICK_FAIL(tablet_id_array.push_back(tablet_id))) { LOG_WARN("failed to push back tablet id", K(ret), K(ls_id), K(tablet_id)); + } else if (OB_ISNULL(create_tablet_schema)) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid args", K(ret), K(info), K(i)); } else if (CLICK_FAIL(ls->get_tablet_svr()->create_tablet(ls_id, tablet_id, data_tablet_id, - scn, snapshot_version, table_schema, compat_mode, tablet_handle))) { + scn, snapshot_version, *create_tablet_schema, tablet_handle))) { LOG_WARN("failed to do create tablet", K(ret), K(ls_id), K(tablet_id), K(data_tablet_id), "arg", PRETTY_ARG(arg)); } @@ -800,7 +847,7 @@ int ObTabletCreateMdsHelper::build_hidden_tablets( const ObLSID &ls_id = arg.id_; const ObTabletID &data_tablet_id = info.data_tablet_id_; const ObSArray &tablet_ids = info.tablet_ids_; - const ObSArray &table_schemas = arg.table_schemas_; + const ObSArray &create_tablet_schemas = arg.create_tablet_schemas_; const lib::Worker::CompatMode &compat_mode = info.compat_mode_; const int64_t snapshot_version = arg.major_frozen_scn_.get_val_for_tx(); ObTabletHandle tablet_handle; @@ -824,22 +871,29 @@ int ObTabletCreateMdsHelper::build_hidden_tablets( lob_meta_tablet_id.reset(); lob_piece_tablet_id.reset(); const ObTabletID &tablet_id = tablet_ids[i]; - const share::schema::ObTableSchema &table_schema = table_schemas[info.table_schema_index_[i]]; + const ObCreateTabletSchema *create_tablet_schema = create_tablet_schemas[info.table_schema_index_[i]]; bool has_related_aux_info = find_aux_info_for_hidden_tablets(arg, tablet_id, aux_info_idx); - if (has_related_aux_info) { + if (OB_ISNULL(create_tablet_schema)) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid args", K(ret), K(info), K(i)); + } else if (has_related_aux_info) { const ObCreateTabletInfo &aux_info = arg.tablets_.at(aux_info_idx); for (int64_t j = 0; j < aux_info.tablet_ids_.count(); ++j) { const int64_t table_schema_index = aux_info.table_schema_index_.at(j); - const share::schema::ObTableSchema &aux_table_schema = table_schemas[table_schema_index]; - if (aux_table_schema.is_aux_lob_meta_table()) { + const ObCreateTabletSchema *aux_table_schema = create_tablet_schemas[table_schema_index]; + if (OB_ISNULL(aux_table_schema)) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid args", K(ret), K(j)); + } else if (aux_table_schema->is_aux_lob_meta_table()) { lob_meta_tablet_id = aux_info.tablet_ids_.at(j); - } else if (aux_table_schema.is_aux_lob_piece_table()) { + } else if (aux_table_schema->is_aux_lob_piece_table()) { lob_piece_tablet_id = aux_info.tablet_ids_.at(j); } } } - if (for_replay) { + if (OB_FAIL(ret)) { + } else if (for_replay) { const ObTabletMapKey key(ls_id, tablet_id); if (CLICK_FAIL(ObTabletCreateDeleteHelper::get_tablet(key, tablet_handle))) { if (OB_TABLET_NOT_EXIST == ret) { @@ -860,7 +914,7 @@ int ObTabletCreateMdsHelper::build_hidden_tablets( } else if (CLICK_FAIL(tablet_id_array.push_back(tablet_id))) { LOG_WARN("failed to push back tablet id", K(ret), K(ls_id), K(tablet_id)); } else if (CLICK_FAIL(ls->get_tablet_svr()->create_tablet(ls_id, tablet_id, data_tablet_id, - scn, snapshot_version, table_schema, compat_mode, tablet_handle))) { + scn, snapshot_version, *create_tablet_schema, tablet_handle))) { LOG_WARN("failed to do create tablet", K(ret), K(ls_id), K(tablet_id), K(data_tablet_id), "arg", PRETTY_ARG(arg)); } diff --git a/src/storage/tablet/ob_tablet_create_mds_helper.h b/src/storage/tablet/ob_tablet_create_mds_helper.h index befcb52f9e..f7e541eeff 100644 --- a/src/storage/tablet/ob_tablet_create_mds_helper.h +++ b/src/storage/tablet/ob_tablet_create_mds_helper.h @@ -155,6 +155,7 @@ private: mds::BufferCtx &ctx, const bool for_old_mds); static void handle_ret_for_replay(int &ret); + static int convert_schemas(obrpc::ObBatchCreateTabletArg &arg); }; } // namespace storage } // namespace oceanbase