From dc2707cb42d226e22489e3234c20e5498e440ac5 Mon Sep 17 00:00:00 2001 From: obdev Date: Fri, 10 Mar 2023 15:40:48 +0000 Subject: [PATCH] Fixing core in the cast_obj function --- .../ob_table_load_partition_calc.cpp | 36 +++++++++---------- .../table_load/ob_table_load_partition_calc.h | 9 ++--- .../ob_table_load_trans_bucket_writer.cpp | 2 +- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/observer/table_load/ob_table_load_partition_calc.cpp b/src/observer/table_load/ob_table_load_partition_calc.cpp index 4fed61af63..1e4d3e7689 100644 --- a/src/observer/table_load/ob_table_load_partition_calc.cpp +++ b/src/observer/table_load/ob_table_load_partition_calc.cpp @@ -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()))) { LOG_WARN("fail to get tenant time zone", KR(ret), K(tenant_id_)); } else { - ObSchemaGetterGuard schema_guard; const ObTableSchema *table_schema = nullptr; ObDataTypeCastParams cast_params(&tz_info_); if (OB_FAIL(time_cvrt_.init(cast_params.get_nls_format(ObDateTimeType)))) { 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))) { LOG_WARN("fail to get table schema", KR(ret), K(tenant_id), K(table_id)); } else { @@ -102,11 +101,11 @@ int ObTableLoadPartitionCalc::init(uint64_t tenant_id, uint64_t table_id) exec_ctx_.set_sql_ctx(&sql_ctx_); // 初始化table_location_ 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)); } - // 获取rowkey_obj_index_ - else if (OB_FAIL(init_rowkey_index(table_schema, allocator_))) { + // 获取part_key_obj_index_ + else if (OB_FAIL(init_part_key_index(table_schema, allocator_))) { 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; } -int ObTableLoadPartitionCalc::init_rowkey_index(const ObTableSchema *table_schema, +int ObTableLoadPartitionCalc::init_part_key_index(const ObTableSchema *table_schema, ObIAllocator &allocator) { int ret = OB_SUCCESS; @@ -146,7 +145,7 @@ int ObTableLoadPartitionCalc::init_rowkey_index(const ObTableSchema *table_schem } } 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)); } } @@ -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(); if (part_key_pos > 0 || sub_part_key_pos > 0) { pos ++; - if (OB_UNLIKELY(pos > rowkey_obj_index_.count())) { + if (OB_UNLIKELY(pos > part_key_obj_index_.count())) { ret = OB_ERR_UNEXPECTED; LOG_WARN("unexpected rowkey position", KR(ret), KPC(column_schema), K(pos)); } else { if (table_schema->is_heap_table()) { abort_unless(i > 0); - rowkey_obj_index_[pos - 1].index_ = i - 1; + part_key_obj_index_[pos - 1].index_ = i - 1; } else { - rowkey_obj_index_[pos - 1].index_ = i; + part_key_obj_index_[pos - 1].index_ = i; if (column_schema->is_tbl_part_key_column() && (column_schema->is_identity_column() || column_schema->is_autoincrement())) { is_partition_with_autoinc_ = true; 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; } -int ObTableLoadPartitionCalc::calc(ObTableLoadPartitionCalcContext &ctx) const +int ObTableLoadPartitionCalc::calc(ObTableLoadPartitionCalcContext &ctx) { OB_TABLE_LOAD_STATISTICS_TIME_COST(calc_part_time_us); int ret = OB_SUCCESS; @@ -230,7 +229,7 @@ int ObTableLoadPartitionCalc::get_row(ObTableLoadPartitionCalcContext &ctx, cons ObIAllocator &allocator) const { 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(allocator.alloc(sizeof(ObObj) * rowkey_obj_count)); ObDataTypeCastParams cast_params(&tz_info_); 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)); } 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_; if (OB_UNLIKELY(obj_index >= length)) { ret = OB_INVALID_ARGUMENT; @@ -258,16 +257,13 @@ int ObTableLoadPartitionCalc::get_row(ObTableLoadPartitionCalcContext &ctx, cons } int ObTableLoadPartitionCalc::get_partition_by_row( - ObIArray &part_rows, ObIArray &partition_ids) const + ObIArray &part_rows, ObIArray &partition_ids) { int ret = OB_SUCCESS; - ObSchemaGetterGuard schema_guard; ObArray tablet_ids; ObArray part_ids; - if (OB_FAIL(ObTableLoadSchema::get_schema_guard(tenant_id_, schema_guard))) { - LOG_WARN("fail to get schema guard", KR(ret), K_(tenant_id)); - } else if (OB_FAIL(table_location_.calculate_partition_ids_by_rows2( - session(), schema_guard, table_id_, part_rows, tablet_ids, part_ids))) { + 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)); } else if (OB_UNLIKELY(part_rows.count() != part_ids.count() || part_rows.count() != tablet_ids.count())) { diff --git a/src/observer/table_load/ob_table_load_partition_calc.h b/src/observer/table_load/ob_table_load_partition_calc.h index 990c32dc8b..47f483277c 100644 --- a/src/observer/table_load/ob_table_load_partition_calc.h +++ b/src/observer/table_load/ob_table_load_partition_calc.h @@ -42,14 +42,14 @@ public: public: ObTableLoadPartitionCalc(); int init(uint64_t tenant_id, uint64_t table_id); - int calc(ObTableLoadPartitionCalcContext &ctx) const; + int calc(ObTableLoadPartitionCalcContext &ctx); 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); int get_row(ObTableLoadPartitionCalcContext &ctx, const table::ObTableLoadObjRow &obj_row, int32_t length, common::ObNewRow &part_row, common::ObIAllocator &allocator) const; int get_partition_by_row(common::ObIArray &part_rows, - common::ObIArray &partition_ids) const; + common::ObIArray &partition_ids); public: struct IndexAndType { @@ -59,7 +59,7 @@ public: TO_STRING_KV(K_(index), KP_(column_schema)); }; public: - table::ObTableLoadArray rowkey_obj_index_; + table::ObTableLoadArray part_key_obj_index_; common::ObTimeZoneInfo tz_info_; ObTableLoadTimeConverter time_cvrt_; bool is_partition_with_autoinc_; @@ -76,6 +76,7 @@ private: sql::ObSqlCtx sql_ctx_; sql::ObExecContext exec_ctx_; sql::ObTableLocation table_location_; + ObSchemaGetterGuard schema_guard_; bool is_inited_; DISALLOW_COPY_AND_ASSIGN(ObTableLoadPartitionCalc); }; diff --git a/src/observer/table_load/ob_table_load_trans_bucket_writer.cpp b/src/observer/table_load/ob_table_load_trans_bucket_writer.cpp index 505ab05bc6..94627df44a 100644 --- a/src/observer/table_load/ob_table_load_trans_bucket_writer.cpp +++ b/src/observer/table_load/ob_table_load_trans_bucket_writer.cpp @@ -215,7 +215,7 @@ int ObTableLoadTransBucketWriter::handle_partition_with_autoinc_identity( ObTableLoadObjRow &obj_row = obj_rows.at(j); out_obj.set_null(); 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_); const ObColumnSchemaV2 *column_schema = index_and_type.column_schema_; const int64_t obj_index = index_and_type.index_;