Fixing core in the cast_obj function

This commit is contained in:
obdev
2023-03-10 15:40:48 +00:00
committed by ob-robot
parent 8e3eeb074b
commit dc2707cb42
3 changed files with 22 additions and 25 deletions

View File

@ -83,12 +83,11 @@ int ObTableLoadPartitionCalc::init(uint64_t tenant_id, uint64_t table_id)
if (OB_FAIL(OTTZ_MGR.get_tenant_tz(tenant_id, tz_info_.get_tz_map_wrap()))) { if (OB_FAIL(OTTZ_MGR.get_tenant_tz(tenant_id, tz_info_.get_tz_map_wrap()))) {
LOG_WARN("fail to get tenant time zone", KR(ret), K(tenant_id_)); LOG_WARN("fail to get tenant time zone", KR(ret), K(tenant_id_));
} else { } else {
ObSchemaGetterGuard schema_guard;
const ObTableSchema *table_schema = nullptr; const ObTableSchema *table_schema = nullptr;
ObDataTypeCastParams cast_params(&tz_info_); ObDataTypeCastParams cast_params(&tz_info_);
if (OB_FAIL(time_cvrt_.init(cast_params.get_nls_format(ObDateTimeType)))) { if (OB_FAIL(time_cvrt_.init(cast_params.get_nls_format(ObDateTimeType)))) {
LOG_WARN("fail to init time converter", KR(ret)); LOG_WARN("fail to init time converter", KR(ret));
} else if (OB_FAIL(ObTableLoadSchema::get_table_schema(tenant_id, table_id, schema_guard, } else if (OB_FAIL(ObTableLoadSchema::get_table_schema(tenant_id, table_id, schema_guard_,
table_schema))) { table_schema))) {
LOG_WARN("fail to get table schema", KR(ret), K(tenant_id), K(table_id)); LOG_WARN("fail to get table schema", KR(ret), K(tenant_id), K(table_id));
} else { } else {
@ -102,11 +101,11 @@ int ObTableLoadPartitionCalc::init(uint64_t tenant_id, uint64_t table_id)
exec_ctx_.set_sql_ctx(&sql_ctx_); exec_ctx_.set_sql_ctx(&sql_ctx_);
// 初始化table_location_ // 初始化table_location_
if (OB_FAIL( if (OB_FAIL(
table_location_.init_partition_ids_by_rowkey2(exec_ctx_, session(), schema_guard, table_id))) { table_location_.init_partition_ids_by_rowkey2(exec_ctx_, session(), schema_guard_, table_id))) {
LOG_WARN("fail to init table location", KR(ret)); LOG_WARN("fail to init table location", KR(ret));
} }
// 获取rowkey_obj_index_ // 获取part_key_obj_index_
else if (OB_FAIL(init_rowkey_index(table_schema, allocator_))) { else if (OB_FAIL(init_part_key_index(table_schema, allocator_))) {
LOG_WARN("fail to get rowkey index", KR(ret)); LOG_WARN("fail to get rowkey index", KR(ret));
} }
} }
@ -122,7 +121,7 @@ int ObTableLoadPartitionCalc::init(uint64_t tenant_id, uint64_t table_id)
return ret; return ret;
} }
int ObTableLoadPartitionCalc::init_rowkey_index(const ObTableSchema *table_schema, int ObTableLoadPartitionCalc::init_part_key_index(const ObTableSchema *table_schema,
ObIAllocator &allocator) ObIAllocator &allocator)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
@ -146,7 +145,7 @@ int ObTableLoadPartitionCalc::init_rowkey_index(const ObTableSchema *table_schem
} }
} }
if (OB_SUCC(ret)) { if (OB_SUCC(ret)) {
if (OB_FAIL(rowkey_obj_index_.create(part_key_num, allocator))) { if (OB_FAIL(part_key_obj_index_.create(part_key_num, allocator))) {
LOG_WARN("fail to create", KR(ret)); LOG_WARN("fail to create", KR(ret));
} }
} }
@ -159,29 +158,29 @@ int ObTableLoadPartitionCalc::init_rowkey_index(const ObTableSchema *table_schem
int64_t sub_part_key_pos = column_schema->get_subpart_key_pos(); int64_t sub_part_key_pos = column_schema->get_subpart_key_pos();
if (part_key_pos > 0 || sub_part_key_pos > 0) { if (part_key_pos > 0 || sub_part_key_pos > 0) {
pos ++; pos ++;
if (OB_UNLIKELY(pos > rowkey_obj_index_.count())) { if (OB_UNLIKELY(pos > part_key_obj_index_.count())) {
ret = OB_ERR_UNEXPECTED; ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected rowkey position", KR(ret), KPC(column_schema), K(pos)); LOG_WARN("unexpected rowkey position", KR(ret), KPC(column_schema), K(pos));
} else { } else {
if (table_schema->is_heap_table()) { if (table_schema->is_heap_table()) {
abort_unless(i > 0); abort_unless(i > 0);
rowkey_obj_index_[pos - 1].index_ = i - 1; part_key_obj_index_[pos - 1].index_ = i - 1;
} else { } else {
rowkey_obj_index_[pos - 1].index_ = i; part_key_obj_index_[pos - 1].index_ = i;
if (column_schema->is_tbl_part_key_column() && if (column_schema->is_tbl_part_key_column() &&
(column_schema->is_identity_column() || column_schema->is_autoincrement())) { (column_schema->is_identity_column() || column_schema->is_autoincrement())) {
is_partition_with_autoinc_ = true; is_partition_with_autoinc_ = true;
partition_with_autoinc_idx_ = pos - 1; partition_with_autoinc_idx_ = pos - 1;
} }
} }
rowkey_obj_index_[pos - 1].column_schema_ = column_schema; part_key_obj_index_[pos - 1].column_schema_ = column_schema;
} }
} }
} }
return ret; return ret;
} }
int ObTableLoadPartitionCalc::calc(ObTableLoadPartitionCalcContext &ctx) const int ObTableLoadPartitionCalc::calc(ObTableLoadPartitionCalcContext &ctx)
{ {
OB_TABLE_LOAD_STATISTICS_TIME_COST(calc_part_time_us); OB_TABLE_LOAD_STATISTICS_TIME_COST(calc_part_time_us);
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
@ -230,7 +229,7 @@ int ObTableLoadPartitionCalc::get_row(ObTableLoadPartitionCalcContext &ctx, cons
ObIAllocator &allocator) const ObIAllocator &allocator) const
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
const int64_t rowkey_obj_count = rowkey_obj_index_.count(); const int64_t rowkey_obj_count = part_key_obj_index_.count();
ObObj *rowkey_objs = static_cast<ObObj *>(allocator.alloc(sizeof(ObObj) * rowkey_obj_count)); ObObj *rowkey_objs = static_cast<ObObj *>(allocator.alloc(sizeof(ObObj) * rowkey_obj_count));
ObDataTypeCastParams cast_params(&tz_info_); ObDataTypeCastParams cast_params(&tz_info_);
ObCastCtx cast_ctx(&allocator, &cast_params, CM_NONE, ObCharset::get_system_collation()); ObCastCtx cast_ctx(&allocator, &cast_params, CM_NONE, ObCharset::get_system_collation());
@ -240,7 +239,7 @@ int ObTableLoadPartitionCalc::get_row(ObTableLoadPartitionCalcContext &ctx, cons
LOG_WARN("fail to alloc memory", KR(ret)); LOG_WARN("fail to alloc memory", KR(ret));
} }
for (int64_t i = 0; OB_SUCC(ret) && i < rowkey_obj_count; ++i) { for (int64_t i = 0; OB_SUCC(ret) && i < rowkey_obj_count; ++i) {
const IndexAndType &index_and_type = rowkey_obj_index_.at(i); const IndexAndType &index_and_type = part_key_obj_index_.at(i);
const int64_t obj_index = index_and_type.index_; const int64_t obj_index = index_and_type.index_;
if (OB_UNLIKELY(obj_index >= length)) { if (OB_UNLIKELY(obj_index >= length)) {
ret = OB_INVALID_ARGUMENT; ret = OB_INVALID_ARGUMENT;
@ -258,16 +257,13 @@ int ObTableLoadPartitionCalc::get_row(ObTableLoadPartitionCalcContext &ctx, cons
} }
int ObTableLoadPartitionCalc::get_partition_by_row( int ObTableLoadPartitionCalc::get_partition_by_row(
ObIArray<ObNewRow> &part_rows, ObIArray<ObTableLoadPartitionId> &partition_ids) const ObIArray<ObNewRow> &part_rows, ObIArray<ObTableLoadPartitionId> &partition_ids)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
ObSchemaGetterGuard schema_guard;
ObArray<ObTabletID> tablet_ids; ObArray<ObTabletID> tablet_ids;
ObArray<ObObjectID> part_ids; ObArray<ObObjectID> part_ids;
if (OB_FAIL(ObTableLoadSchema::get_schema_guard(tenant_id_, schema_guard))) { if (OB_FAIL(table_location_.calculate_partition_ids_by_rows2(
LOG_WARN("fail to get schema guard", KR(ret), K_(tenant_id)); session(), schema_guard_, table_id_, part_rows, tablet_ids, part_ids))) {
} else if (OB_FAIL(table_location_.calculate_partition_ids_by_rows2(
session(), schema_guard, table_id_, part_rows, tablet_ids, part_ids))) {
LOG_WARN("fail to calc partition id", KR(ret)); LOG_WARN("fail to calc partition id", KR(ret));
} else if (OB_UNLIKELY(part_rows.count() != part_ids.count() || } else if (OB_UNLIKELY(part_rows.count() != part_ids.count() ||
part_rows.count() != tablet_ids.count())) { part_rows.count() != tablet_ids.count())) {

View File

@ -42,14 +42,14 @@ public:
public: public:
ObTableLoadPartitionCalc(); ObTableLoadPartitionCalc();
int init(uint64_t tenant_id, uint64_t table_id); int init(uint64_t tenant_id, uint64_t table_id);
int calc(ObTableLoadPartitionCalcContext &ctx) const; int calc(ObTableLoadPartitionCalcContext &ctx);
private: private:
int init_rowkey_index(const share::schema::ObTableSchema *table_schema, int init_part_key_index(const share::schema::ObTableSchema *table_schema,
common::ObIAllocator &allocator); common::ObIAllocator &allocator);
int get_row(ObTableLoadPartitionCalcContext &ctx, const table::ObTableLoadObjRow &obj_row, int32_t length, common::ObNewRow &part_row, int get_row(ObTableLoadPartitionCalcContext &ctx, const table::ObTableLoadObjRow &obj_row, int32_t length, common::ObNewRow &part_row,
common::ObIAllocator &allocator) const; common::ObIAllocator &allocator) const;
int get_partition_by_row(common::ObIArray<common::ObNewRow> &part_rows, int get_partition_by_row(common::ObIArray<common::ObNewRow> &part_rows,
common::ObIArray<table::ObTableLoadPartitionId> &partition_ids) const; common::ObIArray<table::ObTableLoadPartitionId> &partition_ids);
public: public:
struct IndexAndType struct IndexAndType
{ {
@ -59,7 +59,7 @@ public:
TO_STRING_KV(K_(index), KP_(column_schema)); TO_STRING_KV(K_(index), KP_(column_schema));
}; };
public: public:
table::ObTableLoadArray<IndexAndType> rowkey_obj_index_; table::ObTableLoadArray<IndexAndType> part_key_obj_index_;
common::ObTimeZoneInfo tz_info_; common::ObTimeZoneInfo tz_info_;
ObTableLoadTimeConverter time_cvrt_; ObTableLoadTimeConverter time_cvrt_;
bool is_partition_with_autoinc_; bool is_partition_with_autoinc_;
@ -76,6 +76,7 @@ private:
sql::ObSqlCtx sql_ctx_; sql::ObSqlCtx sql_ctx_;
sql::ObExecContext exec_ctx_; sql::ObExecContext exec_ctx_;
sql::ObTableLocation table_location_; sql::ObTableLocation table_location_;
ObSchemaGetterGuard schema_guard_;
bool is_inited_; bool is_inited_;
DISALLOW_COPY_AND_ASSIGN(ObTableLoadPartitionCalc); DISALLOW_COPY_AND_ASSIGN(ObTableLoadPartitionCalc);
}; };

View File

@ -215,7 +215,7 @@ int ObTableLoadTransBucketWriter::handle_partition_with_autoinc_identity(
ObTableLoadObjRow &obj_row = obj_rows.at(j); ObTableLoadObjRow &obj_row = obj_rows.at(j);
out_obj.set_null(); out_obj.set_null();
const ObTableLoadPartitionCalc::IndexAndType &index_and_type = const ObTableLoadPartitionCalc::IndexAndType &index_and_type =
coordinator_ctx_->partition_calc_.rowkey_obj_index_.at( coordinator_ctx_->partition_calc_.part_key_obj_index_.at(
coordinator_ctx_->partition_calc_.partition_with_autoinc_idx_); coordinator_ctx_->partition_calc_.partition_with_autoinc_idx_);
const ObColumnSchemaV2 *column_schema = index_and_type.column_schema_; const ObColumnSchemaV2 *column_schema = index_and_type.column_schema_;
const int64_t obj_index = index_and_type.index_; const int64_t obj_index = index_and_type.index_;