[MemTracker] make all MemTrackers shared (#4135)

We make all MemTrackers shared, in order to show MemTracker real-time consumptions on the web.
As follows:
1. nearly all MemTracker raw ptr -> shared_ptr
2. Use CreateTracker() to create new MemTracker(in order to add itself to its parent)
3. RowBatch & MemPool still use raw ptrs of MemTracker, it's easy to ensure RowBatch & MemPool destructor exec 
     before MemTracker's destructor. So we don't change these code.
4. MemTracker can use RuntimeProfile's counter to calc consumption. So RuntimeProfile's counter need to be shared 
    too. We add a shared counter pool to store the shared counter, don't change other counters of RuntimeProfile.
Note that, this PR doesn't change the MemTracker tree structure. So there still have some orphan trackers, e.g. RowBlockV2's MemTracker. If you find some shared MemTrackers are little memory consumption & too time-consuming, you could make them be the orphan, then it's fine to use the raw ptr.
This commit is contained in:
HuangWei
2020-07-31 21:57:21 +08:00
committed by GitHub
parent f412f99511
commit 10f822eb43
209 changed files with 2137 additions and 1845 deletions

View File

@ -539,7 +539,7 @@ Status Expr::prepare(
const std::vector<ExprContext*>& ctxs,
RuntimeState* state,
const RowDescriptor& row_desc,
MemTracker* tracker) {
const std::shared_ptr<MemTracker>& tracker) {
for (int i = 0; i < ctxs.size(); ++i) {
RETURN_IF_ERROR(ctxs[i]->prepare(state, row_desc, tracker));
}
@ -868,13 +868,12 @@ void Expr::assign_fn_ctx_idx(int* next_fn_ctx_idx) {
_fn_ctx_idx_end = *next_fn_ctx_idx;
}
Status Expr::create(const TExpr& texpr, const RowDescriptor& row_desc,
RuntimeState* state, ObjectPool* pool, Expr** scalar_expr,
MemTracker* tracker) {
*scalar_expr = nullptr;
Expr* root;
RETURN_IF_ERROR(create_expr(pool, texpr.nodes[0], &root));
Status Expr::create(const TExpr& texpr, const RowDescriptor& row_desc, RuntimeState* state,
ObjectPool* pool, Expr** scalar_expr,
const std::shared_ptr<MemTracker>& tracker) {
*scalar_expr = nullptr;
Expr* root;
RETURN_IF_ERROR(create_expr(pool, texpr.nodes[0], &root));
RETURN_IF_ERROR(create_tree(texpr, pool, root));
// TODO pengyubing replace by Init()
ExprContext* ctx = pool->add(new ExprContext(root));
@ -893,9 +892,10 @@ Status Expr::create(const TExpr& texpr, const RowDescriptor& row_desc,
return Status::OK();
}
Status Expr::create(const vector<TExpr>& texprs, const RowDescriptor& row_desc,
RuntimeState* state, ObjectPool* pool, vector<Expr*>* exprs, MemTracker* tracker) {
exprs->clear();
Status Expr::create(const vector<TExpr>& texprs, const RowDescriptor& row_desc, RuntimeState* state,
ObjectPool* pool, vector<Expr*>* exprs,
const std::shared_ptr<MemTracker>& tracker) {
exprs->clear();
for (const TExpr& texpr: texprs) {
Expr* expr;
RETURN_IF_ERROR(create(texpr, row_desc, state, pool, &expr, tracker));
@ -906,12 +906,12 @@ Status Expr::create(const vector<TExpr>& texprs, const RowDescriptor& row_desc,
}
Status Expr::create(const TExpr& texpr, const RowDescriptor& row_desc,
RuntimeState* state, Expr** scalar_expr, MemTracker* tracker) {
RuntimeState* state, Expr** scalar_expr, const std::shared_ptr<MemTracker>& tracker) {
return Expr::create(texpr, row_desc, state, state->obj_pool(), scalar_expr, tracker);
}
Status Expr::create(const vector<TExpr>& texprs, const RowDescriptor& row_desc,
RuntimeState* state, vector<Expr*>* exprs, MemTracker* tracker) {
RuntimeState* state, vector<Expr*>* exprs, const std::shared_ptr<MemTracker>& tracker) {
return Expr::create(texprs, row_desc, state, state->obj_pool(), exprs, tracker);
}