Skip to content

Commit

Permalink
Storages: Fix queries with no segment get stuck (#9110) (#9112)
Browse files Browse the repository at this point in the history
close #9108

If segment count of a query is zero, finishing it directly. And do not add it to the sheduler.

Signed-off-by: JaySon-Huang <tshent@qq.com>

Co-authored-by: jinhelin <linjinhe33@gmail.com>
Co-authored-by: JaySon-Huang <tshent@qq.com>
  • Loading branch information
3 people authored May 31, 2024
1 parent 61348e8 commit c5885bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ SegmentReadTaskScheduler::~SegmentReadTaskScheduler()

void SegmentReadTaskScheduler::add(const SegmentReadTaskPoolPtr & pool)
{
if (pool->getTasks().empty())
{
return;
}
Stopwatch sw_add;
std::lock_guard lock(mtx);
Stopwatch sw_do_add;
Expand Down
29 changes: 17 additions & 12 deletions dbms/src/Storages/DeltaMerge/SegmentReadTaskPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,12 @@ class SegmentReadTaskPool : private boost::noncopyable
// Limiting the minimum number of reading segments to 2 is to avoid, as much as possible,
// situations where the computation may be faster and the storage layer may not be able to keep up.
, active_segment_limit(std::max(num_streams_, 2))
{}
{
if (tasks_wrapper.empty())
{
q.finish();
}
}

~SegmentReadTaskPool()
{
Expand All @@ -201,17 +206,17 @@ class SegmentReadTaskPool : private boost::noncopyable
auto total_bytes = blk_stat.totalBytes();
auto blk_avg_bytes = total_count > 0 ? total_bytes / total_count : 0;
auto approximate_max_pending_block_bytes = blk_avg_bytes * max_queue_size;
LOG_DEBUG(log, "Done. pool_id={} table_id={} pop={} pop_empty={} pop_empty_ratio={} max_queue_size={} blk_avg_bytes={} approximate_max_pending_block_bytes={:.2f}MB total_count={} total_bytes={:.2f}MB", //
pool_id,
table_id,
pop_times,
pop_empty_times,
pop_empty_ratio,
max_queue_size,
blk_avg_bytes,
approximate_max_pending_block_bytes / 1024.0 / 1024.0,
total_count,
total_bytes / 1024.0 / 1024.0);
LOG_INFO(log, "Done. pool_id={} table_id={} pop={} pop_empty={} pop_empty_ratio={} max_queue_size={} blk_avg_bytes={} approximate_max_pending_block_bytes={:.2f}MB total_count={} total_bytes={:.2f}MB", //
pool_id,
table_id,
pop_times,
pop_empty_times,
pop_empty_ratio,
max_queue_size,
blk_avg_bytes,
approximate_max_pending_block_bytes / 1024.0 / 1024.0,
total_count,
total_bytes / 1024.0 / 1024.0);
}

SegmentReadTaskPtr nextTask();
Expand Down

0 comments on commit c5885bb

Please sign in to comment.