From 0e9cb3a0a5c7a9b169270ced9eaed1e87d6582f8 Mon Sep 17 00:00:00 2001 From: ls0 Date: Thu, 17 Mar 2022 17:57:45 +0800 Subject: [PATCH] fix hash part infra hang because negative bound size --- .../engine/basic/ob_hash_partitioning_infrastructure.h | 10 +++++----- .../basic/ob_hash_partitioning_infrastructure_op.h | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/sql/engine/basic/ob_hash_partitioning_infrastructure.h b/src/sql/engine/basic/ob_hash_partitioning_infrastructure.h index b16cf7e148..4e3bed73cc 100644 --- a/src/sql/engine/basic/ob_hash_partitioning_infrastructure.h +++ b/src/sql/engine/basic/ob_hash_partitioning_infrastructure.h @@ -1062,9 +1062,9 @@ int64_t ObBasicHashPartInfrastructure::est_bucket_count( } int64_t est_bucket_mem_size = next_pow2(rows) * sizeof(void*); int64_t est_data_mem_size = rows * width; - int64_t max_remain_mem_size = sql_mem_processor_->get_mem_bound() - est_part_cnt_ * BLOCK_SIZE; + int64_t max_remain_mem_size = std::max(0l, sql_mem_processor_->get_mem_bound() - est_part_cnt_ * BLOCK_SIZE); int64_t est_bucket_num = rows; - while (est_bucket_mem_size + est_data_mem_size > max_remain_mem_size) { + while (est_bucket_mem_size + est_data_mem_size > max_remain_mem_size && est_bucket_num > 0) { est_bucket_num >>= 1; est_bucket_mem_size = next_pow2(est_bucket_num) * sizeof(void*); est_data_mem_size = est_bucket_num * width; @@ -1706,10 +1706,10 @@ int ObPartitionExtendHashTable::init( template int64_t ObPartitionExtendHashTable::estimate_bucket_num(const int64_t bucket_num, const int64_t max_hash_mem) { - int64_t max_bound_size = max_hash_mem * MAX_MEM_PERCENT / 100; + int64_t max_bound_size = std::max(0l, max_hash_mem * MAX_MEM_PERCENT / 100); int64_t est_bucket_num = common::next_pow2(bucket_num); - int64_t est_size = est_bucket_num * sizeof(void*); - while (est_size > max_bound_size) { + int64_t est_size = est_bucket_num * sizeof(void *); + while (est_size > max_bound_size && est_bucket_num > 0) { est_bucket_num >>= 1; est_size = est_bucket_num * sizeof(void*); } diff --git a/src/sql/engine/basic/ob_hash_partitioning_infrastructure_op.h b/src/sql/engine/basic/ob_hash_partitioning_infrastructure_op.h index 944529254e..291d7b8bf6 100644 --- a/src/sql/engine/basic/ob_hash_partitioning_infrastructure_op.h +++ b/src/sql/engine/basic/ob_hash_partitioning_infrastructure_op.h @@ -1051,9 +1051,9 @@ int64_t ObHashPartInfrastructure::est_bucket_count( } int64_t est_bucket_mem_size = next_pow2(rows) * sizeof(void*); int64_t est_data_mem_size = rows * width; - int64_t max_remain_mem_size = sql_mem_processor_->get_mem_bound() - est_part_cnt_ * BLOCK_SIZE; + int64_t max_remain_mem_size = std::max(0l, sql_mem_processor_->get_mem_bound() - est_part_cnt_ * BLOCK_SIZE); int64_t est_bucket_num = rows; - while (est_bucket_mem_size + est_data_mem_size > max_remain_mem_size) { + while (est_bucket_mem_size + est_data_mem_size > max_remain_mem_size && est_bucket_num > 0) { est_bucket_num >>= 1; est_bucket_mem_size = next_pow2(est_bucket_num) * sizeof(void*); est_data_mem_size = est_bucket_num * width; @@ -1719,10 +1719,10 @@ template int64_t ObHashPartitionExtendHashTable::estimate_bucket_num( const int64_t bucket_num, const int64_t max_hash_mem, const int64_t min_bucket, const int64_t max_bucket) { - int64_t max_bound_size = max_hash_mem * MAX_MEM_PERCENT / 100; + int64_t max_bound_size = std::max(0l, max_hash_mem * MAX_MEM_PERCENT / 100); int64_t est_bucket_num = common::next_pow2(bucket_num); - int64_t est_size = est_bucket_num * sizeof(void*); - while (est_size > max_bound_size) { + int64_t est_size = est_bucket_num * sizeof(void *); + while (est_size > max_bound_size && est_bucket_num > 0) { est_bucket_num >>= 1; est_size = est_bucket_num * sizeof(void*); } -- GitLab