Skip to content

Commit

Permalink
[Bug](memory) Fix exception-unsafe in aggregation node (apache#28483)
Browse files Browse the repository at this point in the history
The alloc function may throw std::bad_alloc exception when the process memory exceed limit.

be.INFO:

W1214 09:14:17.434849 771103 mem_tracker_limiter.cpp:204] Memory limit exceeded:<consuming tracker:<Load#Id=28448230da1f432e-8a66597e1032
9235>, process memory used 20.41 GB exceed limit 18.76 GB or sys mem available 9.04 GB less than low water mark 1.60 GB, failed alloc siz
e 1.86 MB>, executing msg:<execute:<>>. backend xx.x.x.xxx process memory used 20.41 GB, limit 18.76 GB. If query tracker exceed, set ex ec_mem_limit=8G to change limit, details see be.INFO.
Process Memory Summary:
    OS physical memory 31.26 GB. Process memory usage 20.41 GB, limit 18.76 GB, soft limit 16.88 GB. Sys available memory 9.04 GB, low wa
ter mark 1.60 GB, warning water mark 3.20 GB. Refresh interval memory growth 0 B
Alloc Stacktrace:
    @     0x555cd858bee9  doris::MemTrackerLimiter::print_log_usage()
    @     0x555cd859a384  doris::ThreadMemTrackerMgr::exceeded()
    @     0x555cd85a0ac4  malloc
    @     0x555cd8fcf368  Allocator<>::alloc()
    @     0x555cd8fdbdaf  doris::vectorized::Arena::add_chunk()
    @     0x555cd96dc0ab  doris::vectorized::AggregateDataContainer::_expand()
    @     0x555cd96aded8  (unknown)
    @     0x555cd969fa2c  doris::vectorized::AggregationNode::_pre_agg_with_serialized_key()
    @     0x555cd96d1d61  std::_Function_handler<>::_M_invoke()
    @     0x555cd967ab0b  doris::vectorized::AggregationNode::get_next()
    @     0x555cd81282a6  doris::ExecNode::get_next_after_projects()
    @     0x555cd8452968  doris::PlanFragmentExecutor::get_vectorized_internal()
    @     0x555cd845553b  doris::PlanFragmentExecutor::open_vectorized_internal()
    @     0x555cd8456a9e  doris::PlanFragmentExecutor::open()
    @     0x555cd842f200  doris::FragmentExecState::execute()
    @     0x555cd843280e  doris::FragmentMgr::_exec_actual()
    @     0x555cd8432d42  _ZNSt17_Function_handlerIFvvEZN5doris11FragmentMgr18exec_plan_fragmentERKNS1_23TExecPlanFragmentParamsESt8funct
ionIFvPNS1_20PlanFragmentExecutorEEEEUlvE_E9_M_invokeERKSt9_Any_data
    @     0x555cd86ead05  doris::ThreadPool::dispatch_thread()
    @     0x555cd86e015f  doris::Thread::supervise_thread()
    @     0x7f3321593ea5  start_thread
    @     0x7f33218a69fd  __clone
    @              (nil)  (unknown)
  • Loading branch information
xy720 authored Dec 15, 2023
1 parent 0f93ee8 commit fb925bd
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions be/src/vec/exec/vaggregation_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,26 @@ struct AggregateDataContainer {
private:
void _expand() {
_index_in_sub_container = 0;
_current_keys = _arena_pool.alloc(_size_of_key * SUB_CONTAINER_CAPACITY);
_key_containers.emplace_back(_current_keys);

_current_agg_data = (AggregateDataPtr)_arena_pool.alloc(_size_of_aggregate_states *
SUB_CONTAINER_CAPACITY);
_value_containers.emplace_back(_current_agg_data);
_current_keys = nullptr;
_current_agg_data = nullptr;
try {
_current_keys = _arena_pool.alloc(_size_of_key * SUB_CONTAINER_CAPACITY);
_key_containers.emplace_back(_current_keys);

_current_agg_data = (AggregateDataPtr)_arena_pool.alloc(_size_of_aggregate_states *
SUB_CONTAINER_CAPACITY);
_value_containers.emplace_back(_current_agg_data);
} catch (...) {
if (_current_keys) {
_key_containers.pop_back();
_current_keys = nullptr;
}
if (_current_agg_data) {
_value_containers.pop_back();
_current_agg_data = nullptr;
}
throw;
}
}

static constexpr uint32_t SUB_CONTAINER_CAPACITY = 8192;
Expand Down

0 comments on commit fb925bd

Please sign in to comment.