[CP] fix adjust_fts_arg() allocator issue

This commit is contained in:
zhenhan.gong@gmail.com
2024-06-17 17:11:51 +00:00
committed by ob-robot
parent 387ce63b5d
commit 8121990907
3 changed files with 20 additions and 18 deletions

View File

@ -231,6 +231,7 @@ int ObFtsIndexBuilderUtil::generate_fts_aux_index_name(
int ObFtsIndexBuilderUtil::adjust_fts_args( int ObFtsIndexBuilderUtil::adjust_fts_args(
obrpc::ObCreateIndexArg &index_arg, obrpc::ObCreateIndexArg &index_arg,
ObTableSchema &data_schema, // not const since will add column to data schema ObTableSchema &data_schema, // not const since will add column to data schema
ObIAllocator &allocator,
ObIArray<ObColumnSchemaV2 *> &gen_columns) ObIArray<ObColumnSchemaV2 *> &gen_columns)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
@ -292,6 +293,7 @@ int ObFtsIndexBuilderUtil::adjust_fts_args(
LOG_WARN("failed to push back doc id col", K(ret)); LOG_WARN("failed to push back doc id col", K(ret));
} else if (OB_FAIL(adjust_fts_arg(&index_arg, } else if (OB_FAIL(adjust_fts_arg(&index_arg,
data_schema, data_schema,
allocator,
tmp_cols))) { tmp_cols))) {
LOG_WARN("failed to append fts_index arg", K(ret)); LOG_WARN("failed to append fts_index arg", K(ret));
} }
@ -352,6 +354,7 @@ int ObFtsIndexBuilderUtil::adjust_fts_args(
LOG_WARN("fail to push back document length column", K(ret)); LOG_WARN("fail to push back document length column", K(ret));
} else if (OB_FAIL(adjust_fts_arg(&index_arg, } else if (OB_FAIL(adjust_fts_arg(&index_arg,
data_schema, data_schema,
allocator,
tmp_cols))) { tmp_cols))) {
LOG_WARN("failed to append fts_index arg", K(ret)); LOG_WARN("failed to append fts_index arg", K(ret));
} }
@ -374,6 +377,7 @@ int ObFtsIndexBuilderUtil::adjust_fts_args(
LOG_WARN("fail to push back document length column", K(ret)); LOG_WARN("fail to push back document length column", K(ret));
} else if (OB_FAIL(adjust_fts_arg(&index_arg, } else if (OB_FAIL(adjust_fts_arg(&index_arg,
data_schema, data_schema,
allocator,
tmp_cols))) { tmp_cols))) {
LOG_WARN("failed to append fts_index arg", K(ret)); LOG_WARN("failed to append fts_index arg", K(ret));
} }
@ -690,8 +694,9 @@ int ObFtsIndexBuilderUtil::check_ft_cols(
} }
int ObFtsIndexBuilderUtil::adjust_fts_arg( int ObFtsIndexBuilderUtil::adjust_fts_arg(
ObCreateIndexArg *index_arg, // not const since index_arg.index_schema.allocator will be used ObCreateIndexArg *index_arg, // not const since index_columns_ will be modified
const ObTableSchema &data_schema, const ObTableSchema &data_schema,
ObIAllocator &allocator,
const ObIArray<const ObColumnSchemaV2 *> &fts_cols) const ObIArray<const ObColumnSchemaV2 *> &fts_cols)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
@ -715,12 +720,8 @@ int ObFtsIndexBuilderUtil::adjust_fts_arg(
} else { } else {
index_arg->index_columns_.reuse(); index_arg->index_columns_.reuse();
index_arg->store_columns_.reuse(); index_arg->store_columns_.reuse();
ObIAllocator *allocator = index_arg->index_schema_.get_allocator();
if (OB_ISNULL(allocator)) { if (is_rowkey_doc) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("allocator is nullptr", K(ret));
} else if (is_rowkey_doc) {
// 1. add rowkey column to arg->index_columns // 1. add rowkey column to arg->index_columns
const ObRowkeyInfo &rowkey_info = data_schema.get_rowkey_info(); const ObRowkeyInfo &rowkey_info = data_schema.get_rowkey_info();
for (int64_t i = 0; OB_SUCC(ret) && i < rowkey_info.get_size(); ++i) { for (int64_t i = 0; OB_SUCC(ret) && i < rowkey_info.get_size(); ++i) {
@ -733,7 +734,7 @@ int ObFtsIndexBuilderUtil::adjust_fts_arg(
ret = OB_ERR_BAD_FIELD_ERROR; ret = OB_ERR_BAD_FIELD_ERROR;
LOG_WARN("get_column_schema failed", "table_id", LOG_WARN("get_column_schema failed", "table_id",
data_schema.get_table_id(), K(column_id), K(ret)); data_schema.get_table_id(), K(column_id), K(ret));
} else if (OB_FAIL(ob_write_string(*allocator, } else if (OB_FAIL(ob_write_string(allocator,
rowkey_col->get_column_name_str(), rowkey_col->get_column_name_str(),
rowkey_column.column_name_))) { rowkey_column.column_name_))) {
//to keep the memory lifetime of column_name consistent with index_arg //to keep the memory lifetime of column_name consistent with index_arg
@ -745,7 +746,7 @@ int ObFtsIndexBuilderUtil::adjust_fts_arg(
// 2. add doc id column to arg->store_columns // 2. add doc id column to arg->store_columns
const ObColumnSchemaV2 *doc_id_col = fts_cols.at(0); const ObColumnSchemaV2 *doc_id_col = fts_cols.at(0);
ObString doc_id_col_name; ObString doc_id_col_name;
if (FAILEDx(ob_write_string(*allocator, doc_id_col->get_column_name_str(), doc_id_col_name))) { if (FAILEDx(ob_write_string(allocator, doc_id_col->get_column_name_str(), doc_id_col_name))) {
LOG_WARN("fail to deep copy doc id column name", K(ret)); LOG_WARN("fail to deep copy doc id column name", K(ret));
} else if (OB_FAIL(index_arg->store_columns_.push_back( doc_id_col_name))) { } else if (OB_FAIL(index_arg->store_columns_.push_back( doc_id_col_name))) {
LOG_WARN("failed to push back doc id column", K(ret)); LOG_WARN("failed to push back doc id column", K(ret));
@ -758,7 +759,7 @@ int ObFtsIndexBuilderUtil::adjust_fts_arg(
} else if (OB_ISNULL(doc_id_col)) { } else if (OB_ISNULL(doc_id_col)) {
ret = OB_ERR_UNEXPECTED; ret = OB_ERR_UNEXPECTED;
LOG_WARN("fts_col is null", K(ret)); LOG_WARN("fts_col is null", K(ret));
} else if (OB_FAIL(ob_write_string(*allocator, } else if (OB_FAIL(ob_write_string(allocator,
doc_id_col->get_column_name_str(), doc_id_col->get_column_name_str(),
doc_id_column.column_name_))) { doc_id_column.column_name_))) {
//to keep the memory lifetime of column_name consistent with index_arg //to keep the memory lifetime of column_name consistent with index_arg
@ -793,16 +794,15 @@ int ObFtsIndexBuilderUtil::inner_adjust_fts_arg(
obrpc::ObCreateIndexArg *fts_arg, obrpc::ObCreateIndexArg *fts_arg,
const ObIArray<const ObColumnSchemaV2 *> &fts_cols, const ObIArray<const ObColumnSchemaV2 *> &fts_cols,
const int index_column_cnt, const int index_column_cnt,
ObIAllocator *allocator) ObIAllocator &allocator)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
if (OB_ISNULL(fts_arg) || if (OB_ISNULL(fts_arg) ||
(!share::schema::is_fts_index_aux(fts_arg->index_type_) && (!share::schema::is_fts_index_aux(fts_arg->index_type_) &&
!share::schema::is_fts_doc_word_aux(fts_arg->index_type_)) || !share::schema::is_fts_doc_word_aux(fts_arg->index_type_)) ||
OB_ISNULL(allocator) ||
fts_cols.count() != index_column_cnt + 2) { fts_cols.count() != index_column_cnt + 2) {
ret = OB_ERR_UNEXPECTED; ret = OB_ERR_UNEXPECTED;
LOG_WARN("invalid argument", K(ret), KPC(fts_arg), KP(allocator), LOG_WARN("invalid argument", K(ret), KPC(fts_arg),
K(fts_cols.count()), K(index_column_cnt)); K(fts_cols.count()), K(index_column_cnt));
} else { } else {
// 1. add doc id column, word column to arg->index_columns // 1. add doc id column, word column to arg->index_columns
@ -812,7 +812,7 @@ int ObFtsIndexBuilderUtil::inner_adjust_fts_arg(
if (OB_ISNULL(fts_col)) { if (OB_ISNULL(fts_col)) {
ret = OB_ERR_UNEXPECTED; ret = OB_ERR_UNEXPECTED;
LOG_WARN("fts_col is null", K(ret), K(i)); LOG_WARN("fts_col is null", K(ret), K(i));
} else if (OB_FAIL(ob_write_string(*allocator, } else if (OB_FAIL(ob_write_string(allocator,
fts_col->get_column_name_str(), fts_col->get_column_name_str(),
fts_column.column_name_))) { fts_column.column_name_))) {
//to keep the memory lifetime of column_name consistent with index_arg //to keep the memory lifetime of column_name consistent with index_arg
@ -824,7 +824,7 @@ int ObFtsIndexBuilderUtil::inner_adjust_fts_arg(
// 2. add word count column to arg->store_columns // 2. add word count column to arg->store_columns
const ObColumnSchemaV2 *word_count_col = fts_cols.at(index_column_cnt); const ObColumnSchemaV2 *word_count_col = fts_cols.at(index_column_cnt);
ObString word_count_col_name; ObString word_count_col_name;
if (FAILEDx(ob_write_string(*allocator, word_count_col->get_column_name_str(), word_count_col_name))) { if (FAILEDx(ob_write_string(allocator, word_count_col->get_column_name_str(), word_count_col_name))) {
LOG_WARN("fail to deep copy word count column name", K(ret)); LOG_WARN("fail to deep copy word count column name", K(ret));
} else if (OB_FAIL(fts_arg->store_columns_.push_back(word_count_col_name))) { } else if (OB_FAIL(fts_arg->store_columns_.push_back(word_count_col_name))) {
LOG_WARN("failed to push back word count column", K(ret)); LOG_WARN("failed to push back word count column", K(ret));
@ -832,7 +832,7 @@ int ObFtsIndexBuilderUtil::inner_adjust_fts_arg(
// 3. add document length column to arg->store_columns // 3. add document length column to arg->store_columns
const ObColumnSchemaV2 *doc_length_col = fts_cols.at(index_column_cnt + 1); const ObColumnSchemaV2 *doc_length_col = fts_cols.at(index_column_cnt + 1);
ObString doc_length_col_name; ObString doc_length_col_name;
if (FAILEDx(ob_write_string(*allocator, doc_length_col->get_column_name_str(), doc_length_col_name))) { if (FAILEDx(ob_write_string(allocator, doc_length_col->get_column_name_str(), doc_length_col_name))) {
LOG_WARN("fail to deep copy doc length column", K(ret)); LOG_WARN("fail to deep copy doc length column", K(ret));
} else if (OB_FAIL(fts_arg->store_columns_.push_back(doc_length_col_name))) { } else if (OB_FAIL(fts_arg->store_columns_.push_back(doc_length_col_name))) {
LOG_WARN("fail to push document length column", K(ret)); LOG_WARN("fail to push document length column", K(ret));

View File

@ -52,6 +52,7 @@ public:
static int adjust_fts_args( static int adjust_fts_args(
obrpc::ObCreateIndexArg &index_arg, obrpc::ObCreateIndexArg &index_arg,
ObTableSchema &data_schema, // not const since will add column to data schema ObTableSchema &data_schema, // not const since will add column to data schema
ObIAllocator &allocator,
ObIArray<ObColumnSchemaV2 *> &gen_columns); ObIArray<ObColumnSchemaV2 *> &gen_columns);
static int set_fts_rowkey_doc_table_columns( static int set_fts_rowkey_doc_table_columns(
const obrpc::ObCreateIndexArg &arg, const obrpc::ObCreateIndexArg &arg,
@ -75,14 +76,15 @@ private:
const obrpc::ObCreateIndexArg *index_arg, const obrpc::ObCreateIndexArg *index_arg,
ObTableSchema &data_schema); // not const since will add cascade flag ObTableSchema &data_schema); // not const since will add cascade flag
static int adjust_fts_arg( static int adjust_fts_arg(
obrpc::ObCreateIndexArg *index_arg, // not const since index_arg.index_schema.allocator will be used obrpc::ObCreateIndexArg *index_arg, // not const since index_columns_ will be modified
const ObTableSchema &data_schema, const ObTableSchema &data_schema,
ObIAllocator &allocator,
const ObIArray<const ObColumnSchemaV2 *> &fts_cols); const ObIArray<const ObColumnSchemaV2 *> &fts_cols);
static int inner_adjust_fts_arg( static int inner_adjust_fts_arg(
obrpc::ObCreateIndexArg *fts_arg, obrpc::ObCreateIndexArg *fts_arg,
const ObIArray<const ObColumnSchemaV2 *> &fts_cols, const ObIArray<const ObColumnSchemaV2 *> &fts_cols,
const int index_column_cnt, const int index_column_cnt,
ObIAllocator *allocator); ObIAllocator &allocator);
static int generate_doc_id_column( static int generate_doc_id_column(
const obrpc::ObCreateIndexArg *index_arg, const obrpc::ObCreateIndexArg *index_arg,
const uint64_t col_id, const uint64_t col_id,

View File

@ -662,7 +662,7 @@ int ObIndexBuilderUtil::adjust_expr_index_args(
} else if (is_fts_index(arg.index_type_)) { } else if (is_fts_index(arg.index_type_)) {
if (OB_FAIL(ObFtsIndexBuilderUtil::check_fts_or_multivalue_index_allowed(data_schema))) { if (OB_FAIL(ObFtsIndexBuilderUtil::check_fts_or_multivalue_index_allowed(data_schema))) {
LOG_WARN("fail to check fts index allowed", K(ret)); LOG_WARN("fail to check fts index allowed", K(ret));
} else if (OB_FAIL(ObFtsIndexBuilderUtil::adjust_fts_args(arg, data_schema, gen_columns))) { } else if (OB_FAIL(ObFtsIndexBuilderUtil::adjust_fts_args(arg, data_schema, allocator, gen_columns))) {
LOG_WARN("failed to adjust fts args", K(ret)); LOG_WARN("failed to adjust fts args", K(ret));
} }
} else if (is_multivalue_index(arg.index_type_)) { } else if (is_multivalue_index(arg.index_type_)) {