Skip to content

Commit

Permalink
add more checks for background split
Browse files Browse the repository at this point in the history
  • Loading branch information
lidezhu authored and ti-chi-bot committed Mar 24, 2022
1 parent 1dd5d6c commit f8662ab
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions dbms/src/Storages/DeltaMerge/DeltaMergeStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,9 +1186,13 @@ void DeltaMergeStore::checkSegmentUpdate(const DMContextPtr & dm_context, const

// Note that, we must use || to combine rows and bytes checks in split check, and use && in merge check.
// Otherwise, segments could be split and merged over and over again.
bool should_split = (segment_rows >= segment_limit_rows * 2 || segment_bytes >= segment_limit_bytes * 2)
&& (delta_rows - delta_last_try_split_rows >= delta_cache_limit_rows
|| delta_bytes - delta_last_try_split_bytes >= delta_cache_limit_bytes);
// Do background split in the following two cases:
// 1. The segment is large enough, and there are some data in the delta layer. (A hot segment which is large enough)
// 2. The segment is too large. (A segment which is too large, although it is cold)
bool should_bg_split = ((segment_rows >= segment_limit_rows * 2 || segment_bytes >= segment_limit_bytes * 2)
&& (delta_rows - delta_last_try_split_rows >= delta_cache_limit_rows
|| delta_bytes - delta_last_try_split_bytes >= delta_cache_limit_bytes))
|| (segment_rows >= segment_limit_rows * 3 || segment_bytes >= segment_limit_bytes * 3);

bool should_merge = segment_rows < segment_limit_rows / 3 && segment_bytes < segment_limit_bytes / 3;

Expand Down Expand Up @@ -1299,7 +1303,7 @@ void DeltaMergeStore::checkSegmentUpdate(const DMContextPtr & dm_context, const
return false;
};
auto try_bg_split = [&](const SegmentPtr & seg) {
if (should_split && !seg->isSplitForbidden())
if (should_bg_split && !seg->isSplitForbidden())
{
delta_last_try_split_rows = delta_rows;
delta_last_try_split_bytes = delta_bytes;
Expand Down

0 comments on commit f8662ab

Please sign in to comment.