fix allocate memory failed in sort vec op

This commit is contained in:
Cerdore 2024-12-16 18:15:17 +00:00 committed by ob-robot
parent 3724a8f402
commit c3b83240d7
2 changed files with 13 additions and 4 deletions

View File

@ -202,7 +202,14 @@ protected:
bool need_dump()
{
return sql_mem_processor_.get_data_size() > get_tmp_buffer_mem_bound()
|| mem_context_->used() >= profile_.get_max_bound();
|| get_total_used_size() >= profile_.get_max_bound();
}
int64_t get_total_used_size()
{
int64_t row_cnt = sk_store_.get_row_cnt();
return mem_context_->used() + ((part_cnt_ == 0) ? 0 :
((row_cnt * FIXED_PART_NODE_SIZE * 2) + // size of(part_hash_nodes_)
(next_pow2(std::max(16L, row_cnt)) * FIXED_PART_BKT_SIZE * 2))); // size of(buckets_)
}
inline int64_t get_tmp_buffer_mem_bound() {
// The memory reserved for ObSortVecOpEagerFilter should be deducted when topn filter is enabled.
@ -400,6 +407,8 @@ protected:
using BucketNodeArray = common::ObSegmentArray<PartHashNode,
OB_MALLOC_MIDDLE_BLOCK_SIZE,
common::ModulePageAllocator>;
const static int64_t FIXED_PART_NODE_SIZE = sizeof(PartHashNode);
const static int64_t FIXED_PART_BKT_SIZE = sizeof(PartHashNode *);
static const int64_t MAX_ROW_CNT = 268435456; // (2G / 8)
static const int64_t EXTEND_MULTIPLE = 2;
static const int64_t MAX_MERGE_WAYS = 256;

View File

@ -1180,7 +1180,7 @@ int ObSortVecOpImpl<Compare, Store_Row, has_addon>::preprocess_dump(bool &dumped
dumped = false;
if (OB_FAIL(sql_mem_processor_.get_max_available_mem_size(&mem_context_->get_malloc_allocator()))) {
SQL_ENG_LOG(WARN, "failed to get max available memory size", K(ret));
} else if (OB_FAIL(sql_mem_processor_.update_used_mem_size(mem_context_->used()))) {
} else if (OB_FAIL(sql_mem_processor_.update_used_mem_size(get_total_used_size()))) {
SQL_ENG_LOG(WARN, "failed to update used memory size", K(ret));
} else {
dumped = need_dump();
@ -1203,10 +1203,10 @@ int ObSortVecOpImpl<Compare, Store_Row, has_addon>::preprocess_dump(bool &dumped
UNUSED(max_memory_size);
return need_dump();
},
dumped, mem_context_->used()))) {
dumped, get_total_used_size()))) {
SQL_ENG_LOG(WARN, "failed to extend memory size", K(ret));
}
LOG_TRACE("trace sort need dump", K(dumped), K(mem_context_->used()), K(get_memory_limit()),
LOG_TRACE("trace sort need dump", K(dumped), K(get_total_used_size()), K(get_memory_limit()),
K(profile_.get_cache_size()), K(profile_.get_expect_size()));
} else {
// one-pass