Skip to content

Commit

Permalink
avoid compact when segment is flushing
Browse files Browse the repository at this point in the history
  • Loading branch information
lidezhu committed May 26, 2022
1 parent 72d5623 commit e148557
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dbms/src/Storages/DeltaMerge/DeltaMergeStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,8 @@ void DeltaMergeStore::checkSegmentUpdate(const DMContextPtr & dm_context, const
&& (delta_rows - delta_last_try_flush_rows >= delta_cache_limit_rows
|| delta_bytes - delta_last_try_flush_bytes >= delta_cache_limit_bytes);
bool should_foreground_flush = unsaved_rows >= delta_cache_limit_rows * 3 || unsaved_bytes >= delta_cache_limit_bytes * 3;
// Actually we never do foreground flush in read thread
// Don't block write thread unless the data in delta layer is really too large.
// And read thread never do foreground flush so no need to special check for read thread.
if (thread_type == ThreadType::Write)
{
should_foreground_flush = unsaved_rows >= delta_cache_limit_rows * 100 || unsaved_bytes >= delta_cache_limit_bytes * 100;
Expand Down Expand Up @@ -1447,7 +1448,8 @@ void DeltaMergeStore::checkSegmentUpdate(const DMContextPtr & dm_context, const
return false;
};
auto try_bg_compact = [&]() {
if (should_compact)
/// Only add background compact task when this segment is not flushing to reduce lock contention on the segment.
if (should_compact && !segment->isFlushing())
{
delta_last_try_compact_column_files = column_file_count;
try_add_background_task(BackgroundTask{TaskType::Compact, dm_context, segment, {}});
Expand Down

0 comments on commit e148557

Please sign in to comment.