fix core caused by incorrect allocator when deep copy string

Co-authored-by: Larry955 <1412857955@qq.com>
This commit is contained in:
obdev
2023-01-28 14:05:48 +08:00
committed by ob-robot
parent 599a51b255
commit 999c80b053
2 changed files with 9 additions and 7 deletions

View File

@ -510,7 +510,7 @@ int ObIndexBuilderUtil::adjust_expr_index_args(
ret = OB_NOT_SUPPORTED; ret = OB_NOT_SUPPORTED;
LOG_WARN("tenant version is less than 4.1, spatial index not supported", K(ret), K(tenant_data_version)); LOG_WARN("tenant version is less than 4.1, spatial index not supported", K(ret), K(tenant_data_version));
LOG_USER_ERROR(OB_NOT_SUPPORTED, "tenant version is less than 4.1, spatial index"); LOG_USER_ERROR(OB_NOT_SUPPORTED, "tenant version is less than 4.1, spatial index");
} else if (OB_FAIL(adjust_spatial_args(arg, data_schema, spatial_cols))) { } else if (OB_FAIL(adjust_spatial_args(arg, data_schema, allocator, spatial_cols))) {
LOG_WARN("adjust spatial args failed", K(ret)); LOG_WARN("adjust spatial args failed", K(ret));
} else if (OB_FAIL(gen_columns.push_back(spatial_cols.at(0)))) { } else if (OB_FAIL(gen_columns.push_back(spatial_cols.at(0)))) {
LOG_WARN("push back cellid column to gen columns failed", K(ret)); LOG_WARN("push back cellid column to gen columns failed", K(ret));
@ -1112,28 +1112,29 @@ int ObIndexBuilderUtil::generate_prefix_column(
int ObIndexBuilderUtil::adjust_spatial_args( int ObIndexBuilderUtil::adjust_spatial_args(
ObCreateIndexArg &arg, ObCreateIndexArg &arg,
ObTableSchema &data_schema, ObTableSchema &data_schema,
ObIAllocator &allocator,
ObIArray<ObColumnSchemaV2*> &spatial_cols) ObIArray<ObColumnSchemaV2*> &spatial_cols)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
ObIAllocator *allocator = arg.index_schema_.get_allocator(); // spatial index needs to create two columns with type of uint64_t, varchar respectively
// 如果是spatial index,那么需要在表中创建2个列(uint64_t, varchar),并且在列上创建索引 // and add index on them
ObIArray<ObColumnSortItem> &sort_items = arg.index_columns_; ObIArray<ObColumnSortItem> &sort_items = arg.index_columns_;
ObArray<ObColumnSortItem> new_sort_items; ObArray<ObColumnSortItem> new_sort_items;
ObColumnSortItem cellid_sort_item; ObColumnSortItem cellid_sort_item;
ObColumnSortItem mbr_sort_item; ObColumnSortItem mbr_sort_item;
if (OB_UNLIKELY(sort_items.empty()) || OB_ISNULL(allocator)) { if (OB_UNLIKELY(sort_items.empty())) {
ret = OB_ERR_UNEXPECTED; ret = OB_ERR_UNEXPECTED;
LOG_WARN("get invalid arguments", K(ret), K(sort_items), K(allocator)); LOG_WARN("get invalid arguments", K(ret));
} else if (OB_FAIL(generate_spatial_columns(sort_items.at(0).column_name_, data_schema, spatial_cols))) { } else if (OB_FAIL(generate_spatial_columns(sort_items.at(0).column_name_, data_schema, spatial_cols))) {
LOG_WARN("generate spatial column failed", K(ret)); LOG_WARN("generate spatial column failed", K(ret));
} else if (OB_UNLIKELY(spatial_cols.count() != 2) || } else if (OB_UNLIKELY(spatial_cols.count() != 2) ||
OB_ISNULL(spatial_cols.at(0)) || OB_ISNULL(spatial_cols.at(1))) { OB_ISNULL(spatial_cols.at(0)) || OB_ISNULL(spatial_cols.at(1))) {
ret = OB_ERR_UNEXPECTED; ret = OB_ERR_UNEXPECTED;
LOG_WARN("get invalid spatial cols", K(ret), K(spatial_cols.count())); LOG_WARN("get invalid spatial cols", K(ret), K(spatial_cols.count()));
} else if (OB_FAIL(ob_write_string(*allocator, spatial_cols.at(0)->get_column_name_str(), } else if (OB_FAIL(ob_write_string(allocator, spatial_cols.at(0)->get_column_name_str(),
cellid_sort_item.column_name_))) { cellid_sort_item.column_name_))) {
LOG_WARN("failed to copy column name", K(ret)); LOG_WARN("failed to copy column name", K(ret));
} else if (OB_FAIL(ob_write_string(*allocator, spatial_cols.at(1)->get_column_name_str(), } else if (OB_FAIL(ob_write_string(allocator, spatial_cols.at(1)->get_column_name_str(),
mbr_sort_item.column_name_))) { mbr_sort_item.column_name_))) {
LOG_WARN("failed to copy column name", K(ret)); LOG_WARN("failed to copy column name", K(ret));
} else if (OB_FAIL(new_sort_items.push_back(cellid_sort_item))) { } else if (OB_FAIL(new_sort_items.push_back(cellid_sort_item))) {

View File

@ -122,6 +122,7 @@ private:
static int adjust_spatial_args( static int adjust_spatial_args(
obrpc::ObCreateIndexArg &arg, obrpc::ObCreateIndexArg &arg,
share::schema::ObTableSchema &data_schema, share::schema::ObTableSchema &data_schema,
common::ObIAllocator &allocator,
common::ObIArray<share::schema::ObColumnSchemaV2*> &spatial_cols); common::ObIArray<share::schema::ObColumnSchemaV2*> &spatial_cols);
static int generate_spatial_columns( static int generate_spatial_columns(
const common::ObString &col_name, const common::ObString &col_name,