diff --git a/src/share/schema/ob_schema_retrieve_utils.h b/src/share/schema/ob_schema_retrieve_utils.h index 51e9f1901..d4cd915b7 100644 --- a/src/share/schema/ob_schema_retrieve_utils.h +++ b/src/share/schema/ob_schema_retrieve_utils.h @@ -112,18 +112,36 @@ public: index_(0), table_(&table), tmp_table_(NULL), - table_array_(NULL) + table_array_(NULL), + current_allocator_("ScheRetri"), + another_allocator_("ScheRetri"), + current_schema_(¤t_allocator_), + another_schema_(&another_allocator_) {} ObSchemaRetrieveHelper(common::ObArray &tables) : mode_(Mode::MULTIPLE_TABLE), index_(0), table_(NULL), tmp_table_(NULL), - table_array_(&tables) + table_array_(&tables), + current_allocator_("ScheRetri"), + another_allocator_("ScheRetri"), + current_schema_(¤t_allocator_), + another_schema_(&another_allocator_) {} ~ObSchemaRetrieveHelper() {} - SCHEMA &get_current() { return schemas_[index_]; } + SCHEMA &get_and_reset_current() + { + if (0 == index_) { + current_schema_.reset(); + current_allocator_.reuse(); + } else { + another_schema_.reset(); + another_allocator_.reuse(); + } + return 0 == index_ ? current_schema_ : another_schema_; + } int64_t get_curr_schema_id(); void rotate() { index_ = 1 - index_; } int get_table(const uint64_t table_id, TABLE_SCHEMA *&table); @@ -142,7 +160,10 @@ private: //for multi table TABLE_SCHEMA *tmp_table_; ObArray *table_array_; - SCHEMA schemas_[2]; + ObArenaAllocator current_allocator_; + ObArenaAllocator another_allocator_; + SCHEMA current_schema_; + SCHEMA another_schema_; }; @@ -163,7 +184,11 @@ public: tmp_table_(NULL), table_array_(NULL), partition_(NULL), - is_subpart_template_(is_subpart_template) + is_subpart_template_(is_subpart_template), + current_allocator_("SubScheRetri"), + another_allocator_("SubScheRetri"), + current_schema_(¤t_allocator_), + another_schema_(&another_allocator_) {} ObSubPartSchemaRetrieveHelper(common::ObArray &tables, const bool is_subpart_template = true) @@ -173,11 +198,25 @@ public: tmp_table_(NULL), table_array_(&tables), partition_(NULL), - is_subpart_template_(is_subpart_template) + is_subpart_template_(is_subpart_template), + current_allocator_("SubScheRetri"), + another_allocator_("SubScheRetri"), + current_schema_(¤t_allocator_), + another_schema_(&another_allocator_) {} ~ObSubPartSchemaRetrieveHelper() {} - ObSubPartition &get_current() { return schemas_[index_]; } + ObSubPartition &get_and_reset_current() + { + if (0 == index_) { + current_schema_.reset(); + current_allocator_.reuse(); + } else { + another_schema_.reset(); + another_allocator_.reuse(); + } + return 0 == index_ ? current_schema_ : another_schema_; + } int64_t get_curr_schema_id(); void rotate() { index_ = 1 - index_; } int get_table(const uint64_t table_id, TABLE_SCHEMA *&table); @@ -197,10 +236,13 @@ private: //for multi table TABLE_SCHEMA *tmp_table_; ObArray *table_array_; - ObSubPartition schemas_[2]; // for is_subpart_template = false ObPartition *partition_; bool is_subpart_template_; + ObArenaAllocator current_allocator_; + ObArenaAllocator another_allocator_; + ObSubPartition current_schema_; + ObSubPartition another_schema_; }; struct VersionHisVal; diff --git a/src/share/schema/ob_schema_retrieve_utils.ipp b/src/share/schema/ob_schema_retrieve_utils.ipp index 548c2c1a9..d48ddc292 100644 --- a/src/share/schema/ob_schema_retrieve_utils.ipp +++ b/src/share/schema/ob_schema_retrieve_utils.ipp @@ -139,8 +139,7 @@ int ObSchemaRetrieveUtils::retrieve_schema( ObSchemaRetrieveHelper helper(table_schema_array); while (OB_SUCC(ret) && common::OB_SUCCESS == (ret = result.next())) { bool is_deleted = false; - SCHEMA ¤t = helper.get_current(); - current.reset(); + SCHEMA ¤t = helper.get_and_reset_current(); if (OB_FAIL(helper.fill_current(tenant_id, check_deleted, result, current, is_deleted))) { SHARE_SCHEMA_LOG(WARN, "fill schema failed", K(ret)); } else if (current.get_table_id() == last_table_id @@ -213,13 +212,17 @@ int ObSchemaRetrieveUtils::retrieve_column_group_schema(const uint64_t tenant_id // store current_schema and last_schema bool is_last_deleted = false; ObColumnGroupSchema *last_schema = NULL; - ObColumnGroupSchema tmp_schemas[2]; // to avoid full copy + ObArenaAllocator current_allocator("ColGroScheRetri"); + ObArenaAllocator another_allocator("ColGroScheRetri"); + ObColumnGroupSchema tmp_schemas[2] = {ObColumnGroupSchema(¤t_allocator), + ObColumnGroupSchema(&another_allocator)}; int64_t tmp_idx = 0; while (OB_SUCC(ret) && OB_SUCC(result.next())) { bool is_deleted = false; uint64_t cur_table_id = common::OB_INVALID_ID; ObColumnGroupSchema ¤t = tmp_schemas[tmp_idx]; current.reset(); + 0 == tmp_idx ? current_allocator.reuse() : another_allocator.reuse(); if (OB_FAIL(ObSchemaRetrieveUtils::fill_column_group_info(check_deleted, result, current, cur_table_id, is_deleted))) { SHARE_SCHEMA_LOG(WARN, "fail to fill column_group schema", KR(ret)); @@ -586,7 +589,7 @@ int ObSubPartSchemaRetrieveHelper::add(ObSubPartition &p) template int64_t ObSubPartSchemaRetrieveHelper::get_curr_schema_id() { - return schemas_[index_].get_sub_part_id(); + return index_ == 0 ? current_schema_.get_sub_part_id() : another_schema_.get_sub_part_id(); } template @@ -665,7 +668,7 @@ int ObSchemaRetrieveHelper::add(SCHEMA &p) template int64_t ObSchemaRetrieveHelper::get_curr_schema_id() { - return ObSchemaRetrieveHelperBase::get_schema_id(schemas_[index_]); + return ObSchemaRetrieveHelperBase::get_schema_id(index_ == 0 ? current_schema_ : another_schema_); } template @@ -698,8 +701,7 @@ int ObSchemaRetrieveUtils::retrieve_schema(const uint64_t tenant_id, ObSchemaRetrieveHelper helper(*table_schema); while (OB_SUCC(ret) && common::OB_SUCCESS == (ret = result.next())) { bool is_deleted = false; - SCHEMA ¤t = helper.get_current(); - current.reset(); + SCHEMA ¤t = helper.get_and_reset_current(); if (OB_FAIL(helper.fill_current(tenant_id, check_deleted, result, current, is_deleted))) { SHARE_SCHEMA_LOG(WARN, "fill schema fail", K(ret)); } else if (table_id != current.get_table_id()) { @@ -839,8 +841,7 @@ int ObSchemaRetrieveUtils::retrieve_subpart_schema( is_subpart_template); while (OB_SUCC(ret) && OB_SUCC(result.next())) { bool is_deleted = false; - ObSubPartition ¤t = helper.get_current(); - current.reset(); + ObSubPartition ¤t = helper.get_and_reset_current(); if (OB_FAIL(helper.fill_current(tenant_id, check_deleted, result, current, is_deleted))) { SHARE_SCHEMA_LOG(WARN, "fill schema fail", K(ret)); @@ -889,8 +890,7 @@ int ObSchemaRetrieveUtils::retrieve_subpart_schema( is_subpart_template); while (OB_SUCC(ret) && OB_SUCC(result.next())) { bool is_deleted = false; - ObSubPartition ¤t = helper.get_current(); - current.reset(); + ObSubPartition ¤t = helper.get_and_reset_current(); if (OB_FAIL(helper.fill_current(tenant_id, check_deleted, result, current, is_deleted))) { SHARE_SCHEMA_LOG(WARN, "fill schema fail", K(ret));