Adding ObTMArray to solve memory bloat issue

This commit is contained in:
obdev
2023-08-04 04:42:28 +00:00
committed by ob-robot
parent e5f2807901
commit 8e88ce9fed
7 changed files with 35 additions and 8 deletions

View File

@ -98,6 +98,7 @@ public:
virtual ~ObArrayImpl() __attribute__((noinline)); virtual ~ObArrayImpl() __attribute__((noinline));
inline void set_label(const lib::ObLabel &label) { block_allocator_.set_label(label); } inline void set_label(const lib::ObLabel &label) { block_allocator_.set_label(label); }
inline void set_attr(const lib::ObMemAttr &attr) { block_allocator_.set_attr(attr); } inline void set_attr(const lib::ObMemAttr &attr) { block_allocator_.set_attr(attr); }
inline void set_tenant_id(const uint64_t &tenant_id) { block_allocator_.set_tenant_id(tenant_id); }
inline void set_block_size(const int64_t block_size) { block_size_ = block_size; } inline void set_block_size(const int64_t block_size) { block_size_ = block_size; }
inline int64_t get_block_size() const {return block_size_; } inline int64_t get_block_size() const {return block_size_; }
inline void set_block_allocator(const BlockAllocatorT &alloc) { block_allocator_ = alloc; } inline void set_block_allocator(const BlockAllocatorT &alloc) { block_allocator_ = alloc; }

View File

@ -77,7 +77,7 @@ int ObBasicNestedLoopJoinOp::prepare_rescan_params(bool is_group)
ObPhysicalPlanCtx *plan_ctx = GET_PHY_PLAN_CTX(ctx_); ObPhysicalPlanCtx *plan_ctx = GET_PHY_PLAN_CTX(ctx_);
CK(OB_NOT_NULL(plan_ctx)); CK(OB_NOT_NULL(plan_ctx));
ObObjParam *param = NULL; ObObjParam *param = NULL;
common::ObSEArray<common::ObObjParam, 8> params; sql::ObTMArray<common::ObObjParam> params;
common::ObSArray<int64_t> param_idxs; common::ObSArray<int64_t> param_idxs;
common::ObSArray<int64_t> param_expr_idxs; common::ObSArray<int64_t> param_expr_idxs;
ObBatchRescanCtl *batch_rescan_ctl = (get_spec().enable_px_batch_rescan_ && is_group) ObBatchRescanCtl *batch_rescan_ctl = (get_spec().enable_px_batch_rescan_ && is_group)

View File

@ -1615,7 +1615,7 @@ int ObBatchRescanParams::deep_copy_param(const common::ObObjParam &org_param,
} }
int ObBatchRescanParams::append_batch_rescan_param(const ObIArray<int64_t> &param_idxs, int ObBatchRescanParams::append_batch_rescan_param(const ObIArray<int64_t> &param_idxs,
const ObSEArray<common::ObObjParam, 8> &res_objs) const ObTMArray<common::ObObjParam> &res_objs)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
if (OB_FAIL(params_.push_back(res_objs))) { if (OB_FAIL(params_.push_back(res_objs))) {
@ -1632,7 +1632,7 @@ int ObBatchRescanParams::append_batch_rescan_param(const ObIArray<int64_t> &para
} }
int ObBatchRescanParams::append_batch_rescan_param(const ObIArray<int64_t> &param_idxs, int ObBatchRescanParams::append_batch_rescan_param(const ObIArray<int64_t> &param_idxs,
const ObSEArray<ObObjParam, 8> &res_objs, const ObTMArray<ObObjParam> &res_objs,
const common::ObIArray<int64_t> &param_expr_idxs) const common::ObIArray<int64_t> &param_expr_idxs)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;

View File

@ -108,9 +108,9 @@ public:
return param_idxs_.at(idx); return param_idxs_.at(idx);
} }
int append_batch_rescan_param(const common::ObIArray<int64_t> &param_idxs, int append_batch_rescan_param(const common::ObIArray<int64_t> &param_idxs,
const common::ObSEArray<common::ObObjParam, 8> &res_objs); const sql::ObTMArray<common::ObObjParam> &res_objs);
int append_batch_rescan_param(const common::ObIArray<int64_t> &param_idxs, int append_batch_rescan_param(const common::ObIArray<int64_t> &param_idxs,
const common::ObSEArray<common::ObObjParam, 8> &res_objs, const sql::ObTMArray<common::ObObjParam> &res_objs,
const common::ObIArray<int64_t> &param_expr_idxs); const common::ObIArray<int64_t> &param_expr_idxs);
void reset() void reset()
{ {
@ -132,7 +132,7 @@ public:
int deep_copy_param(const common::ObObjParam &org_param, common::ObObjParam &new_param); int deep_copy_param(const common::ObObjParam &org_param, common::ObObjParam &new_param);
public: public:
common::ObArenaAllocator allocator_; common::ObArenaAllocator allocator_;
common::ObSArray<common::ObSEArray<common::ObObjParam, 8>> params_; common::ObSArray<sql::ObTMArray<common::ObObjParam>> params_;
common::ObSEArray<int64_t, 8> param_idxs_; common::ObSEArray<int64_t, 8> param_idxs_;
common::ObSEArray<int64_t, 8> param_expr_idxs_; common::ObSEArray<int64_t, 8> param_expr_idxs_;
TO_STRING_KV(K(param_idxs_), K(params_), K_(param_expr_idxs)); TO_STRING_KV(K(param_idxs_), K(params_), K_(param_expr_idxs));

View File

@ -16,6 +16,7 @@
#include "sql/engine/ob_operator.h" #include "sql/engine/ob_operator.h"
#include "sql/engine/basic/ob_chunk_datum_store.h" #include "sql/engine/basic/ob_chunk_datum_store.h"
#include "sql/engine/px/ob_px_util.h" #include "sql/engine/px/ob_px_util.h"
#include "sql/ob_sql_define.h"
namespace oceanbase namespace oceanbase
{ {
@ -271,7 +272,7 @@ private:
ObBatchRescanParams rescan_batch_params_; ObBatchRescanParams rescan_batch_params_;
int64_t left_row_idx_; int64_t left_row_idx_;
ObBatchRescanCtl batch_rescan_ctl_; ObBatchRescanCtl batch_rescan_ctl_;
common::ObSEArray<common::ObObjParam, 8> cur_params_; sql::ObTMArray<common::ObObjParam> cur_params_;
common::ObSArray<int64_t> cur_param_idxs_; common::ObSArray<int64_t> cur_param_idxs_;
common::ObSArray<int64_t> cur_param_expr_idxs_; common::ObSArray<int64_t> cur_param_expr_idxs_;
common::ObSEArray<Iterator*, 8> subplan_iters_to_check_; common::ObSEArray<Iterator*, 8> subplan_iters_to_check_;

View File

@ -324,7 +324,7 @@ protected:
virtual int destroy() override; virtual int destroy() override;
protected: protected:
// 存储同一个partition所对应的所有task id // 存储同一个partition所对应的所有task id
typedef common::ObSEArray<int64_t, 8> TaskIdxArray; typedef sql::ObTMArray<int64_t> TaskIdxArray;
// pkey random情况下:数据可以发送到对应partition所在的SQC的任意一个task上,因此每一个partition都对应着 // pkey random情况下:数据可以发送到对应partition所在的SQC的任意一个task上,因此每一个partition都对应着
// 一组task id // 一组task id
// key: tablet_id // key: tablet_id

View File

@ -17,6 +17,8 @@
#include "share/datum/ob_datum.h" #include "share/datum/ob_datum.h"
#include "common/object/ob_object.h" #include "common/object/ob_object.h"
#include "share/ob_define.h" #include "share/ob_define.h"
#include "deps/oblib/src/lib/container/ob_array.h"
#include "src/share/rc/ob_tenant_base.h"
namespace oceanbase namespace oceanbase
{ {
@ -28,6 +30,7 @@ struct ObSchemaObjVersion;
} }
} }
using namespace common; using namespace common;
namespace sql namespace sql
{ {
const int64_t OB_SQL_MAX_CHILD_OPERATOR_NUM = 16; const int64_t OB_SQL_MAX_CHILD_OPERATOR_NUM = 16;
@ -632,6 +635,28 @@ struct ObWinfuncOptimizationOpt
}; };
}; };
// class full name: ob tenant memory array.
// Used to solve the following problem:
// the initial memory allocation of ObSEArray is relatively large, leading to memory inflation issues in some scenarios.
// Default to using the MTL_ID() tenant,
// and the lifecycle of this class cannot cross tenants.
template<typename T, typename BlockAllocatorT = ModulePageAllocator, bool auto_free = false, typename CallBack = ObArrayDefaultCallBack<T>, typename ItemEncode = DefaultItemEncode<T> >
class ObTMArray final : public ObArrayImpl<T, BlockAllocatorT, auto_free, CallBack, ItemEncode>
{
public:
using ObArrayImpl<T, BlockAllocatorT, auto_free, CallBack, ItemEncode>::ObArrayImpl;
ObTMArray(int64_t block_size = std::min(static_cast<int64_t>(4 * sizeof(T)), OB_MALLOC_NORMAL_BLOCK_SIZE),
const BlockAllocatorT &alloc = BlockAllocatorT("TMArray"));
};
template<typename T, typename BlockAllocatorT, bool auto_free, typename CallBack, typename ItemEncode>
ObTMArray<T, BlockAllocatorT, auto_free, CallBack, ItemEncode>::ObTMArray(int64_t block_size,
const BlockAllocatorT &alloc)
: ObArrayImpl<T, BlockAllocatorT, auto_free, CallBack, ItemEncode>(block_size, alloc)
{
this->set_tenant_id(MTL_ID());
}
} // namespace sql } // namespace sql
} // namespace oceanbase } // namespace oceanbase
#endif /* OCEANBASE_SQL_OB_SQL_DEFINE_H_ */ #endif /* OCEANBASE_SQL_OB_SQL_DEFINE_H_ */